@rspack/test-tools 1.0.0-beta.2 → 1.0.0-beta.3
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/compare/replace-runtime-module-name.d.ts +1 -1
- package/dist/compare/replace-runtime-module-name.js +5 -8
- package/dist/helper/expect/to-match-file-snapshot.d.ts +18 -6
- package/dist/helper/expect/to-match-file-snapshot.js +8 -15
- package/dist/helper/replace-paths.js +3 -3
- package/dist/helper/util/identifier.js +6 -6
- package/dist/processor/defaults.js +11 -9
- package/dist/processor/error.d.ts +2 -2
- package/dist/processor/hook.js +4 -6
- package/dist/processor/hot-step.js +9 -11
- package/dist/runner/hot-step.js +5 -5
- package/dist/runner/hot.js +5 -5
- package/dist/runner/runner/web/fake.js +1 -3
- package/dist/runner/runner/web/jsdom.js +4 -6
- package/package.json +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function replaceRuntimeModuleName(
|
|
1
|
+
export declare function replaceRuntimeModuleName(name: string): string;
|
|
@@ -53,17 +53,14 @@ const RUNTIME_MODULE_PARAM_REGEX = {
|
|
|
53
53
|
"webpack/runtime/get_main_filename": /webpack\/runtime\/get_main_filename\/([\w.\-_\s]+)(\*\/)?/g,
|
|
54
54
|
"webpack/runtime/chunk_prefetch_function": /webpack\/runtime\/chunk_prefetch_function\/([\w.\-_\s]+)(\*\/)?/g
|
|
55
55
|
};
|
|
56
|
-
function replaceRuntimeModuleName(
|
|
57
|
-
|
|
56
|
+
function replaceRuntimeModuleName(name) {
|
|
57
|
+
return Object.entries(RUNTIME_MODULE_NAME_MAPPING).reduce((name, [rspackName, webpackName]) => {
|
|
58
58
|
if (RUNTIME_MODULE_PARAM_REGEX[rspackName]) {
|
|
59
|
-
|
|
59
|
+
return name.replace(RUNTIME_MODULE_PARAM_REGEX[rspackName], (_, $1, $2) => {
|
|
60
60
|
return webpackName.replace("$1", $1.trim()) + ($2 ? " */" : "");
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return raw;
|
|
63
|
+
return name.split(rspackName).join(webpackName);
|
|
64
|
+
}, name);
|
|
68
65
|
}
|
|
69
66
|
exports.replaceRuntimeModuleName = replaceRuntimeModuleName;
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { FileMatcherOptions } from "../../../jest";
|
|
1
3
|
/**
|
|
2
4
|
* Match given content against content of the specified file.
|
|
3
5
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @this {{ testPath: string, currentTestName: string, assertionCalls: number, isNot: boolean, snapshotState: { added: number, updated: number, unmatched: number, _updateSnapshot: 'none' | 'new' | 'all' } }}
|
|
6
|
+
* @param content Output content to match
|
|
7
|
+
* @param filepath Path to the file to match against
|
|
8
|
+
* @param options Additional options for matching
|
|
8
9
|
*/
|
|
9
|
-
export declare function toMatchFileSnapshot(
|
|
10
|
-
|
|
10
|
+
export declare function toMatchFileSnapshot(this: {
|
|
11
|
+
testPath: string;
|
|
12
|
+
currentTestName: string;
|
|
13
|
+
assertionCalls: number;
|
|
14
|
+
isNot: boolean;
|
|
15
|
+
snapshotState: {
|
|
16
|
+
added: number;
|
|
17
|
+
updated: number;
|
|
18
|
+
unmatched: number;
|
|
19
|
+
_updateSnapshot: "none" | "new" | "all";
|
|
20
|
+
};
|
|
21
|
+
}, content: string | Buffer, filepath: string, options?: FileMatcherOptions): {
|
|
22
|
+
pass: boolean;
|
|
11
23
|
message: () => string;
|
|
12
24
|
};
|
|
@@ -14,8 +14,6 @@ const jest_diff_1 = require("jest-diff");
|
|
|
14
14
|
const mkdirp_1 = __importDefault(require("mkdirp"));
|
|
15
15
|
/**
|
|
16
16
|
* Check if 2 strings or buffer are equal
|
|
17
|
-
* @param {string | Buffer} a
|
|
18
|
-
* @param {string | Buffer} b
|
|
19
17
|
*/
|
|
20
18
|
const isEqual = (a, b) => {
|
|
21
19
|
// @ts-ignore: TypeScript gives error if we pass string to buffer.equals
|
|
@@ -24,10 +22,9 @@ const isEqual = (a, b) => {
|
|
|
24
22
|
/**
|
|
25
23
|
* Match given content against content of the specified file.
|
|
26
24
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @this {{ testPath: string, currentTestName: string, assertionCalls: number, isNot: boolean, snapshotState: { added: number, updated: number, unmatched: number, _updateSnapshot: 'none' | 'new' | 'all' } }}
|
|
25
|
+
* @param content Output content to match
|
|
26
|
+
* @param filepath Path to the file to match against
|
|
27
|
+
* @param options Additional options for matching
|
|
31
28
|
*/
|
|
32
29
|
function toMatchFileSnapshot(content, filepath, options = {}) {
|
|
33
30
|
const { isNot, snapshotState } = this;
|
|
@@ -37,14 +34,6 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
|
|
|
37
34
|
replacement: "-"
|
|
38
35
|
}).replace(/\s/g, "-")}-${this.assertionCalls}`)
|
|
39
36
|
: filepath;
|
|
40
|
-
options = {
|
|
41
|
-
// Options for jest-diff
|
|
42
|
-
diff: Object.assign({
|
|
43
|
-
expand: false,
|
|
44
|
-
contextLines: 5,
|
|
45
|
-
aAnnotation: "Snapshot"
|
|
46
|
-
}, options.diff || {})
|
|
47
|
-
};
|
|
48
37
|
if (snapshotState._updateSnapshot === "none" && !node_fs_1.default.existsSync(filename)) {
|
|
49
38
|
// We're probably running in CI environment
|
|
50
39
|
snapshotState.unmatched++;
|
|
@@ -81,7 +70,11 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
|
|
|
81
70
|
snapshotState.unmatched++;
|
|
82
71
|
const difference = Buffer.isBuffer(content) || Buffer.isBuffer(output)
|
|
83
72
|
? ""
|
|
84
|
-
: `\n\n${(0, jest_diff_1.diff)(output, content,
|
|
73
|
+
: `\n\n${(0, jest_diff_1.diff)(output, content, Object.assign({
|
|
74
|
+
expand: false,
|
|
75
|
+
contextLines: 5,
|
|
76
|
+
aAnnotation: "Snapshot"
|
|
77
|
+
}, options.diff || {}))}`;
|
|
85
78
|
return {
|
|
86
79
|
pass: false,
|
|
87
80
|
message: () => `Received content ${chalk_1.default.red("doesn't match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.${difference}`
|
|
@@ -10,16 +10,16 @@ const serializer = require("jest-serializer-path");
|
|
|
10
10
|
const normalizePaths = serializer.normalizePaths;
|
|
11
11
|
const rspackPath = node_path_1.default.resolve(__dirname, "../../../rspack");
|
|
12
12
|
function replacePaths(input) {
|
|
13
|
+
const paths = input.split("\\\\").join("\\");
|
|
13
14
|
const rspackRoot = normalizePaths(rspackPath);
|
|
14
|
-
input = input.split("\\\\").join("\\");
|
|
15
15
|
if (node_os_1.default.platform() === "win32") {
|
|
16
16
|
const winRspackRoot = rspackRoot.split("\\\\").join(node_path_1.default.win32.sep);
|
|
17
|
-
return normalizePaths(
|
|
17
|
+
return normalizePaths(paths)
|
|
18
18
|
.split(rspackRoot)
|
|
19
19
|
.join("<RSPACK_ROOT>")
|
|
20
20
|
.split(winRspackRoot)
|
|
21
21
|
.join("<RSPACK_ROOT>");
|
|
22
22
|
}
|
|
23
|
-
return normalizePaths(
|
|
23
|
+
return normalizePaths(paths).split(rspackRoot).join("<RSPACK_ROOT>");
|
|
24
24
|
}
|
|
25
25
|
exports.replacePaths = replacePaths;
|
|
@@ -311,20 +311,20 @@ exports.parseResourceWithoutFragment = makeCacheable(_parseResourceWithoutFragme
|
|
|
311
311
|
exports.getUndoPath = (filename, outputPath, enforceRelative) => {
|
|
312
312
|
let depth = -1;
|
|
313
313
|
let append = "";
|
|
314
|
-
|
|
314
|
+
let path = outputPath.replace(/[\\/]$/, "");
|
|
315
315
|
for (const part of filename.split(/[/\\]+/)) {
|
|
316
316
|
if (part === "..") {
|
|
317
317
|
if (depth > -1) {
|
|
318
318
|
depth--;
|
|
319
319
|
}
|
|
320
320
|
else {
|
|
321
|
-
const i =
|
|
322
|
-
const j =
|
|
321
|
+
const i = path.lastIndexOf("/");
|
|
322
|
+
const j = path.lastIndexOf("\\");
|
|
323
323
|
const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
|
|
324
324
|
if (pos < 0)
|
|
325
|
-
return `${
|
|
326
|
-
append = `${
|
|
327
|
-
|
|
325
|
+
return `${path}/`;
|
|
326
|
+
append = `${path.slice(pos + 1)}/${append}`;
|
|
327
|
+
path = path.slice(0, pos);
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
330
|
else if (part !== ".") {
|
|
@@ -13,15 +13,16 @@ const cwdRegExp = new RegExp(`${quoteMeta(CURRENT_CWD)}((?:\\\\)?(?:[a-zA-Z.\\-_
|
|
|
13
13
|
const escapedCwd = JSON.stringify(CURRENT_CWD).slice(1, -1);
|
|
14
14
|
const escapedCwdRegExp = new RegExp(`${quoteMeta(escapedCwd)}((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)`, "g");
|
|
15
15
|
const normalize = (str) => {
|
|
16
|
+
let normalizedStr;
|
|
16
17
|
if (CURRENT_CWD.startsWith("/")) {
|
|
17
|
-
|
|
18
|
+
normalizedStr = str.replace(new RegExp(quoteMeta(CURRENT_CWD), "g"), "<cwd>");
|
|
18
19
|
}
|
|
19
20
|
else {
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
normalizedStr = str.replace(cwdRegExp, (_, g) => `<cwd>${g.replace(/\\/g, "/")}`);
|
|
22
|
+
normalizedStr = normalizedStr.replace(escapedCwdRegExp, (_, g) => `<cwd>${g.replace(/\\\\/g, "/")}`);
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
return
|
|
24
|
+
normalizedStr = normalizedStr.replace(/@@ -\d+,\d+ \+\d+,\d+ @@/g, "@@ ... @@");
|
|
25
|
+
return normalizedStr;
|
|
25
26
|
};
|
|
26
27
|
class Diff {
|
|
27
28
|
constructor(value) {
|
|
@@ -71,12 +72,13 @@ class DefaultsConfigProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
71
72
|
static getDefaultConfig(cwd, config) {
|
|
72
73
|
process.chdir(cwd);
|
|
73
74
|
const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = require("@rspack/core").config;
|
|
74
|
-
|
|
75
|
-
applyWebpackOptionsDefaults(
|
|
75
|
+
const normalizedConfig = getNormalizedWebpackOptions(config);
|
|
76
|
+
applyWebpackOptionsDefaults(normalizedConfig);
|
|
76
77
|
// make snapshot stable
|
|
77
|
-
|
|
78
|
+
normalizedConfig.experiments.rspackFuture.bundlerInfo.version =
|
|
79
|
+
"$version$";
|
|
78
80
|
process.chdir(CURRENT_CWD);
|
|
79
|
-
return
|
|
81
|
+
return normalizedConfig;
|
|
80
82
|
}
|
|
81
83
|
static addSnapshotSerializer(expectImpl) {
|
|
82
84
|
expectImpl.addSnapshotSerializer({
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
2
|
/// <reference types="../jest.d.ts" />
|
|
3
|
-
import type { StatsError
|
|
3
|
+
import type { StatsError } from "@rspack/core";
|
|
4
4
|
import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
|
|
5
5
|
import { SimpleTaskProcessor } from "./simple";
|
|
6
6
|
type TStatsDiagnostics = {
|
|
7
7
|
errors: StatsError[];
|
|
8
|
-
warnings:
|
|
8
|
+
warnings: StatsError[];
|
|
9
9
|
};
|
|
10
10
|
export interface IErrorProcessorOptions<T extends ECompilerType> {
|
|
11
11
|
name: string;
|
package/dist/processor/hook.js
CHANGED
|
@@ -106,14 +106,14 @@ class HookCasesContext extends context_1.TestContext {
|
|
|
106
106
|
* @internal
|
|
107
107
|
*/
|
|
108
108
|
_addSnapshot(content, name, group) {
|
|
109
|
-
|
|
109
|
+
const normalizedContent = Buffer.isBuffer(content)
|
|
110
110
|
? content
|
|
111
111
|
: serialize(content, undefined, {
|
|
112
112
|
escapeString: true,
|
|
113
113
|
printBasicPrototype: true
|
|
114
114
|
}).replace(/\r\n/g, "\n");
|
|
115
115
|
(this.snapshots[group] = this.snapshots[group] || []).push([
|
|
116
|
-
|
|
116
|
+
normalizedContent,
|
|
117
117
|
name
|
|
118
118
|
]);
|
|
119
119
|
if (!this.snapshotsList.includes(group)) {
|
|
@@ -133,11 +133,9 @@ class HookCasesContext extends context_1.TestContext {
|
|
|
133
133
|
const block = this.snapshots[group || index].reduce((acc, [content, name]) => {
|
|
134
134
|
name = `## ${name || `test: ${index}`}\n\n`;
|
|
135
135
|
const block = `\`\`\`javascript\n${content}\n\`\`\`\n`;
|
|
136
|
-
return
|
|
136
|
+
return `${acc}${name + block}\n`;
|
|
137
137
|
}, "");
|
|
138
|
-
|
|
139
|
-
group = `# ${group}\n\n`;
|
|
140
|
-
return (acc += group + block);
|
|
138
|
+
return `${acc}# ${Number.isInteger(group) ? `Group: ${index}` : group}\n\n${block}`;
|
|
141
139
|
}, "");
|
|
142
140
|
env
|
|
143
141
|
.expect(snapshots)
|
|
@@ -134,21 +134,19 @@ class HotSnapshotProcessor extends hot_1.HotProcessor {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
const replaceContent = (str) => {
|
|
137
|
-
|
|
138
|
-
str
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return (0, helper_1.replacePaths)(str);
|
|
137
|
+
return (0, helper_1.replacePaths)(Object.entries(hashes)
|
|
138
|
+
.reduce((str, [raw, replacement]) => {
|
|
139
|
+
return str.split(raw).join(replacement);
|
|
140
|
+
}, str)
|
|
141
|
+
.replace(/\/\/ (\d+)\s+(?=var cssReload)/, ""));
|
|
143
142
|
};
|
|
144
143
|
const replaceFileName = (str) => {
|
|
145
|
-
|
|
144
|
+
return Object.entries({
|
|
146
145
|
...hashes,
|
|
147
146
|
...runtimes
|
|
148
|
-
})) {
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
return str;
|
|
147
|
+
}).reduce((str, [raw, replacement]) => {
|
|
148
|
+
return str.split(raw).join(replacement);
|
|
149
|
+
}, str);
|
|
152
150
|
};
|
|
153
151
|
const fileList = stats
|
|
154
152
|
.assets.map(i => {
|
package/dist/runner/hot-step.js
CHANGED
|
@@ -58,11 +58,11 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
|
|
|
58
58
|
testConfig: {
|
|
59
59
|
...testConfig,
|
|
60
60
|
moduleScope(ms, stats) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return
|
|
61
|
+
const moduleScope = typeof testConfig.moduleScope === "function"
|
|
62
|
+
? testConfig.moduleScope(ms, stats)
|
|
63
|
+
: ms;
|
|
64
|
+
moduleScope.NEXT = next;
|
|
65
|
+
return moduleScope;
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
source,
|
package/dist/runner/hot.js
CHANGED
|
@@ -49,11 +49,11 @@ class HotRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
49
49
|
testConfig: {
|
|
50
50
|
...testConfig,
|
|
51
51
|
moduleScope(ms, stats) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return
|
|
52
|
+
const moduleScope = typeof testConfig.moduleScope === "function"
|
|
53
|
+
? testConfig.moduleScope(ms, stats)
|
|
54
|
+
: ms;
|
|
55
|
+
moduleScope.NEXT = next;
|
|
56
|
+
return moduleScope;
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
source,
|
|
@@ -38,9 +38,7 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
|
|
|
38
38
|
globalContext.document = this.document;
|
|
39
39
|
globalContext.getComputedStyle = this.document.getComputedStyle.bind(this.document);
|
|
40
40
|
const urlToPath = (url) => {
|
|
41
|
-
|
|
42
|
-
url = url.slice(24);
|
|
43
|
-
return node_path_1.default.resolve(this._options.dist, `./${url}`);
|
|
41
|
+
return node_path_1.default.resolve(this._options.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`);
|
|
44
42
|
};
|
|
45
43
|
globalContext.fetch = async (url) => {
|
|
46
44
|
try {
|
|
@@ -70,9 +70,9 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
|
|
|
70
70
|
}
|
|
71
71
|
createResourceLoader() {
|
|
72
72
|
const urlToPath = (url) => {
|
|
73
|
-
|
|
74
|
-
url
|
|
75
|
-
|
|
73
|
+
return node_path_1.default
|
|
74
|
+
.resolve(this._webOptions.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`)
|
|
75
|
+
.split("?")[0];
|
|
76
76
|
};
|
|
77
77
|
class CustomResourceLoader extends jsdom_1.ResourceLoader {
|
|
78
78
|
fetch(url, _) {
|
|
@@ -97,9 +97,7 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
|
|
|
97
97
|
outputDirectory: this._options.dist
|
|
98
98
|
});
|
|
99
99
|
const urlToPath = (url) => {
|
|
100
|
-
|
|
101
|
-
url = url.slice(24);
|
|
102
|
-
return node_path_1.default.resolve(this._webOptions.dist, `./${url}`);
|
|
100
|
+
return node_path_1.default.resolve(this._webOptions.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`);
|
|
103
101
|
};
|
|
104
102
|
moduleScope.fetch = async (url) => {
|
|
105
103
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -93,14 +93,15 @@
|
|
|
93
93
|
"react": "^18.2.0",
|
|
94
94
|
"react-dom": "^18.2.0",
|
|
95
95
|
"react-refresh": "^0.14.0",
|
|
96
|
-
"sass-
|
|
96
|
+
"sass-embedded": "^1.77.8",
|
|
97
|
+
"sass-loader": "^16.0.0",
|
|
97
98
|
"style-loader": "^3.3.3",
|
|
98
99
|
"source-map-loader": "^5.0.0",
|
|
99
100
|
"terser": "5.27.2",
|
|
100
101
|
"typescript": "5.0.2",
|
|
101
102
|
"wast-loader": "^1.12.1",
|
|
102
|
-
"@rspack/
|
|
103
|
-
"@rspack/
|
|
103
|
+
"@rspack/cli": "1.0.0-beta.3",
|
|
104
|
+
"@rspack/core": "1.0.0-beta.3"
|
|
104
105
|
},
|
|
105
106
|
"peerDependencies": {
|
|
106
107
|
"@rspack/core": ">=0.7.0"
|