@rstest/core 0.7.8 → 0.7.9
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/LICENSE.md +294 -0
- package/dist/0~130.js +2 -2
- package/dist/0~1472.js +48 -0
- package/dist/0~1981.js +3 -0
- package/dist/0~2173.js +25 -10
- package/dist/0~2255.js +2 -2
- package/dist/0~3062.js +0 -5
- package/dist/0~3919.js +1 -1
- package/dist/0~4403.js +6 -5
- package/dist/0~4809.js +1 -1
- package/dist/0~5835.js +2 -2
- package/dist/0~62.js +1 -1
- package/dist/0~6588.js +3 -3
- package/dist/0~6923.js +2 -2
- package/dist/0~7583.js +9 -8
- package/dist/0~7882.js +1144 -0
- package/dist/0~8426.js +1 -2
- package/dist/0~89.js +24 -21
- package/dist/0~9348.js +953 -0
- package/dist/0~9634.js +58 -10
- package/dist/1157.js +12 -117
- package/dist/{7913.js → 1294.js} +51 -1745
- package/dist/2672.js +647 -0
- package/dist/3278.js +3 -450
- package/dist/4484.js +38 -0
- package/dist/487.js +1739 -0
- package/dist/4899.js +11 -0
- package/dist/5734.js +1 -1
- package/dist/{0~6151.js → 6151.js} +169 -13
- package/dist/{0~6973.js → 6973.js} +5 -5
- package/dist/721.js +9 -0
- package/dist/9131.js +554 -502
- package/dist/browser-runtime/2~907.js +1211 -0
- package/dist/browser-runtime/2~907.js.map +1 -0
- package/dist/browser-runtime/389.js +22071 -0
- package/dist/browser-runtime/389.js.LICENSE.txt +329 -0
- package/dist/browser-runtime/389.js.map +1 -0
- package/dist/browser-runtime/index.d.ts +2806 -0
- package/dist/browser-runtime/index.js +1 -0
- package/dist/browser-runtime/rslib-runtime.js +50 -0
- package/dist/browser-runtime/rslib-runtime.js.map +1 -0
- package/dist/browser.d.ts +3329 -0
- package/dist/browser.js +14 -0
- package/dist/globalSetupWorker.js +3 -2
- package/dist/index.d.ts +58 -1
- package/dist/index.js +2 -1
- package/dist/rslib-runtime.js +27 -0
- package/dist/rstestSuppressWarnings.cjs +9 -0
- package/dist/worker.d.ts +57 -1
- package/dist/worker.js +415 -1
- package/package.json +28 -13
- package/dist/0~8957.js +0 -149
- package/dist/554.js +0 -417
- package/dist/5693.js +0 -91
- /package/dist/{7913.js.LICENSE.txt → 1294.js.LICENSE.txt} +0 -0
- /package/dist/{0~6151.js.LICENSE.txt → 6151.js.LICENSE.txt} +0 -0
package/dist/browser.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
4
|
+
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
5
|
+
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
|
6
|
+
var picocolors_default_0 = picocolors_default();
|
|
7
|
+
export { TEMP_RSTEST_OUTPUT_DIR, getTestEntries, globalApis } from "./1157.js";
|
|
8
|
+
export { afterAll, afterEach, assert, beforeAll, beforeEach, describe, expect, it, onTestFailed, onTestFinished, rs, rsbuild, rstest, test } from "./4484.js";
|
|
9
|
+
export { createRstestRuntime } from "./6151.js";
|
|
10
|
+
export { getSetupFiles } from "./6973.js";
|
|
11
|
+
export { isDebug, logger } from "./3278.js";
|
|
12
|
+
export { serializableConfig } from "./2672.js";
|
|
13
|
+
export { setRealTimers } from "./1294.js";
|
|
14
|
+
export { picocolors_default_0 as color };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
3
|
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
4
|
-
import
|
|
5
|
-
import "./
|
|
4
|
+
import "./487.js";
|
|
5
|
+
import "./2672.js";
|
|
6
|
+
import { formatTestError } from "./1294.js";
|
|
6
7
|
const source_map_support = __webpack_require__("../../node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js");
|
|
7
8
|
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
8
9
|
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
package/dist/index.d.ts
CHANGED
|
@@ -264,6 +264,45 @@ declare interface BranchMapping {
|
|
|
264
264
|
line: number;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
+
declare type BrowserModeConfig = {
|
|
268
|
+
/**
|
|
269
|
+
* Enable browser mode when running tests.
|
|
270
|
+
*
|
|
271
|
+
* @default false
|
|
272
|
+
*/
|
|
273
|
+
enabled?: boolean;
|
|
274
|
+
/**
|
|
275
|
+
* Browser provider to use for running tests.
|
|
276
|
+
*
|
|
277
|
+
* Currently only 'playwright' is supported.
|
|
278
|
+
*
|
|
279
|
+
* @default 'playwright'
|
|
280
|
+
*/
|
|
281
|
+
provider?: 'playwright';
|
|
282
|
+
/**
|
|
283
|
+
* Which browser to use for testing.
|
|
284
|
+
*
|
|
285
|
+
* - `chromium` - Google Chrome, Microsoft Edge
|
|
286
|
+
* - `firefox` - Mozilla Firefox
|
|
287
|
+
* - `webkit` - Safari
|
|
288
|
+
*
|
|
289
|
+
* @default 'chromium'
|
|
290
|
+
*/
|
|
291
|
+
browser?: 'chromium' | 'firefox' | 'webkit';
|
|
292
|
+
/**
|
|
293
|
+
* Run browser in headless mode.
|
|
294
|
+
*
|
|
295
|
+
* @default Inferred from CI environment. `true` in CI, `false` otherwise.
|
|
296
|
+
*/
|
|
297
|
+
headless?: boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Port for the browser mode dev server.
|
|
300
|
+
*
|
|
301
|
+
* If not specified, a random available port will be used.
|
|
302
|
+
*/
|
|
303
|
+
port?: number;
|
|
304
|
+
};
|
|
305
|
+
|
|
267
306
|
declare type BuiltInReporterNames = keyof typeof reportersMap;
|
|
268
307
|
|
|
269
308
|
declare type BuiltinReporterOptions = {
|
|
@@ -310,6 +349,7 @@ declare type CommonOptions = {
|
|
|
310
349
|
config?: string;
|
|
311
350
|
configLoader?: LoadConfigOptions['loader'];
|
|
312
351
|
globals?: boolean;
|
|
352
|
+
browser?: boolean;
|
|
313
353
|
isolate?: boolean;
|
|
314
354
|
include?: string[];
|
|
315
355
|
exclude?: string[];
|
|
@@ -2039,10 +2079,19 @@ declare interface Node_2 {
|
|
|
2039
2079
|
visit(visitor: Visitor, state: any): void;
|
|
2040
2080
|
}
|
|
2041
2081
|
|
|
2042
|
-
declare type
|
|
2082
|
+
declare type NormalizedBrowserModeConfig = {
|
|
2083
|
+
enabled: boolean;
|
|
2084
|
+
provider: 'playwright';
|
|
2085
|
+
browser: 'chromium' | 'firefox' | 'webkit';
|
|
2086
|
+
headless: boolean;
|
|
2087
|
+
port?: number;
|
|
2088
|
+
};
|
|
2089
|
+
|
|
2090
|
+
declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage' | 'setupFiles' | 'globalSetup' | 'exclude' | 'testEnvironment' | 'browser'>> & Partial<Pick<RstestConfig, OptionalKeys>> & {
|
|
2043
2091
|
pool: RstestPoolOptions;
|
|
2044
2092
|
testEnvironment: EnvironmentWithOptions;
|
|
2045
2093
|
coverage: NormalizedCoverageOptions;
|
|
2094
|
+
browser: NormalizedBrowserModeConfig;
|
|
2046
2095
|
setupFiles: string[];
|
|
2047
2096
|
globalSetup: string[];
|
|
2048
2097
|
exclude: {
|
|
@@ -2246,6 +2295,10 @@ export declare interface Reporter {
|
|
|
2246
2295
|
* Called before running the test case.
|
|
2247
2296
|
*/
|
|
2248
2297
|
onTestCaseStart?: (test: TestCaseInfo) => void;
|
|
2298
|
+
/**
|
|
2299
|
+
* Called before all tests start
|
|
2300
|
+
*/
|
|
2301
|
+
onTestRunStart?: () => MaybePromise<void>;
|
|
2249
2302
|
/**
|
|
2250
2303
|
* Called after all tests have finished running.
|
|
2251
2304
|
*/
|
|
@@ -2511,6 +2564,10 @@ export declare interface RstestConfig {
|
|
|
2511
2564
|
* Custom environment variables available on `process.env` during tests.
|
|
2512
2565
|
*/
|
|
2513
2566
|
env?: Partial<NodeJS.ProcessEnv>;
|
|
2567
|
+
/**
|
|
2568
|
+
* Browser mode configuration.
|
|
2569
|
+
*/
|
|
2570
|
+
browser?: BrowserModeConfig;
|
|
2514
2571
|
/**
|
|
2515
2572
|
* Coverage options
|
|
2516
2573
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
export { afterAll, afterEach, assert, beforeAll, beforeEach,
|
|
3
|
+
export { afterAll, afterEach, assert, beforeAll, beforeEach, describe, expect, it, onTestFailed, onTestFinished, rs, rstest, test } from "./4484.js";
|
|
4
|
+
export { createRstest, defineConfig, defineProject, initCli, loadConfig, mergeProjectConfig, mergeRstestConfig, runCLI } from "./9131.js";
|
package/dist/rslib-runtime.js
CHANGED
|
@@ -29,6 +29,33 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
29
29
|
return getter;
|
|
30
30
|
};
|
|
31
31
|
})();
|
|
32
|
+
(()=>{
|
|
33
|
+
var getProto = Object.getPrototypeOf ? (obj)=>Object.getPrototypeOf(obj) : (obj)=>obj.__proto__;
|
|
34
|
+
var leafPrototypes;
|
|
35
|
+
__webpack_require__.t = function(value, mode) {
|
|
36
|
+
if (1 & mode) value = this(value);
|
|
37
|
+
if (8 & mode) return value;
|
|
38
|
+
if ('object' == typeof value && value) {
|
|
39
|
+
if (4 & mode && value.__esModule) return value;
|
|
40
|
+
if (16 & mode && 'function' == typeof value.then) return value;
|
|
41
|
+
}
|
|
42
|
+
var ns = Object.create(null);
|
|
43
|
+
__webpack_require__.r(ns);
|
|
44
|
+
var def = {};
|
|
45
|
+
leafPrototypes = leafPrototypes || [
|
|
46
|
+
null,
|
|
47
|
+
getProto({}),
|
|
48
|
+
getProto([]),
|
|
49
|
+
getProto(getProto)
|
|
50
|
+
];
|
|
51
|
+
for(var current = 2 & mode && value; ('object' == typeof current || 'function' == typeof current) && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach((key)=>{
|
|
52
|
+
def[key] = ()=>value[key];
|
|
53
|
+
});
|
|
54
|
+
def['default'] = ()=>value;
|
|
55
|
+
__webpack_require__.d(ns, def);
|
|
56
|
+
return ns;
|
|
57
|
+
};
|
|
58
|
+
})();
|
|
32
59
|
(()=>{
|
|
33
60
|
__webpack_require__.d = (exports, definition)=>{
|
|
34
61
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
package/dist/worker.d.ts
CHANGED
|
@@ -251,6 +251,45 @@ declare interface BranchMapping {
|
|
|
251
251
|
line: number;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
declare type BrowserModeConfig = {
|
|
255
|
+
/**
|
|
256
|
+
* Enable browser mode when running tests.
|
|
257
|
+
*
|
|
258
|
+
* @default false
|
|
259
|
+
*/
|
|
260
|
+
enabled?: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Browser provider to use for running tests.
|
|
263
|
+
*
|
|
264
|
+
* Currently only 'playwright' is supported.
|
|
265
|
+
*
|
|
266
|
+
* @default 'playwright'
|
|
267
|
+
*/
|
|
268
|
+
provider?: 'playwright';
|
|
269
|
+
/**
|
|
270
|
+
* Which browser to use for testing.
|
|
271
|
+
*
|
|
272
|
+
* - `chromium` - Google Chrome, Microsoft Edge
|
|
273
|
+
* - `firefox` - Mozilla Firefox
|
|
274
|
+
* - `webkit` - Safari
|
|
275
|
+
*
|
|
276
|
+
* @default 'chromium'
|
|
277
|
+
*/
|
|
278
|
+
browser?: 'chromium' | 'firefox' | 'webkit';
|
|
279
|
+
/**
|
|
280
|
+
* Run browser in headless mode.
|
|
281
|
+
*
|
|
282
|
+
* @default Inferred from CI environment. `true` in CI, `false` otherwise.
|
|
283
|
+
*/
|
|
284
|
+
headless?: boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Port for the browser mode dev server.
|
|
287
|
+
*
|
|
288
|
+
* If not specified, a random available port will be used.
|
|
289
|
+
*/
|
|
290
|
+
port?: number;
|
|
291
|
+
};
|
|
292
|
+
|
|
254
293
|
declare type BuiltInReporterNames = keyof typeof reportersMap;
|
|
255
294
|
|
|
256
295
|
declare type BuiltinReporterOptions = {
|
|
@@ -1682,10 +1721,19 @@ declare interface Node_2 {
|
|
|
1682
1721
|
visit(visitor: Visitor, state: any): void;
|
|
1683
1722
|
}
|
|
1684
1723
|
|
|
1685
|
-
declare type
|
|
1724
|
+
declare type NormalizedBrowserModeConfig = {
|
|
1725
|
+
enabled: boolean;
|
|
1726
|
+
provider: 'playwright';
|
|
1727
|
+
browser: 'chromium' | 'firefox' | 'webkit';
|
|
1728
|
+
headless: boolean;
|
|
1729
|
+
port?: number;
|
|
1730
|
+
};
|
|
1731
|
+
|
|
1732
|
+
declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool' | 'projects' | 'coverage' | 'setupFiles' | 'globalSetup' | 'exclude' | 'testEnvironment' | 'browser'>> & Partial<Pick<RstestConfig, OptionalKeys>> & {
|
|
1686
1733
|
pool: RstestPoolOptions;
|
|
1687
1734
|
testEnvironment: EnvironmentWithOptions;
|
|
1688
1735
|
coverage: NormalizedCoverageOptions;
|
|
1736
|
+
browser: NormalizedBrowserModeConfig;
|
|
1689
1737
|
setupFiles: string[];
|
|
1690
1738
|
globalSetup: string[];
|
|
1691
1739
|
exclude: {
|
|
@@ -1872,6 +1920,10 @@ declare interface Reporter {
|
|
|
1872
1920
|
* Called before running the test case.
|
|
1873
1921
|
*/
|
|
1874
1922
|
onTestCaseStart?: (test: TestCaseInfo) => void;
|
|
1923
|
+
/**
|
|
1924
|
+
* Called before all tests start
|
|
1925
|
+
*/
|
|
1926
|
+
onTestRunStart?: () => MaybePromise<void>;
|
|
1875
1927
|
/**
|
|
1876
1928
|
* Called after all tests have finished running.
|
|
1877
1929
|
*/
|
|
@@ -2124,6 +2176,10 @@ declare interface RstestConfig {
|
|
|
2124
2176
|
* Custom environment variables available on `process.env` during tests.
|
|
2125
2177
|
*/
|
|
2126
2178
|
env?: Partial<NodeJS.ProcessEnv>;
|
|
2179
|
+
/**
|
|
2180
|
+
* Browser mode configuration.
|
|
2181
|
+
*/
|
|
2182
|
+
browser?: BrowserModeConfig;
|
|
2127
2183
|
/**
|
|
2128
2184
|
* Coverage options
|
|
2129
2185
|
*/
|
package/dist/worker.js
CHANGED
|
@@ -1,3 +1,417 @@
|
|
|
1
1
|
import 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
|
|
3
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
4
|
+
import { basename, isAbsolute, undoSerializableConfig, dirname, resolve as pathe_M_eThtNZ_resolve, join } from "./2672.js";
|
|
5
|
+
import "./487.js";
|
|
6
|
+
import { node_v8, createBirpc } from "./3216.js";
|
|
7
|
+
import { createCoverageProvider } from "./5734.js";
|
|
8
|
+
import { formatTestError, setRealTimers, getRealTimers } from "./1294.js";
|
|
9
|
+
import { globalApis } from "./1157.js";
|
|
10
|
+
const processSend = process.send.bind(process);
|
|
11
|
+
const processOn = process.on.bind(process);
|
|
12
|
+
const processOff = process.off.bind(process);
|
|
13
|
+
function createForksRpcOptions({ nodeV8 = node_v8, dispose = [] }) {
|
|
14
|
+
return {
|
|
15
|
+
serialize: nodeV8.serialize,
|
|
16
|
+
deserialize: (v)=>nodeV8.deserialize(Buffer.from(v)),
|
|
17
|
+
post (v) {
|
|
18
|
+
processSend(v);
|
|
19
|
+
},
|
|
20
|
+
on (fn) {
|
|
21
|
+
const handler = (message, ...extras)=>{
|
|
22
|
+
if (message?.__tinypool_worker_message__) return;
|
|
23
|
+
return fn(message, ...extras);
|
|
24
|
+
};
|
|
25
|
+
processOn('message', handler);
|
|
26
|
+
dispose.push(()=>processOff('message', handler));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createRuntimeRpc(options, { originalConsole }) {
|
|
31
|
+
const rpc = createBirpc({}, {
|
|
32
|
+
...options,
|
|
33
|
+
onTimeoutError: (functionName, error)=>{
|
|
34
|
+
switch(functionName){
|
|
35
|
+
case 'onTestCaseStart':
|
|
36
|
+
{
|
|
37
|
+
const caseTest = error[0];
|
|
38
|
+
console.error(`[Rstest] timeout on calling "onTestCaseStart" rpc method (Case: "${caseTest.name}")`);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
case 'onTestCaseResult':
|
|
42
|
+
{
|
|
43
|
+
const caseResult = error[0];
|
|
44
|
+
console.error(`[Rstest] timeout on calling "onTestCaseResult" rpc method (Case: "${caseResult.name}", Result: "${caseResult.status}")`);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
case 'onConsoleLog':
|
|
48
|
+
originalConsole.error(`[Rstest] timeout on calling "onConsoleLog" rpc method (Original log: ${error[0].content})`);
|
|
49
|
+
return true;
|
|
50
|
+
default:
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
rpc
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const external_node_fs_ = __webpack_require__("fs");
|
|
60
|
+
class NodeSnapshotEnvironment {
|
|
61
|
+
constructor(options = {}){
|
|
62
|
+
this.options = options;
|
|
63
|
+
}
|
|
64
|
+
getVersion() {
|
|
65
|
+
return "1";
|
|
66
|
+
}
|
|
67
|
+
getHeader() {
|
|
68
|
+
return `// Snapshot v${this.getVersion()}`;
|
|
69
|
+
}
|
|
70
|
+
async resolveRawPath(testPath, rawPath) {
|
|
71
|
+
return isAbsolute(rawPath) ? rawPath : pathe_M_eThtNZ_resolve(dirname(testPath), rawPath);
|
|
72
|
+
}
|
|
73
|
+
async resolvePath(filepath) {
|
|
74
|
+
return join(join(dirname(filepath), this.options.snapshotsDirName ?? "__snapshots__"), `${basename(filepath)}.snap`);
|
|
75
|
+
}
|
|
76
|
+
async prepareDirectory(dirPath) {
|
|
77
|
+
await external_node_fs_.promises.mkdir(dirPath, {
|
|
78
|
+
recursive: true
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async saveSnapshotFile(filepath, snapshot) {
|
|
82
|
+
await external_node_fs_.promises.mkdir(dirname(filepath), {
|
|
83
|
+
recursive: true
|
|
84
|
+
});
|
|
85
|
+
await external_node_fs_.promises.writeFile(filepath, snapshot, "utf-8");
|
|
86
|
+
}
|
|
87
|
+
async readSnapshotFile(filepath) {
|
|
88
|
+
if (!(0, external_node_fs_.existsSync)(filepath)) return null;
|
|
89
|
+
return external_node_fs_.promises.readFile(filepath, "utf-8");
|
|
90
|
+
}
|
|
91
|
+
async removeSnapshotFile(filepath) {
|
|
92
|
+
if ((0, external_node_fs_.existsSync)(filepath)) await external_node_fs_.promises.unlink(filepath);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
class RstestSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
96
|
+
resolveSnapshotPath;
|
|
97
|
+
constructor(options){
|
|
98
|
+
super();
|
|
99
|
+
this.resolveSnapshotPath = options.resolveSnapshotPath;
|
|
100
|
+
}
|
|
101
|
+
getHeader() {
|
|
102
|
+
return `// Rstest Snapshot v${this.getVersion()}`;
|
|
103
|
+
}
|
|
104
|
+
resolvePath(filepath) {
|
|
105
|
+
return this.resolveSnapshotPath(filepath);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const source_map_support = __webpack_require__("../../node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js");
|
|
109
|
+
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
110
|
+
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
|
111
|
+
let sourceMaps = {};
|
|
112
|
+
(0, source_map_support.install)({
|
|
113
|
+
environment: 'node',
|
|
114
|
+
handleUncaughtExceptions: false,
|
|
115
|
+
retrieveSourceMap: (source)=>{
|
|
116
|
+
if (sourceMaps[source]) return {
|
|
117
|
+
url: source,
|
|
118
|
+
map: JSON.parse(sourceMaps[source])
|
|
119
|
+
};
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const registerGlobalApi = (api)=>globalApis.reduce((apis, key)=>{
|
|
124
|
+
globalThis[key] = api[key];
|
|
125
|
+
return apis;
|
|
126
|
+
}, {});
|
|
127
|
+
const globalCleanups = [];
|
|
128
|
+
let isTeardown = false;
|
|
129
|
+
const setupEnv = (env)=>{
|
|
130
|
+
if (env) Object.assign(process.env, env);
|
|
131
|
+
};
|
|
132
|
+
const preparePool = async ({ entryInfo: { distPath, testPath }, updateSnapshot, context })=>{
|
|
133
|
+
globalCleanups.forEach((fn)=>{
|
|
134
|
+
fn();
|
|
135
|
+
});
|
|
136
|
+
globalCleanups.length = 0;
|
|
137
|
+
setRealTimers();
|
|
138
|
+
context.runtimeConfig = undoSerializableConfig(context.runtimeConfig);
|
|
139
|
+
process.env.RSTEST_WORKER_ID = String(process.__tinypool_state__.workerId || context.taskId);
|
|
140
|
+
const cleanupFns = [];
|
|
141
|
+
const originalConsole = global.console;
|
|
142
|
+
const disposeFns = [];
|
|
143
|
+
const { rpc } = createRuntimeRpc(createForksRpcOptions({
|
|
144
|
+
dispose: disposeFns
|
|
145
|
+
}), {
|
|
146
|
+
originalConsole
|
|
147
|
+
});
|
|
148
|
+
globalCleanups.push(()=>{
|
|
149
|
+
disposeFns.forEach((fn)=>{
|
|
150
|
+
fn();
|
|
151
|
+
});
|
|
152
|
+
rpc.$close();
|
|
153
|
+
});
|
|
154
|
+
const { runtimeConfig: { globals, printConsoleTrace, disableConsoleIntercept, testEnvironment, snapshotFormat, env } } = context;
|
|
155
|
+
setupEnv(env);
|
|
156
|
+
if (!disableConsoleIntercept) {
|
|
157
|
+
const { createCustomConsole } = await import("./0~130.js").then((mod)=>({
|
|
158
|
+
createCustomConsole: mod.createCustomConsole
|
|
159
|
+
}));
|
|
160
|
+
global.console = createCustomConsole({
|
|
161
|
+
rpc,
|
|
162
|
+
testPath,
|
|
163
|
+
printConsoleTrace
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const interopDefault = true;
|
|
167
|
+
const workerState = {
|
|
168
|
+
...context,
|
|
169
|
+
snapshotOptions: {
|
|
170
|
+
updateSnapshot,
|
|
171
|
+
snapshotEnvironment: new RstestSnapshotEnvironment({
|
|
172
|
+
resolveSnapshotPath: (filepath)=>rpc.resolveSnapshotPath(filepath)
|
|
173
|
+
}),
|
|
174
|
+
snapshotFormat
|
|
175
|
+
},
|
|
176
|
+
distPath,
|
|
177
|
+
testPath,
|
|
178
|
+
environment: 'node'
|
|
179
|
+
};
|
|
180
|
+
const { createRstestRuntime } = await import("./6151.js").then((mod)=>({
|
|
181
|
+
createRstestRuntime: mod.createRstestRuntime
|
|
182
|
+
}));
|
|
183
|
+
const unhandledErrors = [];
|
|
184
|
+
const handleError = (e, type)=>{
|
|
185
|
+
const error = 'string' == typeof e ? new Error(e) : e;
|
|
186
|
+
error.name = type;
|
|
187
|
+
if (isTeardown) {
|
|
188
|
+
error.stack = `${picocolors_default().yellow('Caught error after test environment was torn down:')}\n\n${error.stack}`;
|
|
189
|
+
console.error(error);
|
|
190
|
+
} else {
|
|
191
|
+
console.error(error);
|
|
192
|
+
unhandledErrors.push(error);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const uncaughtException = (e)=>handleError(e, 'uncaughtException');
|
|
196
|
+
const unhandledRejection = (e)=>handleError(e, 'unhandledRejection');
|
|
197
|
+
process.on('uncaughtException', uncaughtException);
|
|
198
|
+
process.on('unhandledRejection', unhandledRejection);
|
|
199
|
+
globalCleanups.push(()=>{
|
|
200
|
+
process.off('uncaughtException', uncaughtException);
|
|
201
|
+
process.off('unhandledRejection', unhandledRejection);
|
|
202
|
+
});
|
|
203
|
+
const { api, runner } = await createRstestRuntime(workerState);
|
|
204
|
+
switch(testEnvironment.name){
|
|
205
|
+
case 'node':
|
|
206
|
+
break;
|
|
207
|
+
case 'jsdom':
|
|
208
|
+
{
|
|
209
|
+
const { environment } = await import("./0~62.js").then((mod)=>({
|
|
210
|
+
environment: mod.environment
|
|
211
|
+
}));
|
|
212
|
+
const { teardown } = await environment.setup(global, testEnvironment.options || {});
|
|
213
|
+
cleanupFns.push(()=>teardown(global));
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case 'happy-dom':
|
|
217
|
+
{
|
|
218
|
+
const { environment } = await import("./0~4809.js").then((mod)=>({
|
|
219
|
+
environment: mod.environment
|
|
220
|
+
}));
|
|
221
|
+
const { teardown } = await environment.setup(global, testEnvironment.options || {});
|
|
222
|
+
cleanupFns.push(async ()=>teardown(global));
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
default:
|
|
226
|
+
throw new Error(`Unknown test environment: ${testEnvironment.name}`);
|
|
227
|
+
}
|
|
228
|
+
if (globals) registerGlobalApi(api);
|
|
229
|
+
const rstestContext = {
|
|
230
|
+
global,
|
|
231
|
+
console: global.console,
|
|
232
|
+
Error
|
|
233
|
+
};
|
|
234
|
+
rstestContext.global['@rstest/core'] = api;
|
|
235
|
+
return {
|
|
236
|
+
interopDefault,
|
|
237
|
+
rstestContext,
|
|
238
|
+
runner,
|
|
239
|
+
rpc,
|
|
240
|
+
api,
|
|
241
|
+
unhandledErrors,
|
|
242
|
+
cleanup: async ()=>{
|
|
243
|
+
await Promise.all(cleanupFns.map((fn)=>fn()));
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
const loadFiles = async ({ setupEntries, assetFiles, rstestContext, distPath, testPath, interopDefault, isolate, outputModule })=>{
|
|
248
|
+
const { loadModule, updateLatestAssetFiles } = outputModule ? await import("./0~6923.js").then((mod)=>({
|
|
249
|
+
EsmMode: mod.loadEsModule_EsmMode,
|
|
250
|
+
asModule: mod.asModule,
|
|
251
|
+
loadModule: mod.loadModule,
|
|
252
|
+
updateLatestAssetFiles: mod.updateLatestAssetFiles
|
|
253
|
+
})) : await import("./0~5835.js").then((mod)=>({
|
|
254
|
+
cacheableLoadModule: mod.cacheableLoadModule,
|
|
255
|
+
loadModule: mod.loadModule,
|
|
256
|
+
updateLatestAssetFiles: mod.updateLatestAssetFiles
|
|
257
|
+
}));
|
|
258
|
+
if (!isolate) {
|
|
259
|
+
updateLatestAssetFiles(assetFiles);
|
|
260
|
+
await loadModule({
|
|
261
|
+
codeContent: `if (global && typeof global.__rstest_clean_core_cache__ === 'function') {
|
|
262
|
+
global.__rstest_clean_core_cache__();
|
|
263
|
+
}`,
|
|
264
|
+
distPath: '',
|
|
265
|
+
testPath,
|
|
266
|
+
rstestContext,
|
|
267
|
+
assetFiles,
|
|
268
|
+
interopDefault
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
for (const { distPath, testPath } of setupEntries){
|
|
272
|
+
const setupCodeContent = assetFiles[distPath];
|
|
273
|
+
await loadModule({
|
|
274
|
+
codeContent: setupCodeContent,
|
|
275
|
+
distPath,
|
|
276
|
+
testPath,
|
|
277
|
+
rstestContext,
|
|
278
|
+
assetFiles,
|
|
279
|
+
interopDefault
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
await loadModule({
|
|
283
|
+
codeContent: assetFiles[distPath],
|
|
284
|
+
distPath,
|
|
285
|
+
testPath,
|
|
286
|
+
rstestContext,
|
|
287
|
+
assetFiles,
|
|
288
|
+
interopDefault
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
const runInPool = async (options)=>{
|
|
292
|
+
isTeardown = false;
|
|
293
|
+
const { entryInfo: { distPath, testPath }, setupEntries, assets, type, context: { project, runtimeConfig: { isolate, bail } } } = options;
|
|
294
|
+
const cleanups = [];
|
|
295
|
+
const exit = process.exit.bind(process);
|
|
296
|
+
process.exit = (code = process.exitCode || 0)=>{
|
|
297
|
+
throw new Error(`process.exit unexpectedly called with "${code}"`);
|
|
298
|
+
};
|
|
299
|
+
const kill = process.kill.bind(process);
|
|
300
|
+
process.kill = (pid, signal)=>{
|
|
301
|
+
if (-1 === pid || Math.abs(pid) === process.pid) throw new Error(`process.kill unexpectedly called with "${pid}" and "${signal}"`);
|
|
302
|
+
return kill(pid, signal);
|
|
303
|
+
};
|
|
304
|
+
cleanups.push(()=>{
|
|
305
|
+
process.kill = kill;
|
|
306
|
+
process.exit = exit;
|
|
307
|
+
});
|
|
308
|
+
const teardown = async ()=>{
|
|
309
|
+
await new Promise((resolve)=>getRealTimers().setTimeout(resolve));
|
|
310
|
+
await Promise.all(cleanups.map((fn)=>fn()));
|
|
311
|
+
isTeardown = true;
|
|
312
|
+
};
|
|
313
|
+
if ('collect' === type) try {
|
|
314
|
+
const { rstestContext, runner, rpc, cleanup, unhandledErrors, interopDefault } = await preparePool(options);
|
|
315
|
+
const { assetFiles, sourceMaps: sourceMapsFromAssets } = assets || await rpc.getAssetsByEntry();
|
|
316
|
+
sourceMaps = sourceMapsFromAssets;
|
|
317
|
+
cleanups.push(cleanup);
|
|
318
|
+
await loadFiles({
|
|
319
|
+
rstestContext,
|
|
320
|
+
distPath,
|
|
321
|
+
testPath,
|
|
322
|
+
assetFiles,
|
|
323
|
+
setupEntries,
|
|
324
|
+
interopDefault,
|
|
325
|
+
isolate,
|
|
326
|
+
outputModule: options.context.outputModule
|
|
327
|
+
});
|
|
328
|
+
const tests = await runner.collectTests();
|
|
329
|
+
return {
|
|
330
|
+
project,
|
|
331
|
+
testPath,
|
|
332
|
+
tests,
|
|
333
|
+
errors: formatTestError(unhandledErrors)
|
|
334
|
+
};
|
|
335
|
+
} catch (err) {
|
|
336
|
+
return {
|
|
337
|
+
project,
|
|
338
|
+
testPath,
|
|
339
|
+
tests: [],
|
|
340
|
+
errors: formatTestError(err)
|
|
341
|
+
};
|
|
342
|
+
} finally{
|
|
343
|
+
await teardown();
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
const { rstestContext, runner, rpc, api, cleanup, unhandledErrors, interopDefault } = await preparePool(options);
|
|
347
|
+
if (bail && await rpc.getCountOfFailedTests() >= bail) return {
|
|
348
|
+
testId: '0',
|
|
349
|
+
project,
|
|
350
|
+
testPath,
|
|
351
|
+
status: 'skip',
|
|
352
|
+
name: '',
|
|
353
|
+
results: []
|
|
354
|
+
};
|
|
355
|
+
const coverageProvider = await createCoverageProvider(options.context.runtimeConfig.coverage || {}, options.context.rootPath);
|
|
356
|
+
if (coverageProvider) coverageProvider.init();
|
|
357
|
+
const { assetFiles, sourceMaps: sourceMapsFromAssets } = assets || await rpc.getAssetsByEntry();
|
|
358
|
+
sourceMaps = sourceMapsFromAssets;
|
|
359
|
+
cleanups.push(cleanup);
|
|
360
|
+
rpc.onTestFileStart?.({
|
|
361
|
+
testPath,
|
|
362
|
+
tests: []
|
|
363
|
+
});
|
|
364
|
+
await loadFiles({
|
|
365
|
+
rstestContext,
|
|
366
|
+
distPath,
|
|
367
|
+
testPath,
|
|
368
|
+
assetFiles,
|
|
369
|
+
setupEntries,
|
|
370
|
+
interopDefault,
|
|
371
|
+
isolate,
|
|
372
|
+
outputModule: options.context.outputModule
|
|
373
|
+
});
|
|
374
|
+
const results = await runner.runTests(testPath, {
|
|
375
|
+
onTestFileReady: async (test)=>{
|
|
376
|
+
await rpc.onTestFileReady(test);
|
|
377
|
+
},
|
|
378
|
+
onTestSuiteStart: async (test)=>{
|
|
379
|
+
await rpc.onTestSuiteStart(test);
|
|
380
|
+
},
|
|
381
|
+
onTestSuiteResult: async (result)=>{
|
|
382
|
+
await rpc.onTestSuiteResult(result);
|
|
383
|
+
},
|
|
384
|
+
onTestCaseStart: async (test)=>{
|
|
385
|
+
await rpc.onTestCaseStart(test);
|
|
386
|
+
},
|
|
387
|
+
onTestCaseResult: async (result)=>{
|
|
388
|
+
await rpc.onTestCaseResult(result);
|
|
389
|
+
},
|
|
390
|
+
getCountOfFailedTests: async ()=>rpc.getCountOfFailedTests()
|
|
391
|
+
}, api);
|
|
392
|
+
if (unhandledErrors.length > 0) {
|
|
393
|
+
results.status = 'fail';
|
|
394
|
+
results.errors = (results.errors || []).concat(...formatTestError(unhandledErrors));
|
|
395
|
+
}
|
|
396
|
+
if (coverageProvider) {
|
|
397
|
+
const coverageMap = coverageProvider.collect();
|
|
398
|
+
if (coverageMap) results.coverage = coverageMap.toJSON();
|
|
399
|
+
coverageProvider.cleanup();
|
|
400
|
+
}
|
|
401
|
+
return results;
|
|
402
|
+
} catch (err) {
|
|
403
|
+
return {
|
|
404
|
+
testId: '0',
|
|
405
|
+
project,
|
|
406
|
+
testPath,
|
|
407
|
+
status: 'fail',
|
|
408
|
+
name: '',
|
|
409
|
+
results: [],
|
|
410
|
+
errors: formatTestError(err)
|
|
411
|
+
};
|
|
412
|
+
} finally{
|
|
413
|
+
await teardown();
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
const worker = runInPool;
|
|
417
|
+
export default worker;
|