2020-07-22 19:08:10 +03:00
|
|
|
/**
|
|
|
|
* Copyright Microsoft Corporation. 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
|
|
|
|
*
|
|
|
|
* http://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.
|
|
|
|
*/
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
2020-08-12 23:47:44 +03:00
|
|
|
const {installCoverageHooks} = require('./coverage');
|
2020-07-22 19:08:10 +03:00
|
|
|
|
2021-04-05 19:18:56 +03:00
|
|
|
const browserName = process.argv[2] || 'chromium';
|
2020-07-22 19:08:10 +03:00
|
|
|
|
2021-02-11 21:31:57 +03:00
|
|
|
let api = new Set(installCoverageHooks(browserName).coverage.keys());
|
2020-07-22 19:08:10 +03:00
|
|
|
|
|
|
|
// coverage exceptions
|
|
|
|
|
|
|
|
if (browserName === 'chromium') {
|
|
|
|
// Sometimes we already have a background page while launching, before adding a listener.
|
2021-04-02 04:47:14 +03:00
|
|
|
api.delete('browserContext.emit("backgroundpage")');
|
2020-07-22 19:08:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (browserName !== 'chromium') {
|
|
|
|
// we don't have CDPSession in non-chromium browsers
|
2021-04-05 19:18:56 +03:00
|
|
|
api.delete('browser.newBrowserCDPSession');
|
|
|
|
api.delete('browser.startTracing');
|
|
|
|
api.delete('browser.stopTracing');
|
|
|
|
api.delete('browserContext.backgroundPages');
|
|
|
|
api.delete('browserContext.serviceWorkers');
|
|
|
|
api.delete('browserContext.newCDPSession');
|
|
|
|
api.delete('browserContext.emit("backgroundpage")');
|
|
|
|
api.delete('browserContext.emit("serviceworker")');
|
2020-07-22 19:08:10 +03:00
|
|
|
api.delete('cDPSession.send');
|
|
|
|
api.delete('cDPSession.detach');
|
2021-04-05 19:18:56 +03:00
|
|
|
api.delete('coverage.startJSCoverage');
|
|
|
|
api.delete('coverage.stopJSCoverage');
|
|
|
|
api.delete('coverage.startCSSCoverage');
|
|
|
|
api.delete('coverage.stopCSSCoverage');
|
|
|
|
api.delete('page.pdf');
|
2020-07-22 19:08:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Some permissions tests are disabled in webkit. See permissions.jest.js
|
|
|
|
if (browserName === 'webkit')
|
|
|
|
api.delete('browserContext.clearPermissions');
|
|
|
|
|
2021-06-18 21:04:48 +03:00
|
|
|
// Response interception is not implemented in Firefox yet.
|
|
|
|
if (browserName === 'firefox')
|
|
|
|
api.delete('route.intercept');
|
|
|
|
|
2021-04-06 01:51:45 +03:00
|
|
|
const coverageDir = path.join(__dirname, '..', 'coverage-report');
|
2020-07-22 19:08:10 +03:00
|
|
|
|
|
|
|
const coveredMethods = new Set();
|
|
|
|
for (const file of getCoverageFiles(coverageDir)) {
|
|
|
|
for (const method of JSON.parse(fs.readFileSync(file, 'utf8')))
|
|
|
|
coveredMethods.add(method);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let success = true;
|
|
|
|
for (const method of api) {
|
|
|
|
if (coveredMethods.has(method))
|
|
|
|
continue;
|
|
|
|
success = false;
|
|
|
|
console.log(`ERROR: Missing coverage for "${method}"`)
|
|
|
|
}
|
|
|
|
|
|
|
|
process.exit(success ? 0 : 1);
|
|
|
|
|
|
|
|
function * getCoverageFiles(dir) {
|
|
|
|
for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
|
|
|
|
if (entry.isDirectory())
|
|
|
|
yield * getCoverageFiles(path.join(dir, entry.name))
|
|
|
|
else
|
|
|
|
yield path.join(dir, entry.name);
|
|
|
|
}
|
2020-10-30 20:34:24 +03:00
|
|
|
}
|