diff --git a/test/TestExpectations.json b/test/TestExpectations.json index bd5c8f37..03f3c2ef 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -1236,10 +1236,10 @@ "expectations": ["SKIP"] }, { - "testIdPattern": "[page.spec] Page ExecutionContext.queryObjects should work for non-blank page", + "testIdPattern": "[page.spec] Page ExecutionContext.queryObjects should work for non-trivial page", "platforms": ["darwin", "linux", "win32"], "parameters": ["firefox"], - "expectations": ["SKIP"] + "expectations": ["FAIL"] }, { "testIdPattern": "[page.spec] Page Page.addStyleTag should throw when added with content to the CSP page", diff --git a/tools/mochaRunner/src/interface.ts b/tools/mochaRunner/src/interface.ts index 1880fe29..df48855b 100644 --- a/tools/mochaRunner/src/interface.ts +++ b/tools/mochaRunner/src/interface.ts @@ -30,10 +30,15 @@ const skippedTests: Array<{testIdPattern: string; skip: true}> = process.env[ skippedTests.reverse(); function shouldSkipTest(test: Mocha.Test): boolean { - const testId = getTestId(test.file!, test.fullTitle()); + const testIdForFileName = getTestId(test.file!); + const testIdForTestName = getTestId(test.file!, test.fullTitle()); // TODO: more efficient lookup. const defintion = skippedTests.find(skippedTest => { - return testId.startsWith(skippedTest.testIdPattern); + return ( + '' === skippedTest.testIdPattern || + testIdForFileName === skippedTest.testIdPattern || + testIdForTestName === skippedTest.testIdPattern + ); }); if (defintion && defintion.skip) { return true; diff --git a/tools/mochaRunner/src/utils.ts b/tools/mochaRunner/src/utils.ts index 4a2be6d8..517d1f15 100644 --- a/tools/mochaRunner/src/utils.ts +++ b/tools/mochaRunner/src/utils.ts @@ -57,11 +57,11 @@ export function prettyPrintJSON(json: unknown): void { } export function filterByParameters( - expecations: TestExpectation[], + expectations: TestExpectation[], parameters: string[] ): TestExpectation[] { const querySet = new Set(parameters); - return expecations.filter(ex => { + return expectations.filter(ex => { return ex.parameters.every(param => { return querySet.has(param); }); @@ -69,22 +69,20 @@ export function filterByParameters( } /** - * The last expectation that matches the startsWith filter wins. + * The last expectation that matches an empty string as all tests pattern + * or the name of the file or the whole name of the test the filter wins. */ -export function findEffectiveExpecationForTest( +export function findEffectiveExpectationForTest( expectations: TestExpectation[], result: MochaTestResult ): TestExpectation | undefined { return expectations - .filter(expecation => { - if ( - getTestId(result.file, result.fullTitle).startsWith( - expecation.testIdPattern - ) - ) { - return true; - } - return false; + .filter(expectation => { + return ( + '' === expectation.testIdPattern || + getTestId(result.file) === expectation.testIdPattern || + getTestId(result.file, result.fullTitle) === expectation.testIdPattern + ); }) .pop(); } @@ -106,7 +104,7 @@ export function getExpectationUpdates( const output: RecommendedExpecation[] = []; for (const pass of results.passes) { - const expectation = findEffectiveExpecationForTest(expecations, pass); + const expectation = findEffectiveExpectationForTest(expecations, pass); if (expectation && !expectation.expectations.includes('PASS')) { output.push({ expectation, @@ -117,7 +115,7 @@ export function getExpectationUpdates( } for (const failure of results.failures) { - const expectation = findEffectiveExpecationForTest(expecations, failure); + const expectation = findEffectiveExpectationForTest(expecations, failure); if (expectation) { if ( !expectation.expectations.includes(getTestResultForFailure(failure)) @@ -156,6 +154,8 @@ export function getTestResultForFailure( return test.err?.code === 'ERR_MOCHA_TIMEOUT' ? 'TIMEOUT' : 'FAIL'; } -export function getTestId(file: string, fullTitle: string): string { - return `[${getFilename(file)}] ${fullTitle}`; +export function getTestId(file: string, fullTitle?: string): string { + return fullTitle + ? `[${getFilename(file)}] ${fullTitle}` + : `[${getFilename(file)}]`; }