diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f332fdc4..04502762 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore index 58dd0577..391fe991 100644 --- a/.gitignore +++ b/.gitignore @@ -21,5 +21,6 @@ new-docs/ puppeteer*.tgz docs-api-json/ docs-dist/ +coverage website/docs docs/api.html diff --git a/mocha-config/coverage-tests.js b/mocha-config/coverage-tests.js deleted file mode 100644 index 0525532c..00000000 --- a/mocha-config/coverage-tests.js +++ /dev/null @@ -1,6 +0,0 @@ -const base = require('./base.js'); - -module.exports = { - ...base, - spec: 'test/assert-coverage-test.js', -}; diff --git a/package.json b/package.json index 954a5cd9..bf246949 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/assert-coverage-test.js b/test/assert-coverage-test.js deleted file mode 100644 index a63175e6..00000000 --- a/test/assert-coverage-test.js +++ /dev/null @@ -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); - }); -}); diff --git a/test/mocha-utils.ts b/test/mocha-utils.ts index 88dfacf3..990f1282 100644 --- a/test/mocha-utils.ts +++ b/test/mocha-utils.ts @@ -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 => { @@ -302,7 +291,6 @@ export const mochaHooks = { await state.httpsServer.stop(); state.httpsServer = null; }, - coverageHooks.afterAll, ], afterEach: (): void => {