diff --git a/package.json b/package.json index a5c661384e..325723bd27 100644 --- a/package.json +++ b/package.json @@ -16,20 +16,23 @@ "ctest": "cross-env BROWSER=chromium node test/test.js", "ftest": "cross-env BROWSER=firefox node test/test.js", "wtest": "cross-env BROWSER=webkit node test/test.js", - "unit": "npm run ctest", - "funit": "npm run ftest", - "wunit": "npm run wtest", - "debug-test": "node --inspect-brk test/test.js", - "test-doclint": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js", - "test": "npm run lint --silent && npm run ccoverage && npm run fcoverage && npm run wcoverage && npm run test-doclint && node utils/testrunner/test/test.js", - "prepare": "node install-from-github.js", - "lint": "([ \"$CI\" = true ] && eslint --quiet -f codeframe --ext js,ts ./src || eslint --ext js,ts ./src) && npm run tsc && npm run doc", - "doc": "node utils/doclint/cli.js", - "ccoverage": "cross-env COVERAGE=true npm run ctest", + "test": "cross-env BROWSER=all node test/test.js", + "cunit": "cross-env BROWSER=chromium node test/test.js", + "funit": "cross-env BROWSER=firefox node test/test.js", + "wunit": "cross-env BROWSER=webkit node test/test.js", + "unit": "cross-env BROWSER=all node test/test.js", + "ccoverage": "cross-env COVERAGE=true BROWSER=chromium node test/test.js", "fcoverage": "cross-env COVERAGE=true BROWSER=firefox node test/test.js", "wcoverage": "cross-env COVERAGE=true BROWSER=webkit node test/test.js", + "coverage": "cross-env COVERAGE=true BROWSER=all node test/test.js", + "eslint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe --ext js,ts ./src || eslint --ext js,ts ./src", "tsc": "tsc -p .", + "doc": "node utils/doclint/cli.js", + "test-infra": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js && node utils/testrunner/test/test.js", + "lint": "npm run eslint && npm run tsc && npm run doc && npm run test-infra", + "debug-test": "node --inspect-brk test/test.js", "clean": "rimraf lib", + "prepare": "node install-from-github.js", "build": "node utils/runWebpack.js --mode='development' && tsc -p .", "watch": "node utils/runWebpack.js --mode='development' --watch --silent | tsc -w -p .", "version": "node utils/sync_package_versions.js && npm run doc" diff --git a/test/test.js b/test/test.js index bf9fd75112..706e7b5af1 100644 --- a/test/test.js +++ b/test/test.js @@ -77,44 +77,51 @@ beforeEach(async({server, httpsServer}) => { httpsServer.reset(); }); -const products = ['WebKit', 'Firefox', 'Chromium']; -let product; -let events; -let missingCoverage; -if (process.env.BROWSER === 'firefox') { - product = 'Firefox'; - events = { - ...require('../lib/events').Events, - ...require('../lib/chromium/events').Events, - }; - missingCoverage = ['browserContext.setGeolocation', 'browserContext.setOffline']; -} else if (process.env.BROWSER === 'webkit') { - product = 'WebKit'; - events = require('../lib/events').Events; - missingCoverage = ['browserContext.clearPermissions']; -} else { - product = 'Chromium'; - events = require('../lib/events').Events; - missingCoverage = []; -} +const BROWSER_CONFIGS = [ + { + name: 'Firefox', + events: { + ...require('../lib/events').Events, + ...require('../lib/chromium/events').Events, + }, + missingCoverage: ['browserContext.setGeolocation', 'browserContext.setOffline'], + }, + { + name: 'WebKit', + events: require('../lib/events').Events, + missingCoverage: ['browserContext.clearPermissions'], + }, + { + name: 'Chromium', + events: require('../lib/events').Events, + missingCoverage: [], + }, +]; -describe(product, () => { - testRunner.loadTests(require('./playwright.spec.js'), { - product, - playwrightPath: utils.projectRoot(), - testRunner, - }); - if (process.env.COVERAGE) { - const api = require('../lib/api'); - const filteredApi = {}; - Object.keys(api).forEach(name => { - if (products.some(p => name.startsWith(p)) && !name.startsWith(product)) - return; - filteredApi[name] = api[name]; +const browserNames = BROWSER_CONFIGS.map(config => config.name); + +for (const browserConfig of BROWSER_CONFIGS) { + if (process.env.BROWSER !== browserConfig.name.toLowerCase() && process.env.BROWSER !== 'all') + continue; + const product = browserConfig.name; + describe(product, () => { + testRunner.loadTests(require('./playwright.spec.js'), { + product, + playwrightPath: utils.projectRoot(), + testRunner, }); - utils.recordAPICoverage(testRunner, filteredApi, events, missingCoverage); - } -}); + if (process.env.COVERAGE) { + const api = require('../lib/api'); + const filteredApi = {}; + Object.keys(api).forEach(apiName => { + if (browserNames.some(browserName => apiName.startsWith(browserName)) && !apiName.startsWith(product)) + return; + filteredApi[apiName] = api[apiName]; + }); + utils.recordAPICoverage(testRunner, filteredApi, browserConfig.events, browserConfig.missingCoverage); + } + }); +} if (process.env.CI && testRunner.hasFocusedTestsOrSuites()) { console.error('ERROR: "focused" tests/suites are prohibited on bots. Remove any "fit"/"fdescribe" declarations.');