diff --git a/.vscode/extensions/vscode-selfhost-test-provider/src/vscodeTestRunner.ts b/.vscode/extensions/vscode-selfhost-test-provider/src/vscodeTestRunner.ts index 5d73928aed5..8a76cefe36a 100644 --- a/.vscode/extensions/vscode-selfhost-test-provider/src/vscodeTestRunner.ts +++ b/.vscode/extensions/vscode-selfhost-test-provider/src/vscodeTestRunner.ts @@ -24,7 +24,7 @@ const ATTACH_CONFIG_NAME = 'Attach to VS Code'; const DEBUG_TYPE = 'pwa-chrome'; export abstract class VSCodeTestRunner { - constructor(protected readonly repoLocation: vscode.WorkspaceFolder) {} + constructor(protected readonly repoLocation: vscode.WorkspaceFolder) { } public async run(baseArgs: ReadonlyArray, filter?: ReadonlyArray) { const args = this.prepareArguments(baseArgs, filter); @@ -163,18 +163,40 @@ export abstract class VSCodeTestRunner { path.relative(data.workspaceFolder.uri.fsPath, data.uri.fsPath).replace(/\\/g, '/') ); + const itemDatas = filter.map(f => itemData.get(f)); + /** If true, we have to be careful with greps, as a grep for one test file affects the run of the other test file. */ + const hasBothTestCaseOrTestSuiteAndTestFileFilters = + itemDatas.some(d => (d instanceof TestCase) || (d instanceof TestSuite)) && + itemDatas.some(d => d instanceof TestFile); + + function addTestCaseOrSuite(data: TestCase | TestSuite, test: vscode.TestItem): void { + grepRe.push(escapeRe(data.fullName) + (data instanceof TestCase ? '$' : ' ')); + for (let p = test.parent; p; p = p.parent) { + const parentData = itemData.get(p); + if (parentData instanceof TestFile) { + addTestFileRunPath(parentData); + } + } + } + for (const test of filter) { const data = itemData.get(test); if (data instanceof TestCase || data instanceof TestSuite) { - grepRe.push(escapeRe(data.fullName) + (data instanceof TestCase ? '$' : ' ')); - for (let p = test.parent; p; p = p.parent) { - const parentData = itemData.get(p); - if (parentData instanceof TestFile) { - addTestFileRunPath(parentData); + addTestCaseOrSuite(data, test); + } else if (data instanceof TestFile) { + if (!hasBothTestCaseOrTestSuiteAndTestFileFilters) { + addTestFileRunPath(data); + } else { + // We add all the items individually so they get their own grep expressions. + for (const [_id, nestedTest] of test.children) { + const childData = itemData.get(nestedTest); + if (childData instanceof TestCase || childData instanceof TestSuite) { + addTestCaseOrSuite(childData, nestedTest); + } else { + console.error('Unexpected test item in test file', nestedTest.id, nestedTest.label); + } } } - } else if (data instanceof TestFile) { - addTestFileRunPath(data); } } @@ -303,5 +325,5 @@ export const PlatformTestRunner = process.platform === 'win32' ? WindowsTestRunner : process.platform === 'darwin' - ? DarwinTestRunner - : PosixTestRunner; + ? DarwinTestRunner + : PosixTestRunner;