@rspack/test-tools 2.0.8 → 2.1.0-beta.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/dist/case/cache.js +3 -2
- package/dist/case/common.js +2 -2
- package/dist/case/config.d.ts +2 -2
- package/dist/case/config.js +26 -6
- package/dist/case/hot.d.ts +2 -2
- package/dist/case/hot.js +19 -5
- package/dist/case/runner.js +4 -4
- package/dist/case/runtime-mode.d.ts +2 -0
- package/dist/case/runtime-mode.js +58 -0
- package/dist/compiler.js +2 -1
- package/dist/helper/expect/to-match-file-snapshot.js +58 -11
- package/dist/helper/hot-update/plugin.js +1 -1
- package/dist/runner/node/index.d.ts +2 -0
- package/dist/runner/node/index.js +6 -0
- package/dist/test/context.d.ts +2 -0
- package/dist/test/context.js +8 -0
- package/dist/type.d.ts +3 -0
- package/package.json +6 -6
package/dist/case/cache.js
CHANGED
|
@@ -111,9 +111,10 @@ const creators = new Map();
|
|
|
111
111
|
function matchStatsSnapshot(env, source, updateIndex, stats) {
|
|
112
112
|
const content = (0, placeholder_js_namespaceObject.normalizePlaceholder)(stats.toString({
|
|
113
113
|
all: false,
|
|
114
|
-
logging:
|
|
114
|
+
logging: false,
|
|
115
|
+
loggingDebug: /^rspack\.persistentCache$/,
|
|
115
116
|
colors: false
|
|
116
|
-
})).trim();
|
|
117
|
+
}).replace(/[0-9]+(\.[0-9]+)? ms/g, 'xx ms')).trim();
|
|
117
118
|
if (!content.includes('rspack.persistentCache')) return;
|
|
118
119
|
env.expect(content).toMatchFileSnapshotSync(external_node_path_default().resolve(source, '__snapshots__', `stats-${updateIndex}.txt`));
|
|
119
120
|
}
|
package/dist/case/common.js
CHANGED
|
@@ -222,10 +222,10 @@ function findMultiCompilerBundle(context, name, multiFindBundle) {
|
|
|
222
222
|
}
|
|
223
223
|
function configMultiCompiler(context, name, configFiles, defaultOptions, overrideOptions) {
|
|
224
224
|
const multiCompilerOptions = [];
|
|
225
|
-
const caseOptions = Array.isArray(configFiles) ? (0, index_js_namespaceObject.readConfigFile)(configFiles.map((i)=>context.
|
|
225
|
+
const caseOptions = Array.isArray(configFiles) ? (0, index_js_namespaceObject.readConfigFile)(configFiles.map((i)=>context.getCompileSource(i)), context, {}, (configs)=>configs.flatMap((c)=>{
|
|
226
226
|
if ('function' == typeof c) {
|
|
227
227
|
const options = {
|
|
228
|
-
testPath: context.
|
|
228
|
+
testPath: context.getCompileDist(),
|
|
229
229
|
env: void 0
|
|
230
230
|
};
|
|
231
231
|
return c(options.env, options);
|
package/dist/case/config.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { RspackOptions } from '@rspack/core';
|
|
2
2
|
import type { ITestContext, ITestProcessor, TTestConfig } from '../type';
|
|
3
3
|
export type TConfigCaseConfig = Omit<TTestConfig, 'validate'>;
|
|
4
|
-
export declare function createConfigProcessor(name: string): ITestProcessor;
|
|
5
|
-
export declare function createConfigCase(name: string, src: string, dist: string): void;
|
|
4
|
+
export declare function createConfigProcessor(name: string, rspackOptions?: RspackOptions): ITestProcessor;
|
|
5
|
+
export declare function createConfigCase(name: string, src: string, dist: string, rspackOptions?: RspackOptions): void;
|
|
6
6
|
export declare function defaultOptions(index: number, context: ITestContext): RspackOptions;
|
|
7
7
|
export declare function enableEsmLibraryPlugin(options: RspackOptions): boolean;
|
|
8
8
|
export declare function overrideOptions(index: number, context: ITestContext, options: RspackOptions): void;
|
package/dist/case/config.js
CHANGED
|
@@ -51,15 +51,21 @@ var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_
|
|
|
51
51
|
const parseResource_js_namespaceObject = require("../helper/legacy/parseResource.js");
|
|
52
52
|
const creator_js_namespaceObject = require("../test/creator.js");
|
|
53
53
|
const external_common_js_namespaceObject = require("./common.js");
|
|
54
|
+
const external_runtime_mode_js_namespaceObject = require("./runtime-mode.js");
|
|
54
55
|
const external_runner_js_namespaceObject = require("./runner.js");
|
|
55
|
-
function createConfigProcessor(name) {
|
|
56
|
+
function createConfigProcessor(name, rspackOptions) {
|
|
56
57
|
return {
|
|
57
58
|
config: (context)=>{
|
|
59
|
+
if (context.getTestConfig().isolateSource) external_fs_extra_default().copySync(context.getSource(), context.getCompileSource());
|
|
58
60
|
(0, external_common_js_namespaceObject.configMultiCompiler)(context, name, [
|
|
59
61
|
'rspack.config.cjs',
|
|
60
62
|
'rspack.config.js',
|
|
61
63
|
'webpack.config.js'
|
|
62
|
-
], defaultOptions,
|
|
64
|
+
], defaultOptions, (index, context, options)=>{
|
|
65
|
+
overrideOptions(index, context, options);
|
|
66
|
+
mergeRspackOptions(options, rspackOptions);
|
|
67
|
+
(0, external_runtime_mode_js_namespaceObject.applyRuntimeModeTestDefines)(options);
|
|
68
|
+
});
|
|
63
69
|
},
|
|
64
70
|
compiler: async (context)=>{
|
|
65
71
|
await (0, external_common_js_namespaceObject.compiler)(context, name);
|
|
@@ -98,18 +104,23 @@ const creator = new creator_js_namespaceObject.BasicCaseCreator({
|
|
|
98
104
|
},
|
|
99
105
|
concurrent: true
|
|
100
106
|
});
|
|
101
|
-
function createConfigCase(name, src, dist) {
|
|
102
|
-
creator.create(name, src, dist
|
|
107
|
+
function createConfigCase(name, src, dist, rspackOptions) {
|
|
108
|
+
creator.create(name, src, dist, void 0, {
|
|
109
|
+
rspackOptions,
|
|
110
|
+
steps: ({ name, rspackOptions })=>[
|
|
111
|
+
createConfigProcessor(name, rspackOptions)
|
|
112
|
+
]
|
|
113
|
+
});
|
|
103
114
|
}
|
|
104
115
|
function defaultOptions(index, context) {
|
|
105
116
|
return {
|
|
106
|
-
context: context.
|
|
117
|
+
context: context.getCompileSource(),
|
|
107
118
|
mode: 'production',
|
|
108
119
|
target: 'async-node',
|
|
109
120
|
devtool: false,
|
|
110
121
|
cache: false,
|
|
111
122
|
output: {
|
|
112
|
-
path: context.
|
|
123
|
+
path: context.getCompileDist(),
|
|
113
124
|
bundlerInfo: {
|
|
114
125
|
force: false
|
|
115
126
|
}
|
|
@@ -142,6 +153,15 @@ function overrideOptions(index, context, options) {
|
|
|
142
153
|
level: 'error'
|
|
143
154
|
};
|
|
144
155
|
}
|
|
156
|
+
function mergeRspackOptions(options, override) {
|
|
157
|
+
if (!override) return;
|
|
158
|
+
const { experiments, ...rest } = override;
|
|
159
|
+
Object.assign(options, rest);
|
|
160
|
+
if (experiments) options.experiments = {
|
|
161
|
+
...options.experiments,
|
|
162
|
+
...experiments
|
|
163
|
+
};
|
|
164
|
+
}
|
|
145
165
|
function findBundle(index, context, options) {
|
|
146
166
|
const testConfig = context.getTestConfig();
|
|
147
167
|
if ('function' == typeof testConfig.findBundle) return testConfig.findBundle(index, options);
|
package/dist/case/hot.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { type RspackOptions } from '@rspack/core';
|
|
|
2
2
|
import { HotUpdatePlugin } from '../helper/hot-update/plugin';
|
|
3
3
|
import type { ITestContext, ITestEnv, ITestProcessor, ITestRunner } from '../type';
|
|
4
4
|
type TTarget = RspackOptions['target'];
|
|
5
|
-
export declare function createHotProcessor(name: string, src: string, temp: string, target: TTarget, incremental?: boolean): THotProcessor;
|
|
6
|
-
export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: RspackOptions['target']): void;
|
|
5
|
+
export declare function createHotProcessor(name: string, src: string, temp: string, target: TTarget, incremental?: boolean, rspackOptions?: RspackOptions): THotProcessor;
|
|
6
|
+
export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: RspackOptions['target'], rspackOptions?: RspackOptions): void;
|
|
7
7
|
type THotProcessor = ITestProcessor & {
|
|
8
8
|
updatePlugin: HotUpdatePlugin;
|
|
9
9
|
};
|
package/dist/case/hot.js
CHANGED
|
@@ -52,9 +52,10 @@ const external_plugin_index_js_namespaceObject = require("../plugin/index.js");
|
|
|
52
52
|
const external_runner_index_js_namespaceObject = require("../runner/index.js");
|
|
53
53
|
const creator_js_namespaceObject = require("../test/creator.js");
|
|
54
54
|
const external_common_js_namespaceObject = require("./common.js");
|
|
55
|
+
const external_runtime_mode_js_namespaceObject = require("./runtime-mode.js");
|
|
55
56
|
const external_runner_js_namespaceObject = require("./runner.js");
|
|
56
57
|
const creators = new Map();
|
|
57
|
-
function createHotProcessor(name, src, temp, target, incremental = false) {
|
|
58
|
+
function createHotProcessor(name, src, temp, target, incremental = false, rspackOptions) {
|
|
58
59
|
const updatePlugin = new plugin_js_namespaceObject.HotUpdatePlugin(src, temp);
|
|
59
60
|
const processor = {
|
|
60
61
|
before: async (context)=>{
|
|
@@ -70,6 +71,8 @@ function createHotProcessor(name, src, temp, target, incremental = false) {
|
|
|
70
71
|
], options);
|
|
71
72
|
overrideOptions(context, options, target, updatePlugin);
|
|
72
73
|
if (incremental) options.incremental ??= 'advance-silent';
|
|
74
|
+
mergeRspackOptions(options, rspackOptions);
|
|
75
|
+
(0, external_runtime_mode_js_namespaceObject.applyRuntimeModeTestDefines)(options);
|
|
73
76
|
compiler.setOptions(options);
|
|
74
77
|
},
|
|
75
78
|
compiler: async (context)=>{
|
|
@@ -102,8 +105,8 @@ function getCreator(target) {
|
|
|
102
105
|
clean: true,
|
|
103
106
|
describe: true,
|
|
104
107
|
target,
|
|
105
|
-
steps: ({ name, target, src, dist, temp })=>[
|
|
106
|
-
createHotProcessor(name, src, temp || external_node_path_default().resolve(dist, 'temp'), target)
|
|
108
|
+
steps: ({ name, target, src, dist, temp, rspackOptions })=>[
|
|
109
|
+
createHotProcessor(name, src, temp || external_node_path_default().resolve(dist, 'temp'), target, false, rspackOptions)
|
|
107
110
|
],
|
|
108
111
|
runner: {
|
|
109
112
|
key: (context, name, file)=>name,
|
|
@@ -113,9 +116,20 @@ function getCreator(target) {
|
|
|
113
116
|
}));
|
|
114
117
|
return creators.get(target);
|
|
115
118
|
}
|
|
116
|
-
function createHotCase(name, src, dist, temp, target) {
|
|
119
|
+
function createHotCase(name, src, dist, temp, target, rspackOptions) {
|
|
117
120
|
const creator = getCreator(target);
|
|
118
|
-
creator.create(name, src, dist, temp
|
|
121
|
+
creator.create(name, src, dist, temp, {
|
|
122
|
+
rspackOptions
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function mergeRspackOptions(options, override) {
|
|
126
|
+
if (!override) return;
|
|
127
|
+
const { experiments, ...rest } = override;
|
|
128
|
+
Object.assign(options, rest);
|
|
129
|
+
if (experiments) options.experiments = {
|
|
130
|
+
...options.experiments,
|
|
131
|
+
...experiments
|
|
132
|
+
};
|
|
119
133
|
}
|
|
120
134
|
function defaultOptions(context, target) {
|
|
121
135
|
const options = {
|
package/dist/case/runner.js
CHANGED
|
@@ -71,8 +71,8 @@ function createRunner(context, name, file, env) {
|
|
|
71
71
|
stats: cachedStats(context, name),
|
|
72
72
|
name,
|
|
73
73
|
testConfig: context.getTestConfig(),
|
|
74
|
-
source: context.
|
|
75
|
-
dist: context.
|
|
74
|
+
source: context.getCompileSource(),
|
|
75
|
+
dist: context.getCompileDist(),
|
|
76
76
|
compilerOptions
|
|
77
77
|
};
|
|
78
78
|
const isWeb = isWebTarget(compilerOptions);
|
|
@@ -129,8 +129,8 @@ function createMultiCompilerRunner(context, name, file, env) {
|
|
|
129
129
|
},
|
|
130
130
|
name,
|
|
131
131
|
testConfig: context.getTestConfig(),
|
|
132
|
-
source: context.
|
|
133
|
-
dist: context.
|
|
132
|
+
source: context.getCompileSource(),
|
|
133
|
+
dist: context.getCompileDist(),
|
|
134
134
|
compilerOptions,
|
|
135
135
|
logs,
|
|
136
136
|
errors
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.r = (exports1)=>{
|
|
29
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
+
value: 'Module'
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __webpack_exports__ = {};
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
applyRuntimeModeTestDefines: ()=>applyRuntimeModeTestDefines
|
|
41
|
+
});
|
|
42
|
+
const core_namespaceObject = require("@rspack/core");
|
|
43
|
+
var core_default = /*#__PURE__*/ __webpack_require__.n(core_namespaceObject);
|
|
44
|
+
const runtimeModeDefine = {
|
|
45
|
+
'globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK': JSON.stringify(true)
|
|
46
|
+
};
|
|
47
|
+
function applyRuntimeModeTestDefines(options) {
|
|
48
|
+
if (options.experiments?.runtimeMode !== 'rspack') return;
|
|
49
|
+
options.plugins ??= [];
|
|
50
|
+
options.plugins.push(new (core_default()).DefinePlugin(runtimeModeDefine));
|
|
51
|
+
}
|
|
52
|
+
exports.applyRuntimeModeTestDefines = __webpack_exports__.applyRuntimeModeTestDefines;
|
|
53
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
54
|
+
"applyRuntimeModeTestDefines"
|
|
55
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
56
|
+
Object.defineProperty(exports, '__esModule', {
|
|
57
|
+
value: true
|
|
58
|
+
});
|
package/dist/compiler.js
CHANGED
|
@@ -187,7 +187,8 @@ var __webpack_exports__ = {};
|
|
|
187
187
|
const watchOptions = {
|
|
188
188
|
poll: 300,
|
|
189
189
|
ignored: [],
|
|
190
|
-
aggregateTimeout: timeout
|
|
190
|
+
aggregateTimeout: timeout,
|
|
191
|
+
...this.compilerInstance.options.watchOptions
|
|
191
192
|
};
|
|
192
193
|
if (__DEBUG__) context.setValue(debug_js_namespaceObject.DEBUG_SCOPES.BuildMethod, {
|
|
193
194
|
method: 'watch',
|
|
@@ -51,6 +51,37 @@ const external_jest_diff_namespaceObject = require("jest-diff");
|
|
|
51
51
|
const external_serializers_js_namespaceObject = require("../serializers.js");
|
|
52
52
|
const external_snapshot_serializers_js_namespaceObject = require("./snapshot-serializers.js");
|
|
53
53
|
const isEqual = (a, b)=>Buffer.isBuffer(a) ? a.equals(b) : a === b;
|
|
54
|
+
function readSnapshot(filename, content) {
|
|
55
|
+
const output = external_node_fs_default().readFileSync(filename, Buffer.isBuffer(content) ? null : 'utf8');
|
|
56
|
+
return Buffer.isBuffer(output) ? output : output.replace(/\r\n/g, '\n');
|
|
57
|
+
}
|
|
58
|
+
function toPosixPath(filename) {
|
|
59
|
+
return filename.split(external_node_path_default().sep).join('/');
|
|
60
|
+
}
|
|
61
|
+
function getRuntimeModeSnapshotFilename(filename) {
|
|
62
|
+
if (!globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) return;
|
|
63
|
+
const normalized = toPosixPath(filename);
|
|
64
|
+
if (normalized.includes('/runtimeModeSnapshot/')) return;
|
|
65
|
+
for (const marker of [
|
|
66
|
+
'/__snapshot__/',
|
|
67
|
+
'/__snapshots__/'
|
|
68
|
+
]){
|
|
69
|
+
const markerIndex = normalized.indexOf(marker);
|
|
70
|
+
if (markerIndex >= 0) return external_node_path_default().normalize(`${normalized.slice(0, markerIndex + marker.length)}runtimeModeSnapshot/${normalized.slice(markerIndex + marker.length)}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function cleanupRuntimeModeSnapshot(filename) {
|
|
74
|
+
external_node_fs_default().unlinkSync(filename);
|
|
75
|
+
let current = external_node_path_default().dirname(filename);
|
|
76
|
+
while('runtimeModeSnapshot' !== external_node_path_default().basename(current)){
|
|
77
|
+
try {
|
|
78
|
+
external_node_fs_default().rmdirSync(current);
|
|
79
|
+
} catch {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
current = external_node_path_default().dirname(current);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
54
85
|
function toMatchFileSnapshotSync(rawContent, filepath, options = {}) {
|
|
55
86
|
const content = Buffer.isBuffer(rawContent) ? rawContent : (0, external_snapshot_serializers_js_namespaceObject.serializeSnapshot)(rawContent, 2, {
|
|
56
87
|
plugins: [
|
|
@@ -62,15 +93,17 @@ function toMatchFileSnapshotSync(rawContent, filepath, options = {}) {
|
|
|
62
93
|
const filename = void 0 === filepath ? external_node_path_default().join(external_node_path_default().dirname(this.testPath), '__file_snapshots__', `${external_filenamify_default()(this.currentTestName, {
|
|
63
94
|
replacement: '-'
|
|
64
95
|
}).replace(/\s/g, '-')}-${this.assertionCalls}`) : filepath;
|
|
65
|
-
|
|
96
|
+
const runtimeModeSnapshotFilename = getRuntimeModeSnapshotFilename(filename);
|
|
97
|
+
const matchedFilename = runtimeModeSnapshotFilename && external_node_fs_default().existsSync(runtimeModeSnapshotFilename) ? runtimeModeSnapshotFilename : filename;
|
|
98
|
+
if ('none' === snapshotState._updateSnapshot && !external_node_fs_default().existsSync(matchedFilename)) {
|
|
66
99
|
snapshotState.unmatched++;
|
|
67
100
|
return {
|
|
68
101
|
pass: isNot,
|
|
69
|
-
message: ()=>`New output file ${external_chalk_default().blue(external_node_path_default().basename(
|
|
102
|
+
message: ()=>`New output file ${external_chalk_default().blue(external_node_path_default().basename(matchedFilename))} was ${external_chalk_default().bold.red('not written')}.\n\nThe update flag must be explicitly passed to write a new snapshot.\n\nThis is likely because this test is run in a ${external_chalk_default().blue('continuous integration (CI) environment')} in which snapshots are not written by default.\n\n`
|
|
70
103
|
};
|
|
71
104
|
}
|
|
72
|
-
if (external_node_fs_default().existsSync(
|
|
73
|
-
const output =
|
|
105
|
+
if (external_node_fs_default().existsSync(matchedFilename)) {
|
|
106
|
+
const output = readSnapshot(matchedFilename, content);
|
|
74
107
|
if (isNot) {
|
|
75
108
|
if (!isEqual(content, output)) return {
|
|
76
109
|
pass: false,
|
|
@@ -79,7 +112,7 @@ function toMatchFileSnapshotSync(rawContent, filepath, options = {}) {
|
|
|
79
112
|
snapshotState.unmatched++;
|
|
80
113
|
return {
|
|
81
114
|
pass: true,
|
|
82
|
-
message: ()=>`Expected received content ${external_chalk_default().red('to not match')} the file ${external_chalk_default().blue(external_node_path_default().basename(
|
|
115
|
+
message: ()=>`Expected received content ${external_chalk_default().red('to not match')} the file ${external_chalk_default().blue(external_node_path_default().basename(matchedFilename))}.`
|
|
83
116
|
};
|
|
84
117
|
}
|
|
85
118
|
if (isEqual(content, output)) return {
|
|
@@ -87,10 +120,19 @@ function toMatchFileSnapshotSync(rawContent, filepath, options = {}) {
|
|
|
87
120
|
message: ()=>''
|
|
88
121
|
};
|
|
89
122
|
if ('all' === snapshotState._updateSnapshot) {
|
|
90
|
-
external_node_fs_default().
|
|
123
|
+
if (runtimeModeSnapshotFilename && matchedFilename === runtimeModeSnapshotFilename && external_node_fs_default().existsSync(filename) && isEqual(content, readSnapshot(filename, content))) {
|
|
124
|
+
cleanupRuntimeModeSnapshot(runtimeModeSnapshotFilename);
|
|
125
|
+
snapshotState.updated++;
|
|
126
|
+
return {
|
|
127
|
+
pass: true,
|
|
128
|
+
message: ()=>''
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const updatedFilename = runtimeModeSnapshotFilename && external_node_fs_default().existsSync(filename) ? runtimeModeSnapshotFilename : matchedFilename;
|
|
132
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(updatedFilename), {
|
|
91
133
|
recursive: true
|
|
92
134
|
});
|
|
93
|
-
external_node_fs_default().writeFileSync(
|
|
135
|
+
external_node_fs_default().writeFileSync(updatedFilename, content);
|
|
94
136
|
snapshotState.updated++;
|
|
95
137
|
return {
|
|
96
138
|
pass: true,
|
|
@@ -105,14 +147,19 @@ function toMatchFileSnapshotSync(rawContent, filepath, options = {}) {
|
|
|
105
147
|
}, options.diff || {}))}`;
|
|
106
148
|
return {
|
|
107
149
|
pass: false,
|
|
108
|
-
message: ()=>`Received content ${external_chalk_default().red("doesn't match")} the file ${external_chalk_default().blue(external_node_path_default().basename(
|
|
150
|
+
message: ()=>`Received content ${external_chalk_default().red("doesn't match")} the file ${external_chalk_default().blue(external_node_path_default().basename(matchedFilename))}.${difference}`
|
|
109
151
|
};
|
|
110
152
|
}
|
|
111
153
|
if (!isNot && ('new' === snapshotState._updateSnapshot || 'all' === snapshotState._updateSnapshot)) {
|
|
112
|
-
external_node_fs_default().
|
|
154
|
+
if (runtimeModeSnapshotFilename && external_node_fs_default().existsSync(filename) && isEqual(content, readSnapshot(filename, content))) return {
|
|
155
|
+
pass: true,
|
|
156
|
+
message: ()=>''
|
|
157
|
+
};
|
|
158
|
+
const newFilename = runtimeModeSnapshotFilename || filename;
|
|
159
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(newFilename), {
|
|
113
160
|
recursive: true
|
|
114
161
|
});
|
|
115
|
-
external_node_fs_default().writeFileSync(
|
|
162
|
+
external_node_fs_default().writeFileSync(newFilename, content);
|
|
116
163
|
snapshotState.added++;
|
|
117
164
|
return {
|
|
118
165
|
pass: true,
|
|
@@ -122,7 +169,7 @@ function toMatchFileSnapshotSync(rawContent, filepath, options = {}) {
|
|
|
122
169
|
snapshotState.unmatched++;
|
|
123
170
|
return {
|
|
124
171
|
pass: true,
|
|
125
|
-
message: ()=>`The output file ${external_chalk_default().blue(external_node_path_default().basename(
|
|
172
|
+
message: ()=>`The output file ${external_chalk_default().blue(external_node_path_default().basename(matchedFilename))} ${external_chalk_default().bold.red("doesn't exist")}.`
|
|
126
173
|
};
|
|
127
174
|
}
|
|
128
175
|
exports.toMatchFileSnapshotSync = __webpack_exports__.toMatchFileSnapshotSync;
|
|
@@ -151,7 +151,7 @@ class HotUpdatePlugin {
|
|
|
151
151
|
set.add(compiler.rspack.RuntimeGlobals.moduleCache);
|
|
152
152
|
});
|
|
153
153
|
compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module, _set)=>{
|
|
154
|
-
if ('DefinePropertyGettersRuntimeModule' === module.constructor.name) module.source.source = Buffer.from(`
|
|
154
|
+
if ('DefinePropertyGettersRuntimeModule' === module.constructor.name && compiler.options.experiments?.runtimeMode !== 'rspack') module.source.source = Buffer.from(`
|
|
155
155
|
${RuntimeGlobals.definePropertyGetters} = function (exports, getters, values) {
|
|
156
156
|
var define = function (defs, kind) {
|
|
157
157
|
for(var key in defs) {
|
|
@@ -22,9 +22,11 @@ export declare class NodeRunner implements ITestRunner {
|
|
|
22
22
|
protected globalContext: IGlobalContext | null;
|
|
23
23
|
protected baseModuleScope: IModuleScope | null;
|
|
24
24
|
protected requirers: Map<string, TRunnerRequirer>;
|
|
25
|
+
protected runQueue: Promise<void> | undefined;
|
|
25
26
|
constructor(_options: INodeRunnerOptions);
|
|
26
27
|
protected log(message: string): void;
|
|
27
28
|
run(file: string): Promise<unknown>;
|
|
29
|
+
protected runFile(file: string): Promise<unknown>;
|
|
28
30
|
getRequire(): TRunnerRequirer;
|
|
29
31
|
getGlobal(name: string): unknown;
|
|
30
32
|
protected createGlobalContext(): IGlobalContext;
|
|
@@ -91,6 +91,7 @@ var __webpack_exports__ = {};
|
|
|
91
91
|
globalContext = null;
|
|
92
92
|
baseModuleScope = null;
|
|
93
93
|
requirers = new Map();
|
|
94
|
+
runQueue;
|
|
94
95
|
constructor(_options){
|
|
95
96
|
this._options = _options;
|
|
96
97
|
}
|
|
@@ -98,6 +99,11 @@ var __webpack_exports__ = {};
|
|
|
98
99
|
this._options.logs?.push(`[NodeRunner] ${message}`);
|
|
99
100
|
}
|
|
100
101
|
run(file) {
|
|
102
|
+
const run = this.runQueue ? this.runQueue.then(()=>this.runFile(file)) : this.runFile(file);
|
|
103
|
+
this.runQueue = run.then(()=>void 0, ()=>void 0);
|
|
104
|
+
return run;
|
|
105
|
+
}
|
|
106
|
+
runFile(file) {
|
|
101
107
|
if (!this.globalContext) this.globalContext = this.createGlobalContext();
|
|
102
108
|
this.baseModuleScope = this.createBaseModuleScope();
|
|
103
109
|
if ('function' == typeof this._options.testConfig.moduleScope) this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats, this._options.compilerOptions);
|
package/dist/test/context.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare class TestContext implements ITestContext {
|
|
|
9
9
|
constructor(config: TTestContextOptions);
|
|
10
10
|
getSource(sub?: string): string;
|
|
11
11
|
getDist(sub?: string): string;
|
|
12
|
+
getCompileSource(sub?: string): string;
|
|
13
|
+
getCompileDist(sub?: string): string;
|
|
12
14
|
getTemp(sub?: string): string | null;
|
|
13
15
|
getCompiler(): ITestCompilerManager;
|
|
14
16
|
getRunner(file: string, env: ITestEnv): ITestRunner;
|
package/dist/test/context.js
CHANGED
|
@@ -60,6 +60,14 @@ class TestContext {
|
|
|
60
60
|
if (sub) return external_node_path_default().resolve(this.config.dist, sub);
|
|
61
61
|
return this.config.dist;
|
|
62
62
|
}
|
|
63
|
+
getCompileSource(sub) {
|
|
64
|
+
if (this.config.testConfig?.isolateSource) return this.getDist(sub ? external_node_path_default().join('src', sub) : 'src');
|
|
65
|
+
return this.getSource(sub);
|
|
66
|
+
}
|
|
67
|
+
getCompileDist(sub) {
|
|
68
|
+
if (this.config.testConfig?.isolateSource) return this.getDist(sub ? external_node_path_default().join('dist', sub) : 'dist');
|
|
69
|
+
return this.getDist(sub);
|
|
70
|
+
}
|
|
63
71
|
getTemp(sub) {
|
|
64
72
|
if (!this.config.temp) return null;
|
|
65
73
|
if (sub) return external_node_path_default().resolve(this.config.temp, sub);
|
package/dist/type.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { Compiler, MultiStats, RspackOptions, Stats, StatsCompilation } fro
|
|
|
3
3
|
export interface ITestContext {
|
|
4
4
|
getSource(sub?: string): string;
|
|
5
5
|
getDist(sub?: string): string;
|
|
6
|
+
getCompileSource(sub?: string): string;
|
|
7
|
+
getCompileDist(sub?: string): string;
|
|
6
8
|
getTemp(sub?: string): string | null;
|
|
7
9
|
getCompiler(): ITestCompilerManager;
|
|
8
10
|
closeCompiler(): Promise<void>;
|
|
@@ -122,6 +124,7 @@ export type TTestConfig = {
|
|
|
122
124
|
location?: string;
|
|
123
125
|
validate?: (stats: Stats | MultiStats, stderr?: string) => void;
|
|
124
126
|
noTests?: boolean;
|
|
127
|
+
isolateSource?: boolean;
|
|
125
128
|
writeStatsOuptut?: boolean;
|
|
126
129
|
writeStatsJson?: boolean;
|
|
127
130
|
beforeExecute?: (options: RspackOptions) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-beta.0",
|
|
4
4
|
"description": "Test tools for rspack",
|
|
5
5
|
"homepage": "https://rspack.rs",
|
|
6
6
|
"bugs": "https://github.com/web-infra-dev/rspack/issues",
|
|
@@ -45,24 +45,24 @@
|
|
|
45
45
|
"javascript-stringify": "^2.1.0",
|
|
46
46
|
"jest-diff": "^30.4.1",
|
|
47
47
|
"jsdom": "^26.1.0",
|
|
48
|
-
"memfs": "4.57.
|
|
48
|
+
"memfs": "4.57.7",
|
|
49
49
|
"path-serializer": "0.6.0",
|
|
50
50
|
"pretty-format": "30.4.1",
|
|
51
51
|
"rimraf": "^5.0.10",
|
|
52
|
-
"rspack-merge": "0.1
|
|
52
|
+
"rspack-merge": "1.0.1",
|
|
53
53
|
"source-map": "^0.7.6",
|
|
54
|
-
"terser-webpack-plugin": "^5.
|
|
54
|
+
"terser-webpack-plugin": "^5.6.1",
|
|
55
55
|
"wast-loader": "^1.14.1",
|
|
56
56
|
"webpack-sources": "3.3.4"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@rslib/core": "^0.22.
|
|
59
|
+
"@rslib/core": "^0.22.1",
|
|
60
60
|
"@types/babel__generator": "7.27.0",
|
|
61
61
|
"@types/babel__traverse": "7.28.0",
|
|
62
62
|
"@types/fs-extra": "11.0.4",
|
|
63
63
|
"@types/jsdom": "^21.1.7",
|
|
64
64
|
"typescript": "^6.0.3",
|
|
65
|
-
"@rspack/core": "2.0.
|
|
65
|
+
"@rspack/core": "2.1.0-beta.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@rspack/core": ">=1.0.0"
|