mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: use c8 coverage (#8495)
This commit is contained in:
parent
2b5a90dd72
commit
733cbecf48
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -76,7 +76,6 @@ jobs:
|
||||
CHROMIUM: true
|
||||
run: |
|
||||
xvfb-run --auto-servernum npm run test:unit:coverage
|
||||
xvfb-run --auto-servernum npm run test:coverage
|
||||
|
||||
- name: Run unit tests on Firefox
|
||||
uses: nick-invision/retry@v2
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,5 +21,6 @@ new-docs/
|
||||
puppeteer*.tgz
|
||||
docs-api-json/
|
||||
docs-dist/
|
||||
coverage
|
||||
website/docs
|
||||
docs/api.html
|
||||
|
@ -1,6 +0,0 @@
|
||||
const base = require('./base.js');
|
||||
|
||||
module.exports = {
|
||||
...base,
|
||||
spec: 'test/assert-coverage-test.js',
|
||||
};
|
@ -30,13 +30,12 @@
|
||||
"test": "npm run build && npm run lint --silent && npm run test:unit:coverage",
|
||||
"test:unit": "npm run build:tsc:cjs && npm run build:tsc:cjs:compat && mocha --config mocha-config/puppeteer-unit-tests.js",
|
||||
"test:unit:firefox": "cross-env PUPPETEER_PRODUCT=firefox npm run test:unit",
|
||||
"test:unit:coverage": "cross-env COVERAGE=1 npm run test:unit",
|
||||
"test:unit:coverage": "c8 --check-coverage --lines 94 npm run test:unit",
|
||||
"test:unit:chrome-headless": "cross-env HEADLESS=chrome npm run test:unit",
|
||||
"test:protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package",
|
||||
"test:pinned-deps": "ts-node -s scripts/ensure-pinned-deps",
|
||||
"test:install": "scripts/test-install.sh",
|
||||
"test:debug": "npm run build:tsc:cjs && npm run build:tsc:cjs:compat && mocha --inspect-brk --config mocha-config/puppeteer-unit-tests.js",
|
||||
"test:coverage": "cross-env COVERAGE=1 mocha --config mocha-config/coverage-tests.js",
|
||||
"test:types": "ts-node -s scripts/test-ts-definition-files.ts",
|
||||
"prepublishOnly": "npm run build",
|
||||
"prepare": "node typescript-if-required.js && ([[ $HUSKY = 0 ]] || husky install)",
|
||||
@ -100,6 +99,7 @@
|
||||
"@types/ws": "8.5.3",
|
||||
"@typescript-eslint/eslint-plugin": "5.27.0",
|
||||
"@typescript-eslint/parser": "5.27.0",
|
||||
"c8": "7.11.3",
|
||||
"commonmark": "0.30.0",
|
||||
"cross-env": "7.0.3",
|
||||
"eslint": "8.16.0",
|
||||
|
@ -1,38 +0,0 @@
|
||||
const { describe, it } = require('mocha');
|
||||
const { getCoverageResults } = require('./coverage-utils.js');
|
||||
const expect = require('expect');
|
||||
|
||||
const EXCLUDED_METHODS = new Set([
|
||||
'Puppeteer.registerCustomQueryHandler',
|
||||
'Puppeteer.unregisterCustomQueryHandler',
|
||||
'Puppeteer.customQueryHandlerNames',
|
||||
'Puppeteer.clearCustomQueryHandlers',
|
||||
'PuppeteerNode.connect',
|
||||
'PuppeteerNode.launch',
|
||||
'PuppeteerNode.executablePath',
|
||||
'PuppeteerNode.defaultArgs',
|
||||
'PuppeteerNode.createBrowserFetcher',
|
||||
]);
|
||||
|
||||
describe('API coverage test', () => {
|
||||
it('calls every method', () => {
|
||||
if (!process.env.COVERAGE) return;
|
||||
|
||||
const coverageMap = getCoverageResults();
|
||||
const missingMethods = [];
|
||||
for (const method of coverageMap.keys()) {
|
||||
if (!coverageMap.get(method) && !EXCLUDED_METHODS.has(method))
|
||||
missingMethods.push(method);
|
||||
}
|
||||
if (missingMethods.length) {
|
||||
console.error(
|
||||
'\nCoverage check failed: not all API methods called. See above output for list of missing methods.'
|
||||
);
|
||||
console.error(missingMethods.join('\n'));
|
||||
}
|
||||
|
||||
// We know this will fail because we checked above
|
||||
// but we need the actual test to fail.
|
||||
expect(missingMethods.length).toEqual(0);
|
||||
});
|
||||
});
|
@ -30,7 +30,6 @@ import { Page } from '../lib/cjs/puppeteer/common/Page.js';
|
||||
import { PuppeteerNode } from '../lib/cjs/puppeteer/node/Puppeteer.js';
|
||||
import puppeteer from '../lib/cjs/puppeteer/puppeteer.js';
|
||||
import { TestServer } from '../utils/testserver/index.js';
|
||||
import { trackCoverage } from './coverage-utils.js';
|
||||
import utils from './utils.js';
|
||||
|
||||
const setupServer = async () => {
|
||||
@ -225,15 +224,6 @@ export const describeChromeOnly = (
|
||||
if (isChrome) return describe(description, body);
|
||||
};
|
||||
|
||||
let coverageHooks = {
|
||||
beforeAll: (): void => {},
|
||||
afterAll: (): void => {},
|
||||
};
|
||||
|
||||
if (process.env['COVERAGE']) {
|
||||
coverageHooks = trackCoverage();
|
||||
}
|
||||
|
||||
console.log(
|
||||
`Running unit tests with:
|
||||
-> product: ${product}
|
||||
@ -287,7 +277,6 @@ export const mochaHooks = {
|
||||
state.headless = headless;
|
||||
state.puppeteerPath = path.resolve(path.join(__dirname, '..'));
|
||||
},
|
||||
coverageHooks.beforeAll,
|
||||
],
|
||||
|
||||
beforeEach: async (): Promise<void> => {
|
||||
@ -302,7 +291,6 @@ export const mochaHooks = {
|
||||
await state.httpsServer.stop();
|
||||
state.httpsServer = null;
|
||||
},
|
||||
coverageHooks.afterAll,
|
||||
],
|
||||
|
||||
afterEach: (): void => {
|
||||
|
Loading…
Reference in New Issue
Block a user