chore: remove retries and fix expectations (#9897)

This commit is contained in:
Alex Rudenko 2023-03-23 10:22:17 +01:00 committed by GitHub
parent 976684e4e1
commit ad7bbaebef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 2081 additions and 1847 deletions

View File

@ -41,6 +41,7 @@ jobs:
- 'test/**' - 'test/**'
- 'test-d/**' - 'test-d/**'
- 'tools/mochaRunner/**' - 'tools/mochaRunner/**'
- '.mocharc.cjs'
website: website:
- '.github/workflows/ci.yml' - '.github/workflows/ci.yml'
- 'docs/**' - 'docs/**'

View File

@ -20,7 +20,7 @@ module.exports = {
require: ['./test/build/mocha-utils.js', 'source-map-support/register'], require: ['./test/build/mocha-utils.js', 'source-map-support/register'],
spec: 'test/build/**/*.spec.js', spec: 'test/build/**/*.spec.js',
exit: !!process.env.CI, exit: !!process.env.CI,
retries: process.env.CI ? 2 : 0, retries: 0,
parallel: !!process.env.PARALLEL, parallel: !!process.env.PARALLEL,
timeout: 25_000, timeout: 25_000,
reporter: process.env.CI ? 'spec' : 'dot', reporter: process.env.CI ? 'spec' : 'dot',

View File

@ -17,6 +17,7 @@
"docs": "run-s build:docs generate:markdown", "docs": "run-s build:docs generate:markdown",
"format:eslint": "eslint --ext js --ext ts --fix .", "format:eslint": "eslint --ext js --ext ts --fix .",
"format:prettier": "prettier --write .", "format:prettier": "prettier --write .",
"format:expectations": "node tools/sort-test-expectations.js",
"format": "run-s format:*", "format": "run-s format:*",
"generate:markdown": "tsx tools/generate_docs.ts", "generate:markdown": "tsx tools/generate_docs.ts",
"lint:eslint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .)", "lint:eslint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .)",

File diff suppressed because it is too large Load Diff

View File

@ -3,31 +3,31 @@
{ {
"id": "chrome-headless", "id": "chrome-headless",
"platforms": ["linux", "win32", "darwin"], "platforms": ["linux", "win32", "darwin"],
"parameters": ["chrome", "headless"], "parameters": ["chrome", "headless", "cdp"],
"expectedLineCoverage": 93 "expectedLineCoverage": 93
}, },
{ {
"id": "chrome-headful", "id": "chrome-headful",
"platforms": ["linux"], "platforms": ["linux"],
"parameters": ["chrome", "headful"], "parameters": ["chrome", "headful", "cdp"],
"expectedLineCoverage": 93 "expectedLineCoverage": 93
}, },
{ {
"id": "chrome-new-headless", "id": "chrome-new-headless",
"platforms": ["linux"], "platforms": ["linux"],
"parameters": ["chrome", "new-headless"], "parameters": ["chrome", "new-headless", "cdp"],
"expectedLineCoverage": 93 "expectedLineCoverage": 93
}, },
{ {
"id": "firefox-headless", "id": "firefox-headless",
"platforms": ["linux", "darwin"], "platforms": ["linux", "darwin"],
"parameters": ["firefox", "headless"], "parameters": ["firefox", "headless", "cdp"],
"expectedLineCoverage": 80 "expectedLineCoverage": 80
}, },
{ {
"id": "firefox-headful", "id": "firefox-headful",
"platforms": ["linux"], "platforms": ["linux"],
"parameters": ["firefox", "headful"], "parameters": ["firefox", "headful", "cdp"],
"expectedLineCoverage": 80 "expectedLineCoverage": 80
}, },
{ {
@ -61,6 +61,7 @@
}, },
"webDriverBiDi": { "webDriverBiDi": {
"PUPPETEER_PROTOCOL": "webDriverBiDi" "PUPPETEER_PROTOCOL": "webDriverBiDi"
} },
"cdp": {}
} }
} }

View File

@ -72,6 +72,14 @@ export function printSuggestions(
return item.expectation; return item.expectation;
}) })
); );
console.log(
'The recommendations are based on the following applied expectaions:'
);
prettyPrintJSON(
toPrint.map(item => {
return item.basedOn;
})
);
} }
} }
@ -103,6 +111,7 @@ export function findEffectiveExpectationForTest(
export type RecommendedExpectation = { export type RecommendedExpectation = {
expectation: TestExpectation; expectation: TestExpectation;
action: 'remove' | 'add' | 'update'; action: 'remove' | 'add' | 'update';
basedOn?: TestExpectation;
}; };
export function isWildCardPattern(testIdPattern: string): boolean { export function isWildCardPattern(testIdPattern: string): boolean {
@ -134,6 +143,7 @@ export function getExpectationUpdates(
addEntry({ addEntry({
expectation: expectationEntry, expectation: expectationEntry,
action: 'remove', action: 'remove',
basedOn: expectationEntry,
}); });
} }
} }
@ -149,28 +159,39 @@ export function getExpectationUpdates(
expectations, expectations,
failure failure
); );
// If the effective explanation is a wildcard, we recommend adding a new if (expectationEntry) {
// expectation instead of updating the wildcard that might affect multiple
// tests.
if (
expectationEntry &&
!isWildCardPattern(expectationEntry.testIdPattern)
) {
if ( if (
!expectationEntry.expectations.includes( !expectationEntry.expectations.includes(
getTestResultForFailure(failure) getTestResultForFailure(failure)
) )
) { ) {
addEntry({ // If the effective explanation is a wildcard, we recommend adding a new
expectation: { // expectation instead of updating the wildcard that might affect multiple
...expectationEntry, // tests.
expectations: [ if (isWildCardPattern(expectationEntry.testIdPattern)) {
...expectationEntry.expectations, addEntry({
getTestResultForFailure(failure), expectation: {
], testIdPattern: getTestId(failure.file, failure.fullTitle),
}, platforms: context.platforms,
action: 'update', parameters: context.parameters,
}); expectations: [getTestResultForFailure(failure)],
},
action: 'add',
basedOn: expectationEntry,
});
} else {
addEntry({
expectation: {
...expectationEntry,
expectations: [
...expectationEntry.expectations,
getTestResultForFailure(failure),
],
},
action: 'update',
basedOn: expectationEntry,
});
}
} }
} else { } else {
addEntry({ addEntry({
@ -181,6 +202,7 @@ export function getExpectationUpdates(
expectations: [getTestResultForFailure(failure)], expectations: [getTestResultForFailure(failure)],
}, },
action: 'add', action: 'add',
basedOn: expectationEntry,
}); });
} }
} }

View File

@ -0,0 +1,59 @@
/**
* Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TODO: this could be an eslint rule probably.
const fs = require('fs');
const path = require('path');
const prettier = require('prettier');
const source = 'test/TestExpectations.json';
const testExpectations = JSON.parse(fs.readFileSync(source, 'utf-8'));
function getSpecificity(item) {
return (
item.parameters.length +
(item.testIdPattern.includes('*')
? item.testIdPattern === '*'
? 0
: 1
: 2)
);
}
testExpectations.sort((a, b) => {
const result = getSpecificity(a) - getSpecificity(b);
if (result === 0) {
return a.testIdPattern.localeCompare(b.testIdPattern);
}
return result;
});
testExpectations.forEach(item => {
item.parameters.sort();
item.expectations.sort();
item.platforms.sort();
});
fs.writeFileSync(
source,
prettier.format(JSON.stringify(testExpectations), {
...require(path.join(__dirname, '..', '.prettierrc.cjs')),
parser: 'json',
})
);