Skip to content

Commit

Permalink
dependencies update; minor adjustements
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyraspopov committed Apr 2, 2024
1 parent c08ecd6 commit dd02434
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "vitepress build"
},
"dependencies": {
"vitepress": "^1.0.0-rc.45"
"vitepress": "^1.0.2"
},
"prettier": {
"printWidth": 80,
Expand Down
10 changes: 9 additions & 1 deletion docs/ref/rollwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ relative to the test file.
extensions: Array<string>;
```

<!-- ## `coverage` -->
## `coverage`

```ts
coverage: false | {
include: Array<string | RegExp>;
exclude: Array<string | RegExp>;
extensions: Array<string>;
}
```
2 changes: 1 addition & 1 deletion examples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"dependencies": {
"prettier": "^3.2.5",
"typescript": "^5.4.2"
"typescript": "^5.4.3"
},
"prettier": {
"printWidth": 100,
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup-plugin-worker-url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 10 additions & 10 deletions packages/rollwright/coverage-collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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]
Expand All @@ -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() };
},
};
}
8 changes: 3 additions & 5 deletions packages/rollwright/fixture.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Output, Args extends unknown[]>(
fn: (...args: Unboxed<Args>) => Output,
...args: Args
Expand Down
32 changes: 19 additions & 13 deletions packages/rollwright/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
],
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/rollwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dd02434

Please sign in to comment.