@rspack/test-tools 1.7.0-beta.0 → 1.7.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/builtin.d.ts +2 -2
- package/dist/case/builtin.js +58 -58
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +34 -34
- package/dist/case/common.d.ts +2 -2
- package/dist/case/common.js +45 -45
- package/dist/case/compiler.d.ts +3 -3
- package/dist/case/compiler.js +21 -21
- package/dist/case/config.d.ts +3 -3
- package/dist/case/config.js +19 -19
- package/dist/case/defaults.d.ts +2 -2
- package/dist/case/defaults.js +10 -10
- package/dist/case/diagnostic.js +29 -29
- package/dist/case/error.d.ts +2 -2
- package/dist/case/error.js +21 -21
- package/dist/case/esm-output.js +30 -26
- package/dist/case/example.js +7 -7
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +16 -16
- package/dist/case/hook.d.ts +3 -3
- package/dist/case/hook.js +42 -42
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +46 -46
- package/dist/case/hot.d.ts +5 -5
- package/dist/case/hot.js +43 -43
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +9 -9
- package/dist/case/index.d.ts +31 -31
- package/dist/case/multi-compiler.d.ts +3 -3
- package/dist/case/multi-compiler.js +15 -15
- package/dist/case/native-watcher.js +6 -6
- package/dist/case/normal.js +46 -46
- package/dist/case/runner.d.ts +2 -2
- package/dist/case/runner.js +22 -15
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +4 -4
- package/dist/case/stats-api.d.ts +2 -2
- package/dist/case/stats-api.js +7 -7
- package/dist/case/stats-output.d.ts +2 -2
- package/dist/case/stats-output.js +45 -45
- package/dist/case/treeshaking.js +6 -6
- package/dist/case/watch.d.ts +1 -1
- package/dist/case/watch.js +59 -59
- package/dist/compiler.d.ts +3 -3
- package/dist/compiler.js +31 -31
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +15 -15
- package/dist/helper/disable-iconv-lite-warning.js +3 -3
- package/dist/helper/expect/diff.js +8 -8
- package/dist/helper/expect/error.js +9 -9
- package/dist/helper/expect/placeholder.js +9 -9
- package/dist/helper/expect/rspack.js +5 -5
- package/dist/helper/expect/to-be-typeof.js +2 -2
- package/dist/helper/expect/to-end-with.js +3 -3
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -1
- package/dist/helper/expect/to-match-file-snapshot.js +23 -23
- package/dist/helper/hot-update/index.d.ts +1 -1
- package/dist/helper/hot-update/loader.js +1 -1
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +15 -15
- package/dist/helper/index.d.ts +8 -8
- package/dist/helper/is.js +2 -2
- package/dist/helper/legacy/EventSourceForNode.js +8 -8
- package/dist/helper/legacy/LogTestPlugin.js +18 -18
- package/dist/helper/legacy/asModule.js +6 -6
- package/dist/helper/legacy/captureStdio.js +6 -6
- package/dist/helper/legacy/checkArrayExpectation.js +26 -23
- package/dist/helper/legacy/copyDiff.js +5 -5
- package/dist/helper/legacy/createFakeWorker.js +13 -13
- package/dist/helper/legacy/createLazyTestEnv.js +11 -11
- package/dist/helper/legacy/currentScript.js +1 -1
- package/dist/helper/legacy/deprecationTracking.js +13 -19
- package/dist/helper/legacy/expectSource.js +5 -5
- package/dist/helper/legacy/fakeSystem.js +14 -14
- package/dist/helper/legacy/findOutputFiles.js +4 -4
- package/dist/helper/legacy/parseResource.js +4 -4
- package/dist/helper/legacy/regexEscape.js +2 -2
- package/dist/helper/legacy/supportDefaultAssignment.js +2 -2
- package/dist/helper/legacy/supportsTextDecoder.js +2 -2
- package/dist/helper/legacy/supportsUsing.js +1 -1
- package/dist/helper/legacy/urlToRelativePath.js +3 -3
- package/dist/helper/parse-modules.js +13 -13
- package/dist/helper/read-config-file.d.ts +2 -2
- package/dist/helper/read-config-file.js +3 -3
- package/dist/helper/serializers.d.ts +1 -1
- package/dist/helper/serializers.js +11 -11
- package/dist/helper/setup-env.js +17 -17
- package/dist/helper/setup-expect.js +1 -1
- package/dist/helper/setup-wasm.js +4 -4
- package/dist/helper/stringify-config.d.ts +1 -1
- package/dist/helper/stringify-config.js +3 -3
- package/dist/helper/update-snapshot.js +1 -1
- package/dist/helper/util/checkSourceMap.js +16 -17
- package/dist/helper/util/checkStats.js +3 -3
- package/dist/helper/util/expectWarningFactory.js +2 -2
- package/dist/helper/util/filterUtil.js +9 -9
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.js +13 -13
- package/dist/runner/index.d.ts +2 -2
- package/dist/runner/node/index.d.ts +2 -2
- package/dist/runner/node/index.js +75 -74
- package/dist/runner/web/index.d.ts +2 -2
- package/dist/runner/web/index.js +45 -45
- package/dist/test/context.d.ts +2 -2
- package/dist/test/context.js +4 -4
- package/dist/test/creator.d.ts +1 -1
- package/dist/test/creator.js +28 -28
- package/dist/test/debug.d.ts +1 -1
- package/dist/test/debug.js +31 -31
- package/dist/test/tester.d.ts +1 -1
- package/dist/test/tester.js +11 -11
- package/dist/type.d.ts +3 -3
- package/package.json +7 -7
- package/rstest.d.ts +12 -12
package/dist/compiler.js
CHANGED
|
@@ -40,13 +40,13 @@ class TestCompilerManager {
|
|
|
40
40
|
return this.compilerInstance;
|
|
41
41
|
}
|
|
42
42
|
createCompiler() {
|
|
43
|
-
this.compilerInstance = require(
|
|
43
|
+
this.compilerInstance = require('@rspack/core')(this.compilerOptions);
|
|
44
44
|
if (__DEBUG__) {
|
|
45
45
|
const context = this.context;
|
|
46
46
|
this.compilerInstance = new Proxy(this.compilerInstance, {
|
|
47
47
|
get(target, p, receiver) {
|
|
48
48
|
const value = Reflect.get(target, p, receiver);
|
|
49
|
-
if (typeof value ===
|
|
49
|
+
if (typeof value === 'function' &&
|
|
50
50
|
core_1.Compiler.prototype.hasOwnProperty(p)) {
|
|
51
51
|
return value.bind(target);
|
|
52
52
|
}
|
|
@@ -54,27 +54,27 @@ class TestCompilerManager {
|
|
|
54
54
|
},
|
|
55
55
|
set(target, p, value, receiver) {
|
|
56
56
|
const debugSetProperties = context.getValue(debug_1.DEBUG_SCOPES.CreateCompilerSetProperties) || [];
|
|
57
|
-
debugSetProperties.push(`${p} ${new Error().stack?.split(
|
|
57
|
+
debugSetProperties.push(`${p} ${new Error().stack?.split('\n')[2]?.trim()}`);
|
|
58
58
|
context.setValue(debug_1.DEBUG_SCOPES.CreateCompilerSetProperties, debugSetProperties);
|
|
59
59
|
return Reflect.set(target, p, value, receiver);
|
|
60
|
-
}
|
|
60
|
+
},
|
|
61
61
|
});
|
|
62
62
|
this.context.setValue(debug_1.DEBUG_SCOPES.CreateCompilerInstance, {
|
|
63
|
-
path: require.resolve(
|
|
64
|
-
mode:
|
|
63
|
+
path: require.resolve('@rspack/core'),
|
|
64
|
+
mode: 'no-callback',
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
this.emitter.emit(ECompilerEvent.Create, this.compilerInstance);
|
|
68
68
|
return this.compilerInstance;
|
|
69
69
|
}
|
|
70
70
|
createCompilerWithCallback(callback) {
|
|
71
|
-
this.compilerInstance = require(
|
|
71
|
+
this.compilerInstance = require('@rspack/core')(this.compilerOptions, callback);
|
|
72
72
|
if (__DEBUG__) {
|
|
73
73
|
const context = this.context;
|
|
74
74
|
this.compilerInstance = new Proxy(this.compilerInstance, {
|
|
75
75
|
get(target, p, receiver) {
|
|
76
76
|
const value = Reflect.get(target, p, receiver);
|
|
77
|
-
if (typeof value ===
|
|
77
|
+
if (typeof value === 'function' &&
|
|
78
78
|
core_1.Compiler.prototype.hasOwnProperty(p)) {
|
|
79
79
|
return value.bind(target);
|
|
80
80
|
}
|
|
@@ -82,14 +82,14 @@ class TestCompilerManager {
|
|
|
82
82
|
},
|
|
83
83
|
set(target, p, value, receiver) {
|
|
84
84
|
const debugSetProperties = context.getValue(debug_1.DEBUG_SCOPES.CreateCompilerSetProperties) || [];
|
|
85
|
-
debugSetProperties.push(`${p} ${new Error().stack?.split(
|
|
85
|
+
debugSetProperties.push(`${p} ${new Error().stack?.split('\n')[2]?.trim()}`);
|
|
86
86
|
context.setValue(debug_1.DEBUG_SCOPES.CreateCompilerSetProperties, debugSetProperties);
|
|
87
87
|
return Reflect.set(target, p, value, receiver);
|
|
88
|
-
}
|
|
88
|
+
},
|
|
89
89
|
});
|
|
90
90
|
this.context.setValue(debug_1.DEBUG_SCOPES.CreateCompilerInstance, {
|
|
91
|
-
path: require.resolve(
|
|
92
|
-
mode:
|
|
91
|
+
path: require.resolve('@rspack/core'),
|
|
92
|
+
mode: 'callback',
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
this.emitter.emit(ECompilerEvent.Create, this.compilerInstance);
|
|
@@ -97,13 +97,13 @@ class TestCompilerManager {
|
|
|
97
97
|
}
|
|
98
98
|
build() {
|
|
99
99
|
if (!this.compilerInstance)
|
|
100
|
-
throw new Error(
|
|
100
|
+
throw new Error('Compiler should be created before build');
|
|
101
101
|
return new Promise((resolve, reject) => {
|
|
102
102
|
try {
|
|
103
103
|
const context = this.context;
|
|
104
104
|
if (__DEBUG__) {
|
|
105
105
|
context.setValue(debug_1.DEBUG_SCOPES.BuildMethod, {
|
|
106
|
-
method:
|
|
106
|
+
method: 'run',
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
this.compilerInstance.run((error, newStats) => {
|
|
@@ -111,8 +111,8 @@ class TestCompilerManager {
|
|
|
111
111
|
if (error) {
|
|
112
112
|
if (__DEBUG__) {
|
|
113
113
|
context.setValue(debug_1.DEBUG_SCOPES.BuildError, {
|
|
114
|
-
type:
|
|
115
|
-
errors: [error]
|
|
114
|
+
type: 'fatal',
|
|
115
|
+
errors: [error],
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
return reject(error);
|
|
@@ -121,15 +121,15 @@ class TestCompilerManager {
|
|
|
121
121
|
if (__DEBUG__) {
|
|
122
122
|
if (newStats?.hasErrors()) {
|
|
123
123
|
context.setValue(debug_1.DEBUG_SCOPES.BuildError, {
|
|
124
|
-
type:
|
|
124
|
+
type: 'stats',
|
|
125
125
|
errors: newStats.toJson({
|
|
126
|
-
errors: true
|
|
127
|
-
}).errors || []
|
|
126
|
+
errors: true,
|
|
127
|
+
}).errors || [],
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
if (newStats?.hasWarnings()) {
|
|
131
131
|
context.setValue(debug_1.DEBUG_SCOPES.BuildWarning, newStats.toJson({
|
|
132
|
-
warnings: true
|
|
132
|
+
warnings: true,
|
|
133
133
|
}).warnings || []);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
@@ -143,7 +143,7 @@ class TestCompilerManager {
|
|
|
143
143
|
}
|
|
144
144
|
watch(timeout = 1000) {
|
|
145
145
|
if (!this.compilerInstance)
|
|
146
|
-
throw new Error(
|
|
146
|
+
throw new Error('Compiler should be created before watch');
|
|
147
147
|
const context = this.context;
|
|
148
148
|
const watchOptions = {
|
|
149
149
|
// IMPORTANT:
|
|
@@ -153,12 +153,12 @@ class TestCompilerManager {
|
|
|
153
153
|
// Rspack ignored node_modules and .git by default for better performance, but for tests we
|
|
154
154
|
// want to watch all files, which aligns with webpack's default behavior
|
|
155
155
|
ignored: [],
|
|
156
|
-
aggregateTimeout: timeout
|
|
156
|
+
aggregateTimeout: timeout,
|
|
157
157
|
};
|
|
158
158
|
if (__DEBUG__) {
|
|
159
159
|
context.setValue(debug_1.DEBUG_SCOPES.BuildMethod, {
|
|
160
|
-
method:
|
|
161
|
-
options: watchOptions
|
|
160
|
+
method: 'watch',
|
|
161
|
+
options: watchOptions,
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
this.compilerInstance.watch(watchOptions, (error, newStats) => {
|
|
@@ -166,8 +166,8 @@ class TestCompilerManager {
|
|
|
166
166
|
if (__DEBUG__) {
|
|
167
167
|
if (error) {
|
|
168
168
|
context.setValue(debug_1.DEBUG_SCOPES.BuildError, {
|
|
169
|
-
type:
|
|
170
|
-
errors: [error]
|
|
169
|
+
type: 'fatal',
|
|
170
|
+
errors: [error],
|
|
171
171
|
});
|
|
172
172
|
return error;
|
|
173
173
|
}
|
|
@@ -176,15 +176,15 @@ class TestCompilerManager {
|
|
|
176
176
|
if (__DEBUG__) {
|
|
177
177
|
if (newStats.hasErrors()) {
|
|
178
178
|
context.setValue(debug_1.DEBUG_SCOPES.BuildError, {
|
|
179
|
-
type:
|
|
179
|
+
type: 'stats',
|
|
180
180
|
errors: newStats.toJson({
|
|
181
|
-
errors: true
|
|
182
|
-
}).errors || []
|
|
181
|
+
errors: true,
|
|
182
|
+
}).errors || [],
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
if (newStats.hasWarnings()) {
|
|
186
186
|
context.setValue(debug_1.DEBUG_SCOPES.BuildWarning, newStats.toJson({
|
|
187
|
-
warnings: true
|
|
187
|
+
warnings: true,
|
|
188
188
|
}).warnings || []);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
@@ -202,7 +202,7 @@ class TestCompilerManager {
|
|
|
202
202
|
close() {
|
|
203
203
|
return new Promise((resolve, reject) => {
|
|
204
204
|
if (this.compilerInstance) {
|
|
205
|
-
this.compilerInstance.close(e => {
|
|
205
|
+
this.compilerInstance.close((e) => {
|
|
206
206
|
this.emitter.emit(ECompilerEvent.Close, e);
|
|
207
207
|
e ? reject(e) : resolve();
|
|
208
208
|
});
|
|
@@ -2,7 +2,7 @@ export declare const isDirectory: (p: string) => boolean;
|
|
|
2
2
|
export declare const isFile: (p: string) => boolean;
|
|
3
3
|
export declare const isValidCaseDirectory: (name: string) => boolean;
|
|
4
4
|
export declare function describeByWalk(testFile: string, createCase: (name: string, src: string, dist: string) => void, options?: {
|
|
5
|
-
type?:
|
|
5
|
+
type?: 'file' | 'directory';
|
|
6
6
|
level?: number;
|
|
7
7
|
source?: string;
|
|
8
8
|
dist?: string;
|
package/dist/helper/directory.js
CHANGED
|
@@ -12,44 +12,44 @@ const isDirectory = (p) => node_fs_1.default.lstatSync(p).isDirectory();
|
|
|
12
12
|
exports.isDirectory = isDirectory;
|
|
13
13
|
const isFile = (p) => node_fs_1.default.lstatSync(p).isFile();
|
|
14
14
|
exports.isFile = isFile;
|
|
15
|
-
const isValidCaseDirectory = (name) => !name.startsWith(
|
|
15
|
+
const isValidCaseDirectory = (name) => !name.startsWith('_') && !name.startsWith('.') && name !== 'node_modules';
|
|
16
16
|
exports.isValidCaseDirectory = isValidCaseDirectory;
|
|
17
17
|
function describeByWalk(testFile, createCase, options = {}) {
|
|
18
18
|
const describeFn = options.describe || describe;
|
|
19
19
|
const testBasename = node_path_1.default
|
|
20
20
|
.basename(testFile)
|
|
21
|
-
.replace(/(\.part\d+)?\.(diff|hot)?test\.(j|t)s/,
|
|
21
|
+
.replace(/(\.part\d+)?\.(diff|hot)?test\.(j|t)s/, '');
|
|
22
22
|
const testId = testBasename.charAt(0).toLowerCase() + testBasename.slice(1);
|
|
23
23
|
const sourceBase = options.source || node_path_1.default.join(node_path_1.default.dirname(testFile), `${testId}Cases`);
|
|
24
24
|
const testSourceId = node_path_1.default.basename(sourceBase);
|
|
25
|
-
const distBase = options.dist || node_path_1.default.join(node_path_1.default.dirname(testFile),
|
|
25
|
+
const distBase = options.dist || node_path_1.default.join(node_path_1.default.dirname(testFile), 'js', testId);
|
|
26
26
|
const level = options.level || 2;
|
|
27
|
-
const type = options.type ||
|
|
27
|
+
const type = options.type || 'directory';
|
|
28
28
|
const absoluteDist = options.absoluteDist ?? true;
|
|
29
29
|
function describeDirectory(dirname, currentLevel) {
|
|
30
30
|
node_fs_1.default.readdirSync(node_path_1.default.join(sourceBase, dirname))
|
|
31
31
|
.filter(exports.isValidCaseDirectory)
|
|
32
|
-
.filter(folder => {
|
|
32
|
+
.filter((folder) => {
|
|
33
33
|
if (options.exclude) {
|
|
34
|
-
if (options.exclude.some(exclude => {
|
|
35
|
-
return exclude.test(node_path_1.default.join(dirname, folder).replace(/\\/g,
|
|
34
|
+
if (options.exclude.some((exclude) => {
|
|
35
|
+
return exclude.test(node_path_1.default.join(dirname, folder).replace(/\\/g, '/'));
|
|
36
36
|
})) {
|
|
37
37
|
return false;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
return true;
|
|
41
41
|
})
|
|
42
|
-
.filter(folder => {
|
|
42
|
+
.filter((folder) => {
|
|
43
43
|
const p = node_path_1.default.join(sourceBase, dirname, folder);
|
|
44
|
-
if (type ===
|
|
44
|
+
if (type === 'file' && currentLevel === 1) {
|
|
45
45
|
return (0, exports.isFile)(p);
|
|
46
46
|
}
|
|
47
|
-
if (type ===
|
|
47
|
+
if (type === 'directory' || currentLevel > 1) {
|
|
48
48
|
return (0, exports.isDirectory)(p);
|
|
49
49
|
}
|
|
50
50
|
return false;
|
|
51
51
|
})
|
|
52
|
-
.map(folder => {
|
|
52
|
+
.map((folder) => {
|
|
53
53
|
const caseName = node_path_1.default.join(dirname, folder);
|
|
54
54
|
if (currentLevel > 1) {
|
|
55
55
|
describeDirectory(caseName, currentLevel - 1);
|
|
@@ -57,16 +57,16 @@ function describeByWalk(testFile, createCase, options = {}) {
|
|
|
57
57
|
else {
|
|
58
58
|
const name = (0, _1.escapeSep)(node_path_1.default
|
|
59
59
|
.join(`${testId}Cases-${testSourceId}`, caseName)
|
|
60
|
-
.split(
|
|
60
|
+
.split('.')
|
|
61
61
|
.shift());
|
|
62
62
|
describeFn(name, () => {
|
|
63
63
|
const source = node_path_1.default.join(sourceBase, caseName);
|
|
64
|
-
let dist =
|
|
64
|
+
let dist = '';
|
|
65
65
|
if (absoluteDist) {
|
|
66
66
|
dist = node_path_1.default.join(distBase, caseName);
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
|
-
const relativeDist = options.dist ||
|
|
69
|
+
const relativeDist = options.dist || 'dist';
|
|
70
70
|
if (node_path_1.default.isAbsolute(relativeDist)) {
|
|
71
71
|
dist = node_path_1.default.join(relativeDist, caseName);
|
|
72
72
|
}
|
|
@@ -80,6 +80,6 @@ function describeByWalk(testFile, createCase, options = {}) {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
describeFn(testId, () => {
|
|
83
|
-
describeDirectory(
|
|
83
|
+
describeDirectory('', level);
|
|
84
84
|
});
|
|
85
85
|
}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.disableIconvLiteWarning = disableIconvLiteWarning;
|
|
4
4
|
function disableIconvLiteWarning() {
|
|
5
5
|
for (const [path, mod] of Object.entries(require.cache)) {
|
|
6
|
-
if (path.includes(
|
|
7
|
-
typeof mod?.exports ===
|
|
8
|
-
typeof mod.exports.decode ===
|
|
6
|
+
if (path.includes('iconv-lite') &&
|
|
7
|
+
typeof mod?.exports === 'object' &&
|
|
8
|
+
typeof mod.exports.decode === 'function') {
|
|
9
9
|
mod.exports.skipDecodeWarning = true;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeDiff = void 0;
|
|
4
4
|
const CURRENT_CWD = process.cwd();
|
|
5
|
-
const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g,
|
|
6
|
-
const cwdRegExp = new RegExp(`${quoteMeta(CURRENT_CWD)}((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)`,
|
|
5
|
+
const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, '\\$&');
|
|
6
|
+
const cwdRegExp = new RegExp(`${quoteMeta(CURRENT_CWD)}((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)`, 'g');
|
|
7
7
|
const escapedCwd = JSON.stringify(CURRENT_CWD).slice(1, -1);
|
|
8
|
-
const escapedCwdRegExp = new RegExp(`${quoteMeta(escapedCwd)}((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)`,
|
|
8
|
+
const escapedCwdRegExp = new RegExp(`${quoteMeta(escapedCwd)}((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)`, 'g');
|
|
9
9
|
const normalizeDiff = (diff) => {
|
|
10
10
|
let normalizedStr = diff.value;
|
|
11
|
-
if (CURRENT_CWD.startsWith(
|
|
12
|
-
normalizedStr = normalizedStr.replace(new RegExp(quoteMeta(CURRENT_CWD),
|
|
11
|
+
if (CURRENT_CWD.startsWith('/')) {
|
|
12
|
+
normalizedStr = normalizedStr.replace(new RegExp(quoteMeta(CURRENT_CWD), 'g'), '<cwd>');
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
normalizedStr = normalizedStr.replace(cwdRegExp, (_, g) => `<cwd>${g.replace(/\\/g,
|
|
16
|
-
normalizedStr = normalizedStr.replace(escapedCwdRegExp, (_, g) => `<cwd>${g.replace(/\\\\/g,
|
|
15
|
+
normalizedStr = normalizedStr.replace(cwdRegExp, (_, g) => `<cwd>${g.replace(/\\/g, '/')}`);
|
|
16
|
+
normalizedStr = normalizedStr.replace(escapedCwdRegExp, (_, g) => `<cwd>${g.replace(/\\\\/g, '/')}`);
|
|
17
17
|
}
|
|
18
|
-
normalizedStr = normalizedStr.replace(/@@ -\d+,\d+ \+\d+,\d+ @@/g,
|
|
18
|
+
normalizedStr = normalizedStr.replace(/@@ -\d+,\d+ \+\d+,\d+ @@/g, '@@ ... @@');
|
|
19
19
|
return normalizedStr;
|
|
20
20
|
};
|
|
21
21
|
exports.normalizeDiff = normalizeDiff;
|
|
@@ -13,19 +13,19 @@ const prettyFormatOptions = {
|
|
|
13
13
|
plugins: [
|
|
14
14
|
{
|
|
15
15
|
test(val) {
|
|
16
|
-
return typeof val ===
|
|
16
|
+
return typeof val === 'string';
|
|
17
17
|
},
|
|
18
18
|
print(val) {
|
|
19
19
|
return `"${val
|
|
20
|
-
.replace(/\\/gm,
|
|
20
|
+
.replace(/\\/gm, '/')
|
|
21
21
|
.replace(/"/gm, '\\"')
|
|
22
|
-
.replace(/\r?\n/gm,
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
]
|
|
22
|
+
.replace(/\r?\n/gm, '')}"`;
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
26
|
};
|
|
27
27
|
function cleanErrorStack(message) {
|
|
28
|
-
return message.replace(ERROR_STACK_PATTERN,
|
|
28
|
+
return message.replace(ERROR_STACK_PATTERN, '$1xxx');
|
|
29
29
|
}
|
|
30
30
|
function cleanError(err) {
|
|
31
31
|
const result = {};
|
|
@@ -42,8 +42,8 @@ function cleanError(err) {
|
|
|
42
42
|
}
|
|
43
43
|
function normalizeDignostics(received) {
|
|
44
44
|
return (0, pretty_format_1.default)({
|
|
45
|
-
errors: received.errors.map(e => cleanError(e)),
|
|
46
|
-
warnings: received.warnings.map(e => cleanError(e))
|
|
45
|
+
errors: received.errors.map((e) => cleanError(e)),
|
|
46
|
+
warnings: received.warnings.map((e) => cleanError(e)),
|
|
47
47
|
}, prettyFormatOptions).trim();
|
|
48
48
|
}
|
|
49
49
|
function normalizeError(received) {
|
|
@@ -6,36 +6,36 @@ const path_serializer_1 = require("path-serializer");
|
|
|
6
6
|
// 2. replace <RSPACK_ROOT> etc
|
|
7
7
|
// 3. transform win32 sep
|
|
8
8
|
const placeholderSerializer = (0, path_serializer_1.createSnapshotSerializer)({
|
|
9
|
-
root: __dirname.includes(
|
|
9
|
+
root: __dirname.includes('node_modules')
|
|
10
10
|
? // Use `process.cwd()` when using outside Rspack
|
|
11
11
|
process.cwd()
|
|
12
12
|
: __ROOT_PATH__,
|
|
13
13
|
replace: [
|
|
14
14
|
{
|
|
15
15
|
match: __RSPACK_TEST_TOOLS_PATH__,
|
|
16
|
-
mark:
|
|
16
|
+
mark: 'test_tools_root',
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
match: __TEST_PATH__,
|
|
20
|
-
mark:
|
|
20
|
+
mark: 'test_root',
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
match: __RSPACK_PATH__,
|
|
24
|
-
mark:
|
|
24
|
+
mark: 'rspack_root',
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
match: /:\d+:\d+-\d+:\d+/g,
|
|
28
|
-
mark:
|
|
28
|
+
mark: 'line_col_range',
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
match: /:\d+:\d+/g,
|
|
32
|
-
mark:
|
|
33
|
-
}
|
|
32
|
+
mark: 'line_col',
|
|
33
|
+
},
|
|
34
34
|
],
|
|
35
35
|
features: {
|
|
36
36
|
replaceWorkspace: false,
|
|
37
37
|
addDoubleQuotes: false,
|
|
38
|
-
escapeDoubleQuotes: false
|
|
39
|
-
}
|
|
38
|
+
escapeDoubleQuotes: false,
|
|
39
|
+
},
|
|
40
40
|
});
|
|
41
41
|
exports.normalizePlaceholder = placeholderSerializer.serialize;
|
|
@@ -4,11 +4,11 @@ exports.normalizeStats = void 0;
|
|
|
4
4
|
const normalizeStats = (stats) => {
|
|
5
5
|
return (stats.value
|
|
6
6
|
// CHANGE: Remove potential line break and "|" caused by long text
|
|
7
|
-
.replace(/((ERROR|WARNING)([\s\S](?!╭|├))*?)(\n {2}│ )/g,
|
|
7
|
+
.replace(/((ERROR|WARNING)([\s\S](?!╭|├))*?)(\n {2}│ )/g, '$1')
|
|
8
8
|
// CHANGE: Update the regular expression to replace the 'Rspack' version string
|
|
9
|
-
.replace(/Rspack [^ )]+(\)?) compiled/g,
|
|
10
|
-
.replace(/(\w)\\(\w)/g,
|
|
11
|
-
.replace(/, additional resolving: X ms/g,
|
|
12
|
-
.replace(/Unexpected identifier '.+?'/g,
|
|
9
|
+
.replace(/Rspack [^ )]+(\)?) compiled/g, 'Rspack x.x.x$1 compiled')
|
|
10
|
+
.replace(/(\w)\\(\w)/g, '$1/$2')
|
|
11
|
+
.replace(/, additional resolving: X ms/g, '')
|
|
12
|
+
.replace(/Unexpected identifier '.+?'/g, 'Unexpected identifier'));
|
|
13
13
|
};
|
|
14
14
|
exports.normalizeStats = normalizeStats;
|
|
@@ -6,7 +6,7 @@ function toBeTypeOf(received, expected) {
|
|
|
6
6
|
const objType = typeof received;
|
|
7
7
|
const pass = objType === expected;
|
|
8
8
|
const message = pass
|
|
9
|
-
? () => `${this.utils.matcherHint(
|
|
10
|
-
: () => `${this.utils.matcherHint(
|
|
9
|
+
? () => `${this.utils.matcherHint('.not.toBeTypeOf')}\n\nExpected value to not be (using typeof):\n ${this.utils.printExpected(expected)}\nReceived:\n ${this.utils.printReceived(objType)}`
|
|
10
|
+
: () => `${this.utils.matcherHint('.toBeTypeOf')}\n\nExpected value to be (using typeof):\n ${this.utils.printExpected(expected)}\nReceived:\n ${this.utils.printReceived(objType)}`;
|
|
11
11
|
return { message, pass };
|
|
12
12
|
}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toEndWith = toEndWith;
|
|
4
4
|
// @ts-nocheck
|
|
5
5
|
function toEndWith(received, expected) {
|
|
6
|
-
const pass = typeof received ===
|
|
6
|
+
const pass = typeof received === 'string' && received.endsWith(expected);
|
|
7
7
|
const message = pass
|
|
8
|
-
? () => `${this.utils.matcherHint(
|
|
9
|
-
: () => `${this.utils.matcherHint(
|
|
8
|
+
? () => `${this.utils.matcherHint('.not.toEndWith')}\n\nExpected value to not end with:\n ${this.utils.printExpected(expected)}\nReceived:\n ${this.utils.printReceived(received)}`
|
|
9
|
+
: () => `${this.utils.matcherHint('.toEndWith')}\n\nExpected value to end with:\n ${this.utils.printExpected(expected)}\nReceived:\n ${this.utils.printReceived(received)}`;
|
|
10
10
|
return { message, pass };
|
|
11
11
|
}
|
|
@@ -14,7 +14,7 @@ export declare function toMatchFileSnapshotSync(this: {
|
|
|
14
14
|
added: number;
|
|
15
15
|
updated: number;
|
|
16
16
|
unmatched: number;
|
|
17
|
-
_updateSnapshot:
|
|
17
|
+
_updateSnapshot: 'none' | 'new' | 'all';
|
|
18
18
|
};
|
|
19
19
|
}, rawContent: string | Buffer, filepath: string, options?: FileMatcherOptions): {
|
|
20
20
|
pass: boolean;
|
|
@@ -12,9 +12,9 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
12
12
|
const filenamify_1 = __importDefault(require("filenamify"));
|
|
13
13
|
const jest_diff_1 = require("jest-diff");
|
|
14
14
|
const serializers_1 = require("../serializers");
|
|
15
|
-
const { serialize } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve(
|
|
15
|
+
const { serialize } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve('jest-snapshot')), './utils.js'));
|
|
16
16
|
// get jest builtin serializers
|
|
17
|
-
const { getSerializers } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve(
|
|
17
|
+
const { getSerializers } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve('jest-snapshot')), './plugins.js'));
|
|
18
18
|
/**
|
|
19
19
|
* Check if 2 strings or buffer are equal
|
|
20
20
|
*/
|
|
@@ -36,73 +36,73 @@ function toMatchFileSnapshotSync(rawContent, filepath, options = {}) {
|
|
|
36
36
|
plugins: [
|
|
37
37
|
...getSerializers(),
|
|
38
38
|
// Rspack serializers
|
|
39
|
-
...serializers_1.serializers
|
|
40
|
-
]
|
|
39
|
+
...serializers_1.serializers,
|
|
40
|
+
],
|
|
41
41
|
});
|
|
42
42
|
const { isNot, snapshotState } = this;
|
|
43
43
|
const filename = filepath === undefined
|
|
44
44
|
? // If file name is not specified, generate one from the test title
|
|
45
|
-
node_path_1.default.join(node_path_1.default.dirname(this.testPath),
|
|
46
|
-
replacement:
|
|
47
|
-
}).replace(/\s/g,
|
|
45
|
+
node_path_1.default.join(node_path_1.default.dirname(this.testPath), '__file_snapshots__', `${(0, filenamify_1.default)(this.currentTestName, {
|
|
46
|
+
replacement: '-',
|
|
47
|
+
}).replace(/\s/g, '-')}-${this.assertionCalls}`)
|
|
48
48
|
: filepath;
|
|
49
|
-
if (snapshotState._updateSnapshot ===
|
|
49
|
+
if (snapshotState._updateSnapshot === 'none' && !node_fs_1.default.existsSync(filename)) {
|
|
50
50
|
// We're probably running in CI environment
|
|
51
51
|
snapshotState.unmatched++;
|
|
52
52
|
return {
|
|
53
53
|
pass: isNot,
|
|
54
|
-
message: () => `New output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} was ${chalk_1.default.bold.red(
|
|
54
|
+
message: () => `New output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} was ${chalk_1.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 ${chalk_1.default.blue('continuous integration (CI) environment')} in which snapshots are not written by default.\n\n`,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
if (node_fs_1.default.existsSync(filename)) {
|
|
58
58
|
const output = node_fs_1.default
|
|
59
|
-
.readFileSync(filename, Buffer.isBuffer(content) ? null :
|
|
60
|
-
.replace(/\r\n/g,
|
|
59
|
+
.readFileSync(filename, Buffer.isBuffer(content) ? null : 'utf8')
|
|
60
|
+
.replace(/\r\n/g, '\n');
|
|
61
61
|
if (isNot) {
|
|
62
62
|
// The matcher is being used with `.not`
|
|
63
63
|
if (!isEqual(content, output)) {
|
|
64
64
|
// The value of `pass` is reversed when used with `.not`
|
|
65
|
-
return { pass: false, message: () =>
|
|
65
|
+
return { pass: false, message: () => '' };
|
|
66
66
|
}
|
|
67
67
|
snapshotState.unmatched++;
|
|
68
68
|
return {
|
|
69
69
|
pass: true,
|
|
70
|
-
message: () => `Expected received content ${chalk_1.default.red(
|
|
70
|
+
message: () => `Expected received content ${chalk_1.default.red('to not match')} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.`,
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
if (isEqual(content, output)) {
|
|
74
|
-
return { pass: true, message: () =>
|
|
74
|
+
return { pass: true, message: () => '' };
|
|
75
75
|
}
|
|
76
|
-
if (snapshotState._updateSnapshot ===
|
|
76
|
+
if (snapshotState._updateSnapshot === 'all') {
|
|
77
77
|
node_fs_1.default.mkdirSync(node_path_1.default.dirname(filename), { recursive: true });
|
|
78
78
|
node_fs_1.default.writeFileSync(filename, content);
|
|
79
79
|
snapshotState.updated++;
|
|
80
|
-
return { pass: true, message: () =>
|
|
80
|
+
return { pass: true, message: () => '' };
|
|
81
81
|
}
|
|
82
82
|
snapshotState.unmatched++;
|
|
83
83
|
const difference = Buffer.isBuffer(content) || Buffer.isBuffer(output)
|
|
84
|
-
?
|
|
84
|
+
? ''
|
|
85
85
|
: `\n\n${(0, jest_diff_1.diff)(output, content, Object.assign({
|
|
86
86
|
expand: false,
|
|
87
87
|
contextLines: 5,
|
|
88
|
-
aAnnotation:
|
|
88
|
+
aAnnotation: 'Snapshot',
|
|
89
89
|
}, options.diff || {}))}`;
|
|
90
90
|
return {
|
|
91
91
|
pass: false,
|
|
92
|
-
message: () => `Received content ${chalk_1.default.red("doesn't match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.${difference}
|
|
92
|
+
message: () => `Received content ${chalk_1.default.red("doesn't match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.${difference}`,
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
if (!isNot &&
|
|
96
|
-
(snapshotState._updateSnapshot ===
|
|
97
|
-
snapshotState._updateSnapshot ===
|
|
96
|
+
(snapshotState._updateSnapshot === 'new' ||
|
|
97
|
+
snapshotState._updateSnapshot === 'all')) {
|
|
98
98
|
node_fs_1.default.mkdirSync(node_path_1.default.dirname(filename), { recursive: true });
|
|
99
99
|
node_fs_1.default.writeFileSync(filename, content);
|
|
100
100
|
snapshotState.added++;
|
|
101
|
-
return { pass: true, message: () =>
|
|
101
|
+
return { pass: true, message: () => '' };
|
|
102
102
|
}
|
|
103
103
|
snapshotState.unmatched++;
|
|
104
104
|
return {
|
|
105
105
|
pass: true,
|
|
106
|
-
message: () => `The output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} ${chalk_1.default.bold.red("doesn't exist")}
|
|
106
|
+
message: () => `The output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} ${chalk_1.default.bold.red("doesn't exist")}.`,
|
|
107
107
|
};
|
|
108
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { HotUpdatePlugin } from
|
|
1
|
+
export { HotUpdatePlugin } from './plugin';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const loader = function (c) {
|
|
4
|
-
return c.replace(/NEXT_HMR/g,
|
|
4
|
+
return c.replace(/NEXT_HMR/g, 'NEXT_HMR.bind(null, module)');
|
|
5
5
|
};
|
|
6
6
|
module.exports = loader;
|
|
7
7
|
exports.default = loader;
|