@remix-run/test 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -50
- package/dist/app/client/entry.d.ts +2 -0
- package/dist/app/client/entry.d.ts.map +1 -0
- package/dist/app/client/entry.js +328 -0
- package/dist/app/client/iframe.d.ts +2 -0
- package/dist/app/client/iframe.d.ts.map +1 -0
- package/dist/app/client/iframe.js +22 -0
- package/dist/app/server.d.ts +6 -0
- package/dist/app/server.d.ts.map +1 -0
- package/dist/app/server.js +303 -0
- package/dist/cli-entry.d.ts +3 -0
- package/dist/cli-entry.d.ts.map +1 -0
- package/dist/cli-entry.js +14 -0
- package/dist/cli.d.ts +7 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +319 -140
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/colors.d.ts +2 -0
- package/dist/lib/colors.d.ts.map +1 -0
- package/dist/lib/colors.js +2 -0
- package/dist/lib/config.d.ts +59 -14
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +181 -38
- package/dist/lib/context.d.ts +37 -13
- package/dist/lib/context.d.ts.map +1 -1
- package/dist/lib/context.js +19 -3
- package/dist/lib/coverage-loader.d.ts +16 -0
- package/dist/lib/coverage-loader.d.ts.map +1 -0
- package/dist/lib/coverage-loader.js +20 -0
- package/dist/lib/coverage.d.ts +28 -0
- package/dist/lib/coverage.d.ts.map +1 -0
- package/dist/lib/coverage.js +212 -0
- package/dist/lib/executor.d.ts +3 -26
- package/dist/lib/executor.d.ts.map +1 -1
- package/dist/lib/executor.js +11 -6
- package/dist/lib/fake-timers.d.ts +13 -0
- package/dist/lib/fake-timers.d.ts.map +1 -0
- package/dist/lib/fake-timers.js +64 -0
- package/dist/lib/import-module.d.ts +2 -0
- package/dist/lib/import-module.d.ts.map +1 -0
- package/dist/lib/import-module.js +38 -0
- package/dist/lib/normalize.d.ts +2 -0
- package/dist/lib/normalize.d.ts.map +1 -0
- package/dist/lib/{utils.js → normalize.js} +0 -9
- package/dist/lib/playwright.d.ts +1 -1
- package/dist/lib/playwright.d.ts.map +1 -1
- package/dist/lib/playwright.js +5 -8
- package/dist/lib/reporters/dot.d.ts +1 -2
- package/dist/lib/reporters/dot.d.ts.map +1 -1
- package/dist/lib/reporters/dot.js +12 -1
- package/dist/lib/reporters/files.d.ts +1 -2
- package/dist/lib/reporters/files.d.ts.map +1 -1
- package/dist/lib/reporters/files.js +12 -1
- package/dist/lib/reporters/index.d.ts +4 -5
- package/dist/lib/reporters/index.d.ts.map +1 -1
- package/dist/lib/reporters/index.js +3 -3
- package/dist/lib/reporters/results.d.ts +30 -0
- package/dist/lib/reporters/results.d.ts.map +1 -0
- package/dist/lib/reporters/results.js +1 -0
- package/dist/lib/reporters/spec.d.ts +1 -2
- package/dist/lib/reporters/spec.d.ts.map +1 -1
- package/dist/lib/reporters/spec.js +12 -1
- package/dist/lib/reporters/tap.d.ts +1 -2
- package/dist/lib/reporters/tap.d.ts.map +1 -1
- package/dist/lib/reporters/tap.js +11 -1
- package/dist/lib/runner-browser.d.ts +21 -0
- package/dist/lib/runner-browser.d.ts.map +1 -0
- package/dist/lib/runner-browser.js +123 -0
- package/dist/lib/runner.d.ts +24 -2
- package/dist/lib/runner.d.ts.map +1 -1
- package/dist/lib/runner.js +216 -38
- package/dist/lib/runtime.d.ts +2 -0
- package/dist/lib/runtime.d.ts.map +1 -0
- package/dist/lib/runtime.js +2 -0
- package/dist/lib/ts-transform.d.ts +4 -0
- package/dist/lib/ts-transform.d.ts.map +1 -0
- package/dist/lib/ts-transform.js +29 -0
- package/dist/lib/worker-e2e-file.d.ts +11 -0
- package/dist/lib/worker-e2e-file.d.ts.map +1 -0
- package/dist/lib/worker-e2e-file.js +69 -0
- package/dist/lib/worker-e2e.js +11 -46
- package/dist/lib/worker-process.d.ts +2 -0
- package/dist/lib/worker-process.d.ts.map +1 -0
- package/dist/lib/worker-process.js +55 -0
- package/dist/lib/worker-results.d.ts +3 -0
- package/dist/lib/worker-results.d.ts.map +1 -0
- package/dist/lib/worker-results.js +20 -0
- package/dist/lib/worker-server.d.ts +10 -0
- package/dist/lib/worker-server.d.ts.map +1 -0
- package/dist/lib/worker-server.js +113 -0
- package/dist/lib/worker.js +7 -28
- package/dist/test/coverage/fixture.d.ts +5 -0
- package/dist/test/coverage/fixture.d.ts.map +1 -0
- package/dist/test/coverage/fixture.js +32 -0
- package/dist/test/coverage/test-browser.d.ts +2 -0
- package/dist/test/coverage/test-browser.d.ts.map +1 -0
- package/dist/test/coverage/test-browser.js +24 -0
- package/dist/test/coverage/test-e2e.d.ts +2 -0
- package/dist/test/coverage/test-e2e.d.ts.map +1 -0
- package/dist/test/coverage/test-e2e.js +60 -0
- package/dist/test/coverage/test-unit.d.ts +2 -0
- package/dist/test/coverage/test-unit.d.ts.map +1 -0
- package/dist/test/coverage/test-unit.js +27 -0
- package/dist/test/framework.test.browser.d.ts +2 -0
- package/dist/test/framework.test.browser.d.ts.map +1 -0
- package/dist/test/framework.test.browser.js +107 -0
- package/dist/test/framework.test.e2e.d.ts.map +1 -0
- package/dist/test/framework.test.e2e.js +34 -0
- package/package.json +30 -9
- package/src/app/client/entry.ts +357 -0
- package/src/app/client/iframe.ts +18 -0
- package/src/app/server.ts +336 -0
- package/src/cli-entry.ts +15 -0
- package/src/cli.ts +382 -145
- package/src/index.ts +2 -1
- package/src/lib/colors.ts +3 -0
- package/src/lib/config.ts +266 -54
- package/src/lib/context.ts +59 -17
- package/src/lib/coverage-loader.ts +31 -0
- package/src/lib/coverage.ts +320 -0
- package/src/lib/executor.ts +18 -35
- package/src/lib/fake-timers.ts +89 -0
- package/src/lib/import-module.ts +39 -0
- package/src/lib/{utils.ts → normalize.ts} +0 -18
- package/src/lib/playwright.ts +5 -7
- package/src/lib/reporters/dot.ts +12 -2
- package/src/lib/reporters/files.ts +12 -2
- package/src/lib/reporters/index.ts +4 -5
- package/src/lib/reporters/results.ts +29 -0
- package/src/lib/reporters/spec.ts +12 -2
- package/src/lib/reporters/tap.ts +11 -2
- package/src/lib/runner-browser.ts +171 -0
- package/src/lib/runner.ts +308 -53
- package/src/lib/runtime.ts +2 -0
- package/src/lib/ts-transform.ts +36 -0
- package/src/lib/worker-e2e-file.ts +98 -0
- package/src/lib/worker-e2e.ts +14 -49
- package/src/lib/worker-process.ts +69 -0
- package/src/lib/worker-results.ts +22 -0
- package/src/lib/worker-server.ts +123 -0
- package/src/lib/worker.ts +8 -28
- package/src/test/coverage/fixture.ts +34 -0
- package/src/test/coverage/test-browser.ts +29 -0
- package/src/test/coverage/test-e2e.ts +70 -0
- package/src/test/coverage/test-unit.ts +32 -0
- package/tsconfig.json +3 -1
- package/dist/lib/e2e-server.d.ts +0 -11
- package/dist/lib/e2e-server.d.ts.map +0 -1
- package/dist/lib/e2e-server.js +0 -15
- package/dist/lib/framework.test.d.ts +0 -2
- package/dist/lib/framework.test.d.ts.map +0 -1
- package/dist/lib/framework.test.e2e.d.ts.map +0 -1
- package/dist/lib/framework.test.e2e.js +0 -29
- package/dist/lib/framework.test.js +0 -283
- package/dist/lib/utils.d.ts +0 -16
- package/dist/lib/utils.d.ts.map +0 -1
- package/src/lib/e2e-server.ts +0 -28
- /package/dist/{lib → test}/framework.test.e2e.d.ts +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { runTests } from "./executor.js";
|
|
2
|
+
import { importModule } from "./import-module.js";
|
|
3
|
+
import { getBrowserLauncher, getPlaywrightLaunchOptions, getPlaywrightPageOptions, } from "./playwright.js";
|
|
4
|
+
import { createFailedResults } from "./worker-results.js";
|
|
5
|
+
import { isRecord, parseCoverageConfig } from "./worker-server.js";
|
|
6
|
+
export async function runE2ETestFile(value, onOpenResults) {
|
|
7
|
+
try {
|
|
8
|
+
let workerData = parseE2ETestWorkerData(value);
|
|
9
|
+
await importModule(workerData.file, import.meta);
|
|
10
|
+
let launcher = await getBrowserLauncher(workerData.playwrightUseOpts);
|
|
11
|
+
let opts = getPlaywrightLaunchOptions(workerData.playwrightUseOpts);
|
|
12
|
+
let browser = await launcher.launch(opts);
|
|
13
|
+
let browserClosed = false;
|
|
14
|
+
try {
|
|
15
|
+
let results = await runTests({
|
|
16
|
+
browser,
|
|
17
|
+
open: workerData.open ?? false,
|
|
18
|
+
playwrightPageOptions: getPlaywrightPageOptions(workerData.playwrightUseOpts),
|
|
19
|
+
coverage: !!workerData.coverage,
|
|
20
|
+
});
|
|
21
|
+
if (workerData.open) {
|
|
22
|
+
await onOpenResults?.(results);
|
|
23
|
+
console.log('\nBrowser is open. Press Ctrl+C to close.');
|
|
24
|
+
await new Promise((resolve) => browser.on('disconnected', () => resolve()));
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
await browser.close();
|
|
28
|
+
browserClosed = true;
|
|
29
|
+
return results;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
if (!browserClosed) {
|
|
33
|
+
await browser.close();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return createFailedResults(error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function parseE2ETestWorkerData(value) {
|
|
42
|
+
if (!isRecord(value) || typeof value.file !== 'string') {
|
|
43
|
+
throw new Error('Invalid E2E test worker data');
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
file: value.file,
|
|
47
|
+
coverage: parseCoverageConfig(value.coverage),
|
|
48
|
+
open: parseBoolean(value.open, 'open'),
|
|
49
|
+
playwrightUseOpts: parsePlaywrightUseOpts(value.playwrightUseOpts),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function parseBoolean(value, name) {
|
|
53
|
+
if (value === undefined) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (typeof value !== 'boolean') {
|
|
57
|
+
throw new Error(`Invalid E2E test worker ${name}`);
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
function parsePlaywrightUseOpts(value) {
|
|
62
|
+
if (value === undefined) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
if (!isRecord(value)) {
|
|
66
|
+
throw new Error('Invalid E2E test worker playwright options');
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
package/dist/lib/worker-e2e.js
CHANGED
|
@@ -1,48 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { getBrowserLauncher, getPlaywrightLaunchOptions, getPlaywrightPageOptions, } from "./playwright.js";
|
|
6
|
-
try {
|
|
7
|
-
await tsImport(workerData.file, import.meta.url);
|
|
8
|
-
let launcher = await getBrowserLauncher(workerData.playwrightUseOpts);
|
|
9
|
-
let opts = getPlaywrightLaunchOptions(workerData.playwrightUseOpts);
|
|
10
|
-
let browser = await launcher.launch(opts);
|
|
11
|
-
try {
|
|
12
|
-
let results = await runTests({
|
|
13
|
-
browser,
|
|
14
|
-
createServer,
|
|
15
|
-
open: workerData.open,
|
|
16
|
-
playwrightPageOptions: getPlaywrightPageOptions(workerData.playwrightUseOpts),
|
|
17
|
-
});
|
|
18
|
-
parentPort.postMessage(results);
|
|
19
|
-
if (workerData.open) {
|
|
20
|
-
console.log('\nBrowser is open. Press Ctrl+C to close.');
|
|
21
|
-
await new Promise((resolve) => browser.on('disconnected', () => resolve()));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
finally {
|
|
25
|
-
await browser.close();
|
|
26
|
-
}
|
|
1
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
import { runE2ETestFile } from "./worker-e2e-file.js";
|
|
3
|
+
if (!parentPort) {
|
|
4
|
+
throw new Error('E2E test worker is missing a parent port');
|
|
27
5
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
tests: [
|
|
35
|
-
{
|
|
36
|
-
name: '',
|
|
37
|
-
suiteName: '',
|
|
38
|
-
status: 'failed',
|
|
39
|
-
duration: 0,
|
|
40
|
-
error: {
|
|
41
|
-
message: e instanceof Error ? e.message : String(e),
|
|
42
|
-
stack: e instanceof Error ? e.stack : undefined,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
};
|
|
47
|
-
parentPort.postMessage(results);
|
|
6
|
+
const port = parentPort;
|
|
7
|
+
const results = await runE2ETestFile(workerData, (openResults) => {
|
|
8
|
+
port.postMessage(openResults);
|
|
9
|
+
});
|
|
10
|
+
if (results) {
|
|
11
|
+
port.postMessage(results);
|
|
48
12
|
}
|
|
13
|
+
process.exit(0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-process.d.ts","sourceRoot":"","sources":["../../src/lib/worker-process.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { runE2ETestFile } from "./worker-e2e-file.js";
|
|
2
|
+
import { runServerTestFile } from "./worker-server.js";
|
|
3
|
+
import { createFailedResults } from "./worker-results.js";
|
|
4
|
+
const workerData = await readWorkerData();
|
|
5
|
+
const results = await runWorkerProcessFile(workerData);
|
|
6
|
+
if (results) {
|
|
7
|
+
await sendResults(results);
|
|
8
|
+
}
|
|
9
|
+
if (process.connected) {
|
|
10
|
+
process.disconnect();
|
|
11
|
+
}
|
|
12
|
+
process.exitCode = 0;
|
|
13
|
+
function readWorkerData() {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
function cleanup() {
|
|
16
|
+
process.off('message', onMessage);
|
|
17
|
+
process.off('disconnect', onDisconnect);
|
|
18
|
+
}
|
|
19
|
+
function onMessage(value) {
|
|
20
|
+
cleanup();
|
|
21
|
+
resolve(value);
|
|
22
|
+
}
|
|
23
|
+
function onDisconnect() {
|
|
24
|
+
cleanup();
|
|
25
|
+
reject(new Error('Test worker process disconnected'));
|
|
26
|
+
}
|
|
27
|
+
process.once('message', onMessage);
|
|
28
|
+
process.once('disconnect', onDisconnect);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function runWorkerProcessFile(value) {
|
|
32
|
+
try {
|
|
33
|
+
if (!isRecord(value) || (value.type !== 'server' && value.type !== 'e2e')) {
|
|
34
|
+
throw new Error('Invalid test worker process data');
|
|
35
|
+
}
|
|
36
|
+
return value.type === 'e2e'
|
|
37
|
+
? await runE2ETestFile(value, sendResults)
|
|
38
|
+
: await runServerTestFile(value);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return createFailedResults(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function sendResults(results) {
|
|
45
|
+
if (!process.send) {
|
|
46
|
+
throw new Error('Test worker process is missing an IPC channel');
|
|
47
|
+
}
|
|
48
|
+
let send = process.send.bind(process);
|
|
49
|
+
await new Promise((resolve, reject) => {
|
|
50
|
+
send(results, undefined, undefined, (error) => (error ? reject(error) : resolve()));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function isRecord(value) {
|
|
54
|
+
return typeof value === 'object' && value !== null;
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-results.d.ts","sourceRoot":"","sources":["../../src/lib/worker-results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEzD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAmB/D"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function createFailedResults(error) {
|
|
2
|
+
return {
|
|
3
|
+
passed: 0,
|
|
4
|
+
failed: 1,
|
|
5
|
+
skipped: 0,
|
|
6
|
+
todo: 0,
|
|
7
|
+
tests: [
|
|
8
|
+
{
|
|
9
|
+
name: '',
|
|
10
|
+
suiteName: '',
|
|
11
|
+
status: 'failed',
|
|
12
|
+
duration: 0,
|
|
13
|
+
error: {
|
|
14
|
+
message: error instanceof Error ? error.message : String(error),
|
|
15
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CoverageConfig } from './coverage.ts';
|
|
2
|
+
import type { TestResults } from './reporters/results.ts';
|
|
3
|
+
export interface ServerTestWorkerData {
|
|
4
|
+
file: string;
|
|
5
|
+
coverage?: CoverageConfig;
|
|
6
|
+
}
|
|
7
|
+
export declare function runServerTestFile(value: unknown): Promise<TestResults>;
|
|
8
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
9
|
+
export declare function parseCoverageConfig(value: unknown): CoverageConfig | undefined;
|
|
10
|
+
//# sourceMappingURL=worker-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-server.d.ts","sourceRoot":"","sources":["../../src/lib/worker-server.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAKzD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,cAAc,CAAA;CAC1B;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAiC5E;AAaD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CA2B9E"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import * as mod from 'node:module';
|
|
10
|
+
import { IS_RUNNING_FROM_SRC } from "./config.js";
|
|
11
|
+
import { importModule } from "./import-module.js";
|
|
12
|
+
import { runTests } from "./executor.js";
|
|
13
|
+
import { IS_BUN } from "./runtime.js";
|
|
14
|
+
import { createFailedResults } from "./worker-results.js";
|
|
15
|
+
export async function runServerTestFile(value) {
|
|
16
|
+
let workerData;
|
|
17
|
+
try {
|
|
18
|
+
workerData = parseServerTestWorkerData(value);
|
|
19
|
+
// When coverage is enabled in Node, we use a coverage-friendly TypeScript loader which
|
|
20
|
+
// replaces tsx's minified transformation with a non-minified esbuild transform
|
|
21
|
+
// so V8 coverage byte offsets align with readable source lines. This hook runs
|
|
22
|
+
// before the inherited tsx hook (hooks are LIFO), so it intercepts .ts imports and
|
|
23
|
+
// short-circuits before tsx transforms them.
|
|
24
|
+
if (workerData.coverage && !IS_BUN) {
|
|
25
|
+
// Ensure we load the right file whether we're running in the monorepo (TS) or
|
|
26
|
+
// from a published package (JS)
|
|
27
|
+
let ext = IS_RUNNING_FROM_SRC ? '.ts' : '.js';
|
|
28
|
+
mod.register(new URL(`./coverage-loader${ext}`, import.meta.url), import.meta.url);
|
|
29
|
+
await import(__rewriteRelativeImportExtension(workerData.file));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
await importModule(workerData.file, import.meta);
|
|
33
|
+
}
|
|
34
|
+
let results = await runTests();
|
|
35
|
+
await takeCoverage(workerData.coverage);
|
|
36
|
+
return results;
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
try {
|
|
40
|
+
await takeCoverage(workerData?.coverage);
|
|
41
|
+
}
|
|
42
|
+
catch (coverageError) {
|
|
43
|
+
e = coverageError;
|
|
44
|
+
}
|
|
45
|
+
return createFailedResults(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function parseServerTestWorkerData(value) {
|
|
49
|
+
if (!isRecord(value) || typeof value.file !== 'string') {
|
|
50
|
+
throw new Error('Invalid server test worker data');
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
file: value.file,
|
|
54
|
+
coverage: parseCoverageConfig(value.coverage),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function isRecord(value) {
|
|
58
|
+
return typeof value === 'object' && value !== null;
|
|
59
|
+
}
|
|
60
|
+
export function parseCoverageConfig(value) {
|
|
61
|
+
if (value === undefined) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
if (!isRecord(value) || typeof value.dir !== 'string') {
|
|
65
|
+
throw new Error('Invalid server test worker coverage config');
|
|
66
|
+
}
|
|
67
|
+
let coverage = {
|
|
68
|
+
dir: value.dir,
|
|
69
|
+
};
|
|
70
|
+
let include = parseStringArray(value.include, 'include');
|
|
71
|
+
let exclude = parseStringArray(value.exclude, 'exclude');
|
|
72
|
+
let statements = parseNumber(value.statements, 'statements');
|
|
73
|
+
let lines = parseNumber(value.lines, 'lines');
|
|
74
|
+
let branches = parseNumber(value.branches, 'branches');
|
|
75
|
+
let functions = parseNumber(value.functions, 'functions');
|
|
76
|
+
if (include)
|
|
77
|
+
coverage.include = include;
|
|
78
|
+
if (exclude)
|
|
79
|
+
coverage.exclude = exclude;
|
|
80
|
+
if (statements !== undefined)
|
|
81
|
+
coverage.statements = statements;
|
|
82
|
+
if (lines !== undefined)
|
|
83
|
+
coverage.lines = lines;
|
|
84
|
+
if (branches !== undefined)
|
|
85
|
+
coverage.branches = branches;
|
|
86
|
+
if (functions !== undefined)
|
|
87
|
+
coverage.functions = functions;
|
|
88
|
+
return coverage;
|
|
89
|
+
}
|
|
90
|
+
function parseStringArray(value, name) {
|
|
91
|
+
if (value === undefined) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) {
|
|
95
|
+
throw new Error(`Invalid server test worker coverage ${name}`);
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
function parseNumber(value, name) {
|
|
100
|
+
if (value === undefined) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
if (typeof value !== 'number') {
|
|
104
|
+
throw new Error(`Invalid server test worker coverage ${name}`);
|
|
105
|
+
}
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
async function takeCoverage(coverage) {
|
|
109
|
+
if (coverage && !IS_BUN) {
|
|
110
|
+
let v8 = await import('node:v8');
|
|
111
|
+
v8.takeCoverage();
|
|
112
|
+
}
|
|
113
|
+
}
|
package/dist/lib/worker.js
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
await tsImport(workerData.file, import.meta.url);
|
|
6
|
-
let results = await runTests();
|
|
7
|
-
parentPort.postMessage(results);
|
|
8
|
-
}
|
|
9
|
-
catch (e) {
|
|
10
|
-
let results = {
|
|
11
|
-
passed: 0,
|
|
12
|
-
failed: 1,
|
|
13
|
-
skipped: 0,
|
|
14
|
-
todo: 0,
|
|
15
|
-
tests: [
|
|
16
|
-
{
|
|
17
|
-
name: '',
|
|
18
|
-
suiteName: '',
|
|
19
|
-
status: 'failed',
|
|
20
|
-
duration: 0,
|
|
21
|
-
error: {
|
|
22
|
-
message: e instanceof Error ? e.message : String(e),
|
|
23
|
-
stack: e instanceof Error ? e.stack : undefined,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
};
|
|
28
|
-
parentPort.postMessage(results);
|
|
1
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
import { runServerTestFile } from "./worker-server.js";
|
|
3
|
+
if (!parentPort) {
|
|
4
|
+
throw new Error('Server test worker is missing a parent port');
|
|
29
5
|
}
|
|
6
|
+
const results = await runServerTestFile(workerData);
|
|
7
|
+
parentPort.postMessage(results);
|
|
8
|
+
process.exit(0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../../src/test/coverage/fixture.ts"],"names":[],"mappings":"AAKA,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhD;AAGD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAGD,wBAAgB,gBAAgB,IAAI,MAAM,CAIzC;AAGD,wBAAgB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAK3C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// This file exists solely to validate coverage accuracy.
|
|
2
|
+
// Each function has a known expected coverage profile based on
|
|
3
|
+
// which paths the associated tests exercise.
|
|
4
|
+
// Fully covered — both statements and the single branch
|
|
5
|
+
export function add(a, b) {
|
|
6
|
+
return a + b;
|
|
7
|
+
}
|
|
8
|
+
// Partially covered — only the `n > 0` branch is tested
|
|
9
|
+
export function classify(n) {
|
|
10
|
+
if (n > 0) {
|
|
11
|
+
return 'positive';
|
|
12
|
+
}
|
|
13
|
+
else if (n < 0) {
|
|
14
|
+
return 'negative';
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return 'zero';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Never called — 0% across the board
|
|
21
|
+
export function uncalledFunction() {
|
|
22
|
+
let result = 'never';
|
|
23
|
+
result += ' reached';
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
// Partially covered — only the truthy `name` branch is tested
|
|
27
|
+
export function greet(name) {
|
|
28
|
+
if (name) {
|
|
29
|
+
return `Hello, ${name}!`;
|
|
30
|
+
}
|
|
31
|
+
return 'Hello, stranger!';
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-browser.d.ts","sourceRoot":"","sources":["../../../src/test/coverage/test-browser.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as assert from '@remix-run/assert';
|
|
2
|
+
import { describe, it } from "../../lib/framework.js";
|
|
3
|
+
import { add, classify, greet } from "./fixture.js";
|
|
4
|
+
// Expected coverage for coverage-fixture.ts (same as the server/e2e fixture
|
|
5
|
+
// tests):
|
|
6
|
+
//
|
|
7
|
+
// add — 100% functions, statements, lines, branches
|
|
8
|
+
// classify — function covered, but only the `n > 0` branch is hit
|
|
9
|
+
// (the `n < 0` and `else` branches are uncovered)
|
|
10
|
+
// uncalledFunction — 0% across the board (never imported)
|
|
11
|
+
// greet — function covered, but only the truthy `name` branch is hit
|
|
12
|
+
// (the fallback `Hello, stranger!` line is uncovered)
|
|
13
|
+
describe('browser coverage fixture', () => {
|
|
14
|
+
it('exercises some but not all code paths in the browser', () => {
|
|
15
|
+
assert.equal(add(2, 3), 5);
|
|
16
|
+
assert.equal(add(-1, 1), 0);
|
|
17
|
+
assert.equal(classify(42), 'positive');
|
|
18
|
+
assert.equal(classify(1), 'positive');
|
|
19
|
+
// deliberately NOT testing classify(-1) or classify(0)
|
|
20
|
+
assert.equal(greet('World'), 'Hello, World!');
|
|
21
|
+
// deliberately NOT testing greet() without an argument
|
|
22
|
+
// deliberately NOT importing or calling uncalledFunction
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-e2e.d.ts","sourceRoot":"","sources":["../../../src/test/coverage/test-e2e.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as assert from '@remix-run/assert';
|
|
2
|
+
import { createTestServer } from '@remix-run/node-fetch-server/test';
|
|
3
|
+
import * as fsp from 'node:fs/promises';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { describe, it } from "../../lib/framework.js";
|
|
6
|
+
import { transformTypeScript } from "../../lib/ts-transform.js";
|
|
7
|
+
// Expected coverage for coverage/fixture.ts (same as the server fixture test):
|
|
8
|
+
//
|
|
9
|
+
// add — 100% functions, statements, lines, branches
|
|
10
|
+
// classify — function covered, but only the `n > 0` branch is hit
|
|
11
|
+
// uncalledFunction — 0% across the board (never called)
|
|
12
|
+
// greet — function covered, but only the truthy `name` branch is hit
|
|
13
|
+
describe('e2e coverage fixture', () => {
|
|
14
|
+
it('exercises some but not all code paths in the browser', async (t) => {
|
|
15
|
+
// Compile the fixture TypeScript to browser-ready JS
|
|
16
|
+
let fixturePath = path.resolve(import.meta.dirname, './fixture.ts');
|
|
17
|
+
let fixtureSource = await fsp.readFile(fixturePath, 'utf-8');
|
|
18
|
+
let { code: fixtureJs } = await transformTypeScript(fixtureSource, fixturePath);
|
|
19
|
+
let handler = (req) => {
|
|
20
|
+
let url = new URL(req.url);
|
|
21
|
+
if (url.pathname === '/') {
|
|
22
|
+
return new Response([
|
|
23
|
+
`<!doctype html>`,
|
|
24
|
+
`<html>`,
|
|
25
|
+
`<body>`,
|
|
26
|
+
` <div id="result"></div>`,
|
|
27
|
+
` <script type="module">`,
|
|
28
|
+
` import { add, classify, greet } from '/src/test/coverage/fixture.ts'`,
|
|
29
|
+
` // Exercise the same paths as the server fixture test:`,
|
|
30
|
+
` // - add: fully covered`,
|
|
31
|
+
` // - classify: only positive branch`,
|
|
32
|
+
` // - greet: only with a name`,
|
|
33
|
+
` // - uncalledFunction: never imported`,
|
|
34
|
+
` let results = [`,
|
|
35
|
+
` add(2, 3),`,
|
|
36
|
+
` add(-1, 1),`,
|
|
37
|
+
` classify(42),`,
|
|
38
|
+
` classify(1),`,
|
|
39
|
+
` greet('World'),`,
|
|
40
|
+
` ]`,
|
|
41
|
+
` document.getElementById('result').textContent = results.join(',')`,
|
|
42
|
+
` </script>`,
|
|
43
|
+
`</body>`,
|
|
44
|
+
`</html>`,
|
|
45
|
+
].join('\n'), { headers: { 'Content-Type': 'text/html' } });
|
|
46
|
+
}
|
|
47
|
+
// Serve the compiled fixture at the path the import expects
|
|
48
|
+
if (url.pathname === '/src/test/coverage/fixture.ts') {
|
|
49
|
+
return new Response(fixtureJs, {
|
|
50
|
+
headers: { 'Content-Type': 'application/javascript' },
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return new Response('Not found', { status: 404 });
|
|
54
|
+
};
|
|
55
|
+
let page = await t.serve(await createTestServer(handler));
|
|
56
|
+
await page.goto('/');
|
|
57
|
+
let result = await page.locator('#result').textContent();
|
|
58
|
+
assert.equal(result, '5,0,positive,positive,Hello, World!');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-unit.d.ts","sourceRoot":"","sources":["../../../src/test/coverage/test-unit.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as assert from '@remix-run/assert';
|
|
2
|
+
import { describe, it } from "../../lib/framework.js";
|
|
3
|
+
import { add, classify, greet } from "./fixture.js";
|
|
4
|
+
// Expected coverage for coverage-fixture.ts:
|
|
5
|
+
//
|
|
6
|
+
// add — 100% functions, statements, lines, branches
|
|
7
|
+
// classify — function covered, but only the `n > 0` branch is hit
|
|
8
|
+
// (the `n < 0` and `else` branches are uncovered)
|
|
9
|
+
// uncalledFunction — 0% across the board (never imported)
|
|
10
|
+
// greet — function covered, but only the truthy `name` branch is hit
|
|
11
|
+
// (the fallback `Hello, stranger!` line is uncovered)
|
|
12
|
+
describe('coverage/fixture.ts', () => {
|
|
13
|
+
it('add returns the sum', () => {
|
|
14
|
+
assert.equal(add(2, 3), 5);
|
|
15
|
+
assert.equal(add(-1, 1), 0);
|
|
16
|
+
});
|
|
17
|
+
it('classify identifies positive numbers only', () => {
|
|
18
|
+
assert.equal(classify(42), 'positive');
|
|
19
|
+
assert.equal(classify(1), 'positive');
|
|
20
|
+
// deliberately NOT testing classify(-1) or classify(0)
|
|
21
|
+
});
|
|
22
|
+
// deliberately NOT importing or calling uncalledFunction
|
|
23
|
+
it('greet with a name only', () => {
|
|
24
|
+
assert.equal(greet('World'), 'Hello, World!');
|
|
25
|
+
// deliberately NOT testing greet() without an argument
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework.test.browser.d.ts","sourceRoot":"","sources":["../../src/test/framework.test.browser.tsx"],"names":[],"mappings":""}
|