Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions tests/_helpers/playwright.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import type { Browser, ConsoleMessage, Page, Request, Response } from "npm:playwright@1.61.1";
import type {
Browser,
ConsoleMessage,
Page,
Request,
Response as PlaywrightResponse,
} from "npm:playwright@1.61.1";
import { fromFileUrl } from "#veryfront/compat/path/index.ts";
export { findHydrationOrCspFailures } from "../../src/testing/browser-diagnostics.mjs";

Expand Down Expand Up @@ -260,15 +266,15 @@ export async function navigateBrowserPage(
url: string,
diagnostics: BrowserDiagnostics,
serverLogs: string[],
): Promise<Response | null> {
): Promise<PlaywrightResponse | null> {
const pending = new Set<Request>();
const responses: { url: string; status: number }[] = [];
const failed: { url: string; error: string | undefined }[] = [];
const onRequest = (request: Request) => {
if (pending.size < 100) pending.add(request);
};
const onFinished = (request: Request) => pending.delete(request);
const onResponse = (response: Response) => {
const onResponse = (response: PlaywrightResponse) => {
if (responses.length < 100) {
responses.push({ url: response.url().slice(0, 2048), status: response.status() });
}
Expand Down
22 changes: 12 additions & 10 deletions tests/integration/ci/node-executor-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,24 @@ describe("native executor source coverage", () => {
"export function positiveOnly() {\n return 1;\n}\nexport function negativeOnly() {\n return 0;\n}\nexport function target(value: number) {\n if (value > 0) return positiveOnly();\n return negativeOnly();\n}\n",
);
try {
const groups = [];
for (const [index, value] of [1, -1].entries()) {
const file = `${directory}/${index}.test.mjs`;
await Deno.writeTextFile(
file,
`import { test } from "node:test"; import { target } from "./source.ts"; test("owned", () => { target(${value}); });`,
);
groups.push({ testFiles: [file], pattern: "", expectedTests: 1 });
}
const wrapper = `${directory}/wrapper.test.mjs`;
await Deno.writeTextFile(
wrapper,
`import { test } from "node:test"; import { runNativeCoverageGroups } from ${
JSON.stringify(`${root}/scripts/test/coverage-node-executor.mjs`)
}; test("collect", async () => { await runNativeCoverageGroups(${JSON.stringify(root)}, ${
JSON.stringify(groups)
}); });`,
[
'import { test } from "node:test";',
'import { fileURLToPath } from "node:url";',
'import { runNativeCoverageGroups } from "../../scripts/test/coverage-node-executor.mjs";',
'const root = fileURLToPath(new URL("../../", import.meta.url));',
'const groups = [0, 1].map((index) => ({ testFiles: [fileURLToPath(new URL(`./${index}.test.mjs`, import.meta.url))], pattern: "", expectedTests: 1 }));',
'test("collect", async () => { await runNativeCoverageGroups(root, groups); });',
].join("\n"),
);
const output = await new Deno.Command("node", {
args: buildNativeCoverageArgs({
Expand Down Expand Up @@ -133,10 +134,11 @@ describe("native executor source coverage", () => {
'import { spawnSync } from "node:child_process";',
'import process from "node:process";',
'import assert from "node:assert/strict";',
'import { fileURLToPath } from "node:url";',
'test("executes child source", () => {',
` const result = spawnSync(process.execPath, ["--enable-source-maps", "--import", ${
JSON.stringify(`${root}/tests/node/resolver.mjs`)
}, ${JSON.stringify(child)}], {`,
' const resolver = fileURLToPath(new URL("../../tests/node/resolver.mjs", import.meta.url));',
' const child = fileURLToPath(new URL("./child.ts", import.meta.url));',
' const result = spawnSync(process.execPath, ["--enable-source-maps", "--import", resolver, child], {',
' env: { NODE_V8_COVERAGE: process.env.NODE_V8_COVERAGE }, encoding: "utf8",',
" });",
" assert.equal(result.status, 0, result.stderr);",
Expand Down
Loading