@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rstest/core",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.9",
|
|
4
4
|
"description": "The Rsbuild-based test tool.",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rstest/issues"
|
|
@@ -28,6 +28,14 @@
|
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
29
|
"default": "./dist/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./browser": {
|
|
32
|
+
"types": "./dist/browser.d.ts",
|
|
33
|
+
"default": "./dist/browser.js"
|
|
34
|
+
},
|
|
35
|
+
"./browser-runtime": {
|
|
36
|
+
"types": "./dist/browser-runtime/index.d.ts",
|
|
37
|
+
"default": "./dist/browser-runtime/index.js"
|
|
38
|
+
},
|
|
31
39
|
"./package.json": {
|
|
32
40
|
"default": "./package.json"
|
|
33
41
|
},
|
|
@@ -46,46 +54,53 @@
|
|
|
46
54
|
"importMeta.d.ts"
|
|
47
55
|
],
|
|
48
56
|
"dependencies": {
|
|
49
|
-
"@types/chai": "^5.2.3",
|
|
50
57
|
"@rsbuild/core": "1.7.1",
|
|
58
|
+
"@types/chai": "^5.2.3",
|
|
51
59
|
"tinypool": "^1.1.1"
|
|
52
60
|
},
|
|
53
61
|
"devDependencies": {
|
|
54
|
-
"chai": "^5.3.3",
|
|
55
|
-
"pathe": "^2.0.3",
|
|
56
|
-
"birpc": "2.9.0",
|
|
57
|
-
"@vitest/expect": "^3.2.4",
|
|
58
|
-
"@vitest/snapshot": "^3.2.4",
|
|
59
62
|
"@babel/code-frame": "^7.27.1",
|
|
60
63
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
61
64
|
"@microsoft/api-extractor": "^7.55.2",
|
|
65
|
+
"@rsbuild/plugin-node-polyfill": "^1.3.0",
|
|
62
66
|
"@rslib/core": "^0.19.0",
|
|
63
67
|
"@sinonjs/fake-timers": "^15.1.0",
|
|
64
68
|
"@types/babel__code-frame": "^7.0.6",
|
|
65
|
-
"@types/istanbul-reports": "^3.0.4",
|
|
66
69
|
"@types/istanbul-lib-coverage": "^2.0.6",
|
|
67
70
|
"@types/istanbul-lib-report": "^3.0.3",
|
|
71
|
+
"@types/istanbul-reports": "^3.0.4",
|
|
68
72
|
"@types/jsdom": "^21.1.7",
|
|
73
|
+
"@types/picomatch": "^4.0.2",
|
|
69
74
|
"@types/sinonjs__fake-timers": "^8.1.5",
|
|
75
|
+
"@clack/prompts": "^0.10.1",
|
|
76
|
+
"@vercel/detect-agent": "^1.0.0",
|
|
70
77
|
"@types/source-map-support": "^0.5.10",
|
|
71
|
-
"@
|
|
78
|
+
"@vitest/expect": "^3.2.4",
|
|
79
|
+
"@vitest/snapshot": "^3.2.4",
|
|
80
|
+
"birpc": "2.9.0",
|
|
72
81
|
"cac": "^6.7.14",
|
|
82
|
+
"chai": "^5.3.3",
|
|
73
83
|
"chokidar": "^4.0.3",
|
|
74
84
|
"happy-dom": "^20.0.11",
|
|
75
85
|
"jest-diff": "^30.2.0",
|
|
76
86
|
"jsdom": "^26.1.0",
|
|
77
|
-
"
|
|
87
|
+
"memfs": "^4.51.1",
|
|
88
|
+
"package-manager-detector": "^1.6.0",
|
|
89
|
+
"pathe": "^2.0.3",
|
|
78
90
|
"picocolors": "^1.1.1",
|
|
91
|
+
"picomatch": "^4.0.3",
|
|
79
92
|
"pretty-format": "^30.2.0",
|
|
80
93
|
"rslog": "^1.3.2",
|
|
81
94
|
"source-map-support": "^0.5.21",
|
|
82
|
-
"std-env": "^3.10.0",
|
|
83
95
|
"stacktrace-parser": "0.1.11",
|
|
96
|
+
"std-env": "^3.10.0",
|
|
84
97
|
"strip-ansi": "^7.1.2",
|
|
85
98
|
"tinyglobby": "^0.2.15",
|
|
86
99
|
"tinyspy": "^4.0.4",
|
|
87
|
-
"
|
|
88
|
-
"
|
|
100
|
+
"url-extras": "^0.1.0",
|
|
101
|
+
"webpack-license-plugin": "^4.5.1",
|
|
102
|
+
"@rstest/tsconfig": "0.0.1",
|
|
103
|
+
"@rstest/browser-ui": "0.7.9"
|
|
89
104
|
},
|
|
90
105
|
"peerDependencies": {
|
|
91
106
|
"happy-dom": "*",
|
package/dist/0~8957.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import 'module';
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import { M, T } from "./0~6151.js";
|
|
4
|
-
const isMockFunction = (fn)=>'function' == typeof fn && '_isMockFunction' in fn && fn._isMockFunction;
|
|
5
|
-
const initSpy = ()=>{
|
|
6
|
-
let callOrder = 0;
|
|
7
|
-
const mocks = new Set();
|
|
8
|
-
const wrapSpy = (obj, methodName, mockFn)=>{
|
|
9
|
-
const spyImpl = M(obj, methodName, mockFn);
|
|
10
|
-
const spyFn = spyImpl;
|
|
11
|
-
let mockImplementationOnce = [];
|
|
12
|
-
let implementation = mockFn;
|
|
13
|
-
let mockName = mockFn?.name;
|
|
14
|
-
const initMockState = ()=>({
|
|
15
|
-
instances: [],
|
|
16
|
-
contexts: [],
|
|
17
|
-
invocationCallOrder: []
|
|
18
|
-
});
|
|
19
|
-
let mockState = initMockState();
|
|
20
|
-
const spyState = T(spyImpl);
|
|
21
|
-
spyFn.getMockName = ()=>mockName || methodName;
|
|
22
|
-
spyFn.mockName = (name)=>{
|
|
23
|
-
mockName = name;
|
|
24
|
-
return spyFn;
|
|
25
|
-
};
|
|
26
|
-
spyFn.getMockImplementation = ()=>mockImplementationOnce.length ? mockImplementationOnce[mockImplementationOnce.length - 1] : implementation;
|
|
27
|
-
function withImplementation(fn, cb) {
|
|
28
|
-
const originalImplementation = implementation;
|
|
29
|
-
const originalMockImplementationOnce = mockImplementationOnce;
|
|
30
|
-
implementation = fn;
|
|
31
|
-
mockImplementationOnce = [];
|
|
32
|
-
spyState.willCall(willCall);
|
|
33
|
-
const reset = ()=>{
|
|
34
|
-
implementation = originalImplementation;
|
|
35
|
-
mockImplementationOnce = originalMockImplementationOnce;
|
|
36
|
-
};
|
|
37
|
-
const result = cb();
|
|
38
|
-
if (result instanceof Promise) return result.then(()=>{
|
|
39
|
-
reset();
|
|
40
|
-
});
|
|
41
|
-
reset();
|
|
42
|
-
}
|
|
43
|
-
spyFn.withImplementation = withImplementation;
|
|
44
|
-
spyFn.mockImplementation = (fn)=>{
|
|
45
|
-
implementation = fn;
|
|
46
|
-
return spyFn;
|
|
47
|
-
};
|
|
48
|
-
spyFn.mockImplementationOnce = (fn)=>{
|
|
49
|
-
mockImplementationOnce.push(fn);
|
|
50
|
-
return spyFn;
|
|
51
|
-
};
|
|
52
|
-
spyFn.mockReturnValue = (value)=>spyFn.mockImplementation(()=>value);
|
|
53
|
-
spyFn.mockReturnValueOnce = (value)=>spyFn.mockImplementationOnce(()=>value);
|
|
54
|
-
spyFn.mockResolvedValue = (value)=>spyFn.mockImplementation(()=>Promise.resolve(value));
|
|
55
|
-
spyFn.mockResolvedValueOnce = (value)=>spyFn.mockImplementationOnce(()=>Promise.resolve(value));
|
|
56
|
-
spyFn.mockRejectedValue = (value)=>spyFn.mockImplementation(()=>Promise.reject(value));
|
|
57
|
-
spyFn.mockRejectedValueOnce = (value)=>spyFn.mockImplementationOnce(()=>Promise.reject(value));
|
|
58
|
-
spyFn.mockReturnThis = ()=>spyFn.mockImplementation(function() {
|
|
59
|
-
return this;
|
|
60
|
-
});
|
|
61
|
-
function willCall(...args) {
|
|
62
|
-
let impl = implementation || spyState.getOriginal();
|
|
63
|
-
mockState.instances.push(this);
|
|
64
|
-
mockState.contexts.push(this);
|
|
65
|
-
mockState.invocationCallOrder.push(++callOrder);
|
|
66
|
-
if (mockImplementationOnce.length) impl = mockImplementationOnce.shift();
|
|
67
|
-
return impl?.apply(this, args);
|
|
68
|
-
}
|
|
69
|
-
spyState.willCall(willCall);
|
|
70
|
-
Object.defineProperty(spyFn, 'mock', {
|
|
71
|
-
get: ()=>({
|
|
72
|
-
get calls () {
|
|
73
|
-
return spyState.calls;
|
|
74
|
-
},
|
|
75
|
-
get lastCall () {
|
|
76
|
-
return spyState.calls[spyState.callCount - 1];
|
|
77
|
-
},
|
|
78
|
-
get instances () {
|
|
79
|
-
return mockState.instances;
|
|
80
|
-
},
|
|
81
|
-
get contexts () {
|
|
82
|
-
return mockState.contexts;
|
|
83
|
-
},
|
|
84
|
-
get invocationCallOrder () {
|
|
85
|
-
return mockState.invocationCallOrder;
|
|
86
|
-
},
|
|
87
|
-
get results () {
|
|
88
|
-
return spyState.results.map(([resultType, value])=>{
|
|
89
|
-
const type = 'error' === resultType ? 'throw' : 'return';
|
|
90
|
-
return {
|
|
91
|
-
type: type,
|
|
92
|
-
value
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
get settledResults () {
|
|
97
|
-
return spyState.resolves.map(([resultType, value])=>{
|
|
98
|
-
const type = 'error' === resultType ? 'rejected' : 'fulfilled';
|
|
99
|
-
return {
|
|
100
|
-
type,
|
|
101
|
-
value
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
});
|
|
107
|
-
spyFn.mockClear = ()=>{
|
|
108
|
-
mockState = initMockState();
|
|
109
|
-
spyState.reset();
|
|
110
|
-
return spyFn;
|
|
111
|
-
};
|
|
112
|
-
spyFn.mockReset = ()=>{
|
|
113
|
-
spyFn.mockClear();
|
|
114
|
-
implementation = mockFn;
|
|
115
|
-
mockImplementationOnce = [];
|
|
116
|
-
return spyFn;
|
|
117
|
-
};
|
|
118
|
-
spyFn.mockRestore = ()=>{
|
|
119
|
-
spyFn.mockReset();
|
|
120
|
-
spyState.restore();
|
|
121
|
-
mockName = mockFn?.name;
|
|
122
|
-
};
|
|
123
|
-
mocks.add(spyFn);
|
|
124
|
-
return spyFn;
|
|
125
|
-
};
|
|
126
|
-
const fn = (mockFn)=>{
|
|
127
|
-
const defaultName = 'rstest.fn()';
|
|
128
|
-
return wrapSpy({
|
|
129
|
-
[defaultName]: mockFn
|
|
130
|
-
}, defaultName, mockFn);
|
|
131
|
-
};
|
|
132
|
-
const spyOn = (obj, methodName, accessType)=>{
|
|
133
|
-
const accessTypeMap = {
|
|
134
|
-
get: 'getter',
|
|
135
|
-
set: 'setter'
|
|
136
|
-
};
|
|
137
|
-
const method = accessType ? {
|
|
138
|
-
[accessTypeMap[accessType]]: methodName
|
|
139
|
-
} : methodName;
|
|
140
|
-
return wrapSpy(obj, method);
|
|
141
|
-
};
|
|
142
|
-
return {
|
|
143
|
-
isMockFunction: isMockFunction,
|
|
144
|
-
spyOn,
|
|
145
|
-
fn,
|
|
146
|
-
mocks
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
export { initSpy };
|
package/dist/554.js
DELETED
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
import __rslib_shim_module__ from 'module';
|
|
2
|
-
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
|
-
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
4
|
-
import "./5693.js";
|
|
5
|
-
import { formatTestError, setRealTimers, getRealTimers } from "./7913.js";
|
|
6
|
-
import { node_v8, createBirpc } from "./3216.js";
|
|
7
|
-
import { basename, isAbsolute, dirname, resolve as pathe_M_eThtNZ_resolve, join } from "./3278.js";
|
|
8
|
-
import { createCoverageProvider } from "./5734.js";
|
|
9
|
-
import { undoSerializableConfig, globalApis } from "./1157.js";
|
|
10
|
-
__webpack_require__.add({
|
|
11
|
-
timers (module) {
|
|
12
|
-
module.exports = require("timers");
|
|
13
|
-
},
|
|
14
|
-
"timers/promises" (module) {
|
|
15
|
-
module.exports = require("timers/promises");
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
const processSend = process.send.bind(process);
|
|
19
|
-
const processOn = process.on.bind(process);
|
|
20
|
-
const processOff = process.off.bind(process);
|
|
21
|
-
const dispose = [];
|
|
22
|
-
function createForksRpcOptions(nodeV8 = node_v8) {
|
|
23
|
-
return {
|
|
24
|
-
serialize: nodeV8.serialize,
|
|
25
|
-
deserialize: (v)=>nodeV8.deserialize(Buffer.from(v)),
|
|
26
|
-
post (v) {
|
|
27
|
-
processSend(v);
|
|
28
|
-
},
|
|
29
|
-
on (fn) {
|
|
30
|
-
const handler = (message, ...extras)=>{
|
|
31
|
-
if (message?.__tinypool_worker_message__) return;
|
|
32
|
-
return fn(message, ...extras);
|
|
33
|
-
};
|
|
34
|
-
processOn('message', handler);
|
|
35
|
-
dispose.push(()=>processOff('message', handler));
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function createRuntimeRpc(options, { originalConsole }) {
|
|
40
|
-
const rpc = createBirpc({}, {
|
|
41
|
-
...options,
|
|
42
|
-
onTimeoutError: (functionName, error)=>{
|
|
43
|
-
switch(functionName){
|
|
44
|
-
case 'onTestCaseStart':
|
|
45
|
-
{
|
|
46
|
-
const caseTest = error[0];
|
|
47
|
-
console.error(`[Rstest] timeout on calling "onTestCaseStart" rpc method (Case: "${caseTest.name}")`);
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
case 'onTestCaseResult':
|
|
51
|
-
{
|
|
52
|
-
const caseResult = error[0];
|
|
53
|
-
console.error(`[Rstest] timeout on calling "onTestCaseResult" rpc method (Case: "${caseResult.name}", Result: "${caseResult.status}")`);
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
case 'onConsoleLog':
|
|
57
|
-
originalConsole.error(`[Rstest] timeout on calling "onConsoleLog" rpc method (Original log: ${error[0].content})`);
|
|
58
|
-
return true;
|
|
59
|
-
default:
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
rpc
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const external_node_fs_ = __webpack_require__("node:fs");
|
|
69
|
-
class NodeSnapshotEnvironment {
|
|
70
|
-
constructor(options = {}){
|
|
71
|
-
this.options = options;
|
|
72
|
-
}
|
|
73
|
-
getVersion() {
|
|
74
|
-
return "1";
|
|
75
|
-
}
|
|
76
|
-
getHeader() {
|
|
77
|
-
return `// Snapshot v${this.getVersion()}`;
|
|
78
|
-
}
|
|
79
|
-
async resolveRawPath(testPath, rawPath) {
|
|
80
|
-
return isAbsolute(rawPath) ? rawPath : pathe_M_eThtNZ_resolve(dirname(testPath), rawPath);
|
|
81
|
-
}
|
|
82
|
-
async resolvePath(filepath) {
|
|
83
|
-
return join(join(dirname(filepath), this.options.snapshotsDirName ?? "__snapshots__"), `${basename(filepath)}.snap`);
|
|
84
|
-
}
|
|
85
|
-
async prepareDirectory(dirPath) {
|
|
86
|
-
await external_node_fs_.promises.mkdir(dirPath, {
|
|
87
|
-
recursive: true
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
async saveSnapshotFile(filepath, snapshot) {
|
|
91
|
-
await external_node_fs_.promises.mkdir(dirname(filepath), {
|
|
92
|
-
recursive: true
|
|
93
|
-
});
|
|
94
|
-
await external_node_fs_.promises.writeFile(filepath, snapshot, "utf-8");
|
|
95
|
-
}
|
|
96
|
-
async readSnapshotFile(filepath) {
|
|
97
|
-
if (!(0, external_node_fs_.existsSync)(filepath)) return null;
|
|
98
|
-
return external_node_fs_.promises.readFile(filepath, "utf-8");
|
|
99
|
-
}
|
|
100
|
-
async removeSnapshotFile(filepath) {
|
|
101
|
-
if ((0, external_node_fs_.existsSync)(filepath)) await external_node_fs_.promises.unlink(filepath);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
class RstestSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
105
|
-
resolveSnapshotPath;
|
|
106
|
-
constructor(options){
|
|
107
|
-
super();
|
|
108
|
-
this.resolveSnapshotPath = options.resolveSnapshotPath;
|
|
109
|
-
}
|
|
110
|
-
getHeader() {
|
|
111
|
-
return `// Rstest Snapshot v${this.getVersion()}`;
|
|
112
|
-
}
|
|
113
|
-
resolvePath(filepath) {
|
|
114
|
-
return this.resolveSnapshotPath(filepath);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const source_map_support = __webpack_require__("../../node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js");
|
|
118
|
-
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
119
|
-
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
|
120
|
-
let sourceMaps = {};
|
|
121
|
-
(0, source_map_support.install)({
|
|
122
|
-
environment: 'node',
|
|
123
|
-
handleUncaughtExceptions: false,
|
|
124
|
-
retrieveSourceMap: (source)=>{
|
|
125
|
-
if (sourceMaps[source]) return {
|
|
126
|
-
url: source,
|
|
127
|
-
map: JSON.parse(sourceMaps[source])
|
|
128
|
-
};
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
const registerGlobalApi = (api)=>globalApis.reduce((apis, key)=>{
|
|
133
|
-
globalThis[key] = api[key];
|
|
134
|
-
return apis;
|
|
135
|
-
}, {});
|
|
136
|
-
const listeners = [];
|
|
137
|
-
let isTeardown = false;
|
|
138
|
-
const setupEnv = (env)=>{
|
|
139
|
-
if (env) Object.assign(process.env, env);
|
|
140
|
-
};
|
|
141
|
-
const preparePool = async ({ entryInfo: { distPath, testPath }, updateSnapshot, context })=>{
|
|
142
|
-
setRealTimers();
|
|
143
|
-
context.runtimeConfig = undoSerializableConfig(context.runtimeConfig);
|
|
144
|
-
process.env.RSTEST_WORKER_ID = String(process.__tinypool_state__.workerId || context.taskId);
|
|
145
|
-
const cleanupFns = [];
|
|
146
|
-
const originalConsole = global.console;
|
|
147
|
-
const { rpc } = createRuntimeRpc(createForksRpcOptions(), {
|
|
148
|
-
originalConsole
|
|
149
|
-
});
|
|
150
|
-
const { runtimeConfig: { globals, printConsoleTrace, disableConsoleIntercept, testEnvironment, snapshotFormat, env } } = context;
|
|
151
|
-
setupEnv(env);
|
|
152
|
-
if (!disableConsoleIntercept) {
|
|
153
|
-
const { createCustomConsole } = await import("./0~130.js").then((mod)=>({
|
|
154
|
-
createCustomConsole: mod.createCustomConsole
|
|
155
|
-
}));
|
|
156
|
-
global.console = createCustomConsole({
|
|
157
|
-
rpc,
|
|
158
|
-
testPath,
|
|
159
|
-
printConsoleTrace
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
const interopDefault = true;
|
|
163
|
-
const workerState = {
|
|
164
|
-
...context,
|
|
165
|
-
snapshotOptions: {
|
|
166
|
-
updateSnapshot,
|
|
167
|
-
snapshotEnvironment: new RstestSnapshotEnvironment({
|
|
168
|
-
resolveSnapshotPath: (filepath)=>rpc.resolveSnapshotPath(filepath)
|
|
169
|
-
}),
|
|
170
|
-
snapshotFormat
|
|
171
|
-
},
|
|
172
|
-
distPath,
|
|
173
|
-
testPath,
|
|
174
|
-
environment: 'node'
|
|
175
|
-
};
|
|
176
|
-
const { createRstestRuntime } = await import("./0~6151.js").then((mod)=>({
|
|
177
|
-
createRstestRuntime: mod.createRstestRuntime
|
|
178
|
-
}));
|
|
179
|
-
listeners.forEach((fn)=>{
|
|
180
|
-
fn();
|
|
181
|
-
});
|
|
182
|
-
listeners.length = 0;
|
|
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
|
-
listeners.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;
|