From dd024344f83bd8bfb0ff643879167c8d79a30d2d Mon Sep 17 00:00:00 2001 From: Oleksii Raspopov Date: Tue, 2 Apr 2024 14:39:28 -0400 Subject: [PATCH] dependencies update; minor adjustements --- docs/package.json | 2 +- docs/ref/rollwright.md | 10 +++++- examples/angular/package.json | 2 +- examples/react/package.json | 6 ++-- package.json | 2 +- .../rollup-plugin-worker-url/package.json | 2 +- packages/rollwright/coverage-collector.js | 20 ++++++------ packages/rollwright/fixture.d.ts | 8 ++--- packages/rollwright/fixture.js | 32 +++++++++++-------- packages/rollwright/package.json | 6 ++-- 10 files changed, 51 insertions(+), 39 deletions(-) diff --git a/docs/package.json b/docs/package.json index a81e21d..0b5ad02 100644 --- a/docs/package.json +++ b/docs/package.json @@ -7,7 +7,7 @@ "build": "vitepress build" }, "dependencies": { - "vitepress": "^1.0.0-rc.45" + "vitepress": "^1.0.2" }, "prettier": { "printWidth": 80, diff --git a/docs/ref/rollwright.md b/docs/ref/rollwright.md index 9222f5e..77d3980 100644 --- a/docs/ref/rollwright.md +++ b/docs/ref/rollwright.md @@ -34,4 +34,12 @@ relative to the test file. extensions: Array; ``` - +## `coverage` + +```ts +coverage: false | { + include: Array; + exclude: Array; + extensions: Array; +} +``` diff --git a/examples/angular/package.json b/examples/angular/package.json index f377e7e..6453594 100644 --- a/examples/angular/package.json +++ b/examples/angular/package.json @@ -10,7 +10,7 @@ "@angular/compiler": "^17.3.0", "@angular/core": "^17.3.0", "@angular/platform-browser": "^17.3.0", - "@angular/platform-browser-dynamic": "^17.3.0", + "@angular/platform-browser-dynamic": "^17.3.2", "@playwright/test": "^1.42.1", "@rollup/plugin-swc": "^0.3.0", "rollwright": "file:../../packages/rollwright", diff --git a/examples/react/package.json b/examples/react/package.json index fdd6cc8..0ad9fb3 100644 --- a/examples/react/package.json +++ b/examples/react/package.json @@ -10,9 +10,9 @@ "@radix-ui/react-dialog": "^1.0.5", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-inject": "^5.0.5", - "@types/node": "^20.11.28", - "@types/react": "^18.2.67", - "@types/react-dom": "^18.2.22", + "@types/node": "^20.12.2", + "@types/react": "^18.2.74", + "@types/react-dom": "^18.2.23", "@types/sinon": "^17.0.3", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/package.json b/package.json index 332984e..b4e114f 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ ], "dependencies": { "prettier": "^3.2.5", - "typescript": "^5.4.2" + "typescript": "^5.4.3" }, "prettier": { "printWidth": 100, diff --git a/packages/rollup-plugin-worker-url/package.json b/packages/rollup-plugin-worker-url/package.json index 6f1058c..562efd3 100644 --- a/packages/rollup-plugin-worker-url/package.json +++ b/packages/rollup-plugin-worker-url/package.json @@ -9,7 +9,7 @@ "test": "node --test --experimental-test-coverage" }, "peerDependencies": { - "rollup": "^4.13.0" + "rollup": "^4.13.2" }, "dependencies": { "magic-string": "^0.30.8" diff --git a/packages/rollwright/coverage-collector.js b/packages/rollwright/coverage-collector.js index 46e46ae..1169a6f 100644 --- a/packages/rollwright/coverage-collector.js +++ b/packages/rollwright/coverage-collector.js @@ -15,7 +15,7 @@ export function createCoverageCollector(enable, server, page) { let coverageMap = libCoverage.createCoverageMap(); let events = new EventEmitter(); if (enable) { - server.post("/__register__", async (ctx) => { + server.post("/__register__", (ctx) => { counter++; return ctx.body(null, 200); }); @@ -48,6 +48,14 @@ export function createCoverageCollector(enable, server, page) { }; } +let sender = `/* istanbul ignore next */ (async function report() { + await fetch('/__register__', { method: "POST" }); + if (self.__source__ == null) self.__source__ = new EventSource('/__events__'); + self.__source__.addEventListener('coverage', () => { + fetch('/__coverage__', { method: 'POST', body: JSON.stringify(self.__coverage__) }) + }); +})();`; + /** * @typedef Options * @property {import("@rollup/pluginutils").FilterPattern} [include] @@ -63,16 +71,8 @@ function coverage(options) { if (!filter(id)) return; let instrumenter = libInstrument.createInstrumenter(); let sourceMaps = this.getCombinedSourcemap(); - let sender = `/* istanbul ignore next */ (async function report() { - await fetch('/__register__', { method: "POST" }); - if (self.__source__ == null) self.__source__ = new EventSource('/__events__'); - self.__source__.addEventListener('coverage', () => { - fetch('/__coverage__', { method: 'POST', body: JSON.stringify(self.__coverage__) }) - }); - })();`; let instrumentedCode = instrumenter.instrumentSync(code, id, sourceMaps); - instrumentedCode = sender + instrumentedCode; - return { code: instrumentedCode, map: instrumenter.lastSourceMap() }; + return { code: sender + instrumentedCode, map: instrumenter.lastSourceMap() }; }, }; } diff --git a/packages/rollwright/fixture.d.ts b/packages/rollwright/fixture.d.ts index eb16dc8..97f7076 100644 --- a/packages/rollwright/fixture.d.ts +++ b/packages/rollwright/fixture.d.ts @@ -12,11 +12,9 @@ export type RollwrightFixtures = { plugins: Plugin[]; template: string | { html: string; root: string | null }; extensions: string[]; - coverage: { - extensions: string[]; - include: (string | RegExp)[]; - exclude: (string | RegExp)[]; - }; + coverage: + | false + | { extensions: string[]; include: (string | RegExp)[]; exclude: (string | RegExp)[] }; execute: ( fn: (...args: Unboxed) => Output, ...args: Args diff --git a/packages/rollwright/fixture.js b/packages/rollwright/fixture.js index 6a1c263..70fcb1f 100644 --- a/packages/rollwright/fixture.js +++ b/packages/rollwright/fixture.js @@ -41,9 +41,11 @@ async function rlcache({}, use) { async function execute({ page, rlcache, plugins, template, extensions, coverage }, use, testInfo) { let reporterName = "rollwright/coverage-reporter"; - let shouldInstrument = testInfo.config.reporter.some( - (v) => v != null && (v.includes(reporterName) || v[0].includes(reporterName)), - ); + let shouldInstrument = + coverage !== false && + testInfo.config.reporter.some( + (v) => v != null && (v.includes(reporterName) || v[0].includes(reporterName)), + ); let server = new Hono(); let connect = null; @@ -76,15 +78,19 @@ async function execute({ page, rlcache, plugins, template, extensions, coverage treeshake: false, plugins: [ ...plugins, - coverageCollector.instrument({ - include: coverage?.include ?? [], - exclude: [ - new RegExp(input.replace(/\./, "\\.")), - /node_modules/, - ...(coverage?.exclude ?? []), - ...(coverage?.extensions?.length > 0 ? [`!(*{${coverage.extensions.join(",")}})`] : []), - ], - }), + coverage !== false + ? coverageCollector.instrument({ + include: coverage?.include ?? [], + exclude: [ + new RegExp(input.replace(/\./, "\\.")), + /node_modules/, + ...(coverage?.exclude ?? []), + ...(coverage?.extensions?.length > 0 + ? [`!(*{${coverage.extensions.join(",")}})`] + : []), + ], + }) + : [], nodeResolve({ browser: true, rootDir: dirname(filename), extensions }), ...files, ], @@ -95,7 +101,7 @@ async function execute({ page, rlcache, plugins, template, extensions, coverage format: "esm", generatedCode: "es2015", preserveModules: true, - root: dirname(filename), + dir: dirname(filename), minifyInternalExports: false, }); rlcache.save(bundle.cache); diff --git a/packages/rollwright/package.json b/packages/rollwright/package.json index c590510..c5703b5 100644 --- a/packages/rollwright/package.json +++ b/packages/rollwright/package.json @@ -11,13 +11,13 @@ "types": "./fixture.d.ts", "peerDependencies": { "@playwright/test": "^1.42.1", - "rollup": "^4.13.0" + "rollup": "^4.13.2" }, "dependencies": { - "@hono/node-server": "^1.8.2", + "@hono/node-server": "^1.9.1", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/pluginutils": "^5.1.0", - "hono": "^4.1.1", + "hono": "^4.2.0", "istanbul-lib-coverage": "^3.2.2", "istanbul-lib-instrument": "^6.0.2", "istanbul-lib-report": "^3.0.1",