Skip to content

Commit

Permalink
Fixes #213573 (#213574)
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet authored May 27, 2024
1 parent 014beb7 commit ccb4db1
Showing 1 changed file with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>, filter?: ReadonlyArray<vscode.TestItem>) {
const args = this.prepareArguments(baseArgs, filter);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -303,5 +325,5 @@ export const PlatformTestRunner =
process.platform === 'win32'
? WindowsTestRunner
: process.platform === 'darwin'
? DarwinTestRunner
: PosixTestRunner;
? DarwinTestRunner
: PosixTestRunner;

0 comments on commit ccb4db1

Please sign in to comment.