Working on multiroot

This commit is contained in:
James Yu 2022-12-28 21:57:28 +08:00
parent 95c86d88c6
commit 1e1274d1d8
7 changed files with 102 additions and 5 deletions

2
.vscode/launch.json vendored
View File

@ -22,7 +22,7 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceFolder}/test/fixtures/testground/",
"${workspaceFolder}/test/fixtures/multiroot/resource.code-workspace",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suites/index"
],

View File

@ -0,0 +1 @@
{}

0
test/fixtures/multiroot/A/.gitkeep vendored Normal file
View File

0
test/fixtures/multiroot/B/.gitkeep vendored Normal file
View File

View File

@ -0,0 +1,36 @@
{
"folders": [
{
"path": "A"
},
{
"path": "B"
}
],
"settings": {
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"-outdir=%OUTDIR%",
"-jobname=wsA",
"%DOC%"
],
"env": {}
},
{
"name": "fake",
"command": "touch",
"args": [
"%DIR%/fake.pdf"
]
}
],
"latex-workshop.latex.recipe.default": "latexmk"
}
}

View File

@ -52,19 +52,22 @@ async function runTestsOnEachFixture(targetName: 'viewer' | 'multiroot-ws') {
clearTimeout(nodejsTimeout)
}
}
async function runTestground() {
async function runTestSuites() {
try {
const extensionDevelopmentPath = path.resolve(__dirname, '../../')
const extensionTestsPath = path.resolve(__dirname, './suites/index')
const fixtures = glob.sync('test/fixtures/testground', { cwd: extensionDevelopmentPath })
const fixtures = [
path.resolve(extensionDevelopmentPath, 'test', 'fixtures', 'testground'),
path.resolve(extensionDevelopmentPath, 'test', 'fixtures', 'multiroot')
]
for (const fixture of fixtures) {
await runTests({
version: '1.71.0',
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [
fixture,
fixture + path.basename(fixture) === 'multiroot' ? '/resource.code-workspace' : '',
'--user-data-dir=' + tmpFile.dirSync({ unsafeCleanup: true }).name,
'--extensions-dir=' + tmpFile.dirSync({ unsafeCleanup: true }).name
],
@ -82,7 +85,7 @@ async function runTestground() {
async function main() {
try {
await runTestground()
await runTestSuites()
await runTestsOnEachFixture('viewer')
await runTestsOnEachFixture('multiroot-ws')
} catch (err) {

View File

@ -0,0 +1,57 @@
import * as vscode from 'vscode'
import * as path from 'path'
import * as fs from 'fs'
import rimraf from 'rimraf'
import * as assert from 'assert'
import { Extension, activate } from '../../src/main'
import { runTest, writeTeX, assertBuild } from './utils'
import { sleep } from '../utils/ciutils'
suite('Multi-root workspace test suite', () => {
let extension: Extension | undefined
const suiteName = path.basename(__filename).replace('.test.js', '')
let fixture = path.resolve(__dirname, '../../../test/fixtures/multiroot')
const fixtureName = 'multiroot'
suiteSetup(async () => {
await vscode.commands.executeCommand('latex-workshop.activate')
extension = vscode.extensions.getExtension<ReturnType<typeof activate>>('James-Yu.latex-workshop')?.exports.extension
assert.ok(extension)
fixture = path.resolve(extension.extensionRoot, 'test/fixtures/multiroot')
})
setup(async () => {
await vscode.commands.executeCommand('latex-workshop.activate')
})
teardown(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors')
if (extension) {
extension.manager.rootFile = undefined
}
if (path.basename(fixture) === 'multiroot') {
await sleep(250)
rimraf(fixture + '/A/*', (e) => {if (e) {console.error(e)}})
rimraf(fixture + '/B/*', (e) => {if (e) {console.error(e)}})
await sleep(250)
fs.closeSync(fs.openSync(path.resolve(fixture, 'A', '.gitkeep'), 'a'))
fs.closeSync(fs.openSync(path.resolve(fixture, 'B', '.gitkeep'), 'a'))
}
})
runTest({suiteName, fixtureName, testName: 'basic completion'}, async () => {
const tools = [
{name: 'latexmk', command: 'latexmk', args: ['-synctex=1', '-interaction=nonstopmode', '-file-line-error', '-pdf', '-outdir=%OUTDIR%', '-jobname=wsA', '%DOC%'], env: {}},
{name: 'fake', command: 'touch', args: ['%DIR%/fake.pdf']}
]
await vscode.workspace.getConfiguration().update('latex-workshop.latex.tools', tools)
await vscode.workspace.getConfiguration().update('latex-workshop.latex.recipe.default', 'latexmk')
await writeTeX('main', fixture, {fileName: 'A/main.tex'})
fs.closeSync(fs.openSync(path.resolve(fixture, 'B', 'empty'), 'a'))
await assertBuild({fixture, texFileName: 'A/main.tex', pdfFileName: 'A/wsA.pdf', extension})
})
})