@rspack/test-tools 1.0.13 → 1.0.14
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.js +1 -2
- package/dist/case/compiler.js +1 -2
- package/dist/case/config.js +1 -2
- package/dist/case/defaults.js +1 -2
- package/dist/case/diagnostic.js +1 -2
- package/dist/case/diff.js +1 -2
- package/dist/case/error.js +1 -3
- package/dist/case/hash.js +1 -2
- package/dist/case/hook.js +1 -2
- package/dist/case/hot-step.js +1 -2
- package/dist/case/hot.js +1 -2
- package/dist/case/new-incremental.js +3 -12
- package/dist/case/normal.js +2 -3
- package/dist/case/stats-api.js +1 -3
- package/dist/case/stats-output.js +1 -2
- package/dist/case/treeshaking.js +1 -2
- package/dist/case/watch.js +1 -2
- package/dist/compare/compare.js +3 -4
- package/dist/compare/format-code.js +1 -2
- package/dist/compare/replace-module-argument.js +1 -2
- package/dist/compare/replace-runtime-module-name.js +2 -3
- package/dist/compiler.d.ts +0 -1
- package/dist/compiler.js +1 -1
- package/dist/helper/directory.d.ts +0 -1
- package/dist/helper/directory.js +2 -2
- package/dist/helper/expect/char.d.ts +4 -0
- package/dist/helper/expect/char.js +25 -0
- package/dist/helper/expect/diff.d.ts +3 -0
- package/dist/helper/expect/diff.js +21 -0
- package/dist/helper/expect/error.d.ts +5 -0
- package/dist/helper/expect/error.js +51 -0
- package/dist/helper/expect/placeholder.d.ts +1 -0
- package/dist/helper/expect/placeholder.js +34 -0
- package/dist/helper/expect/rspack.d.ts +3 -0
- package/dist/helper/expect/rspack.js +14 -0
- package/dist/helper/expect/to-be-typeof.js +1 -2
- package/dist/helper/expect/to-end-with.js +1 -2
- package/dist/helper/expect/to-match-file-snapshot.d.ts +0 -1
- package/dist/helper/expect/to-match-file-snapshot.js +1 -2
- package/dist/helper/legacy/EventSourceForNode.d.ts +2 -3
- package/dist/helper/legacy/FakeDocument.d.ts +2 -2
- package/dist/helper/legacy/asModule.d.ts +0 -1
- package/dist/helper/legacy/createFakeWorker.d.ts +0 -1
- package/dist/helper/legacy/fakeSystem.d.ts +3 -3
- package/dist/helper/legacy/walkCssTokens.d.ts +5 -3
- package/dist/helper/parse-modules.js +1 -2
- package/dist/helper/read-config-file.js +1 -2
- package/dist/helper/replace-paths.js +1 -2
- package/dist/helper/setup-env.d.ts +1 -0
- package/dist/helper/setup-env.js +1 -0
- package/dist/helper/setup-expect.js +58 -1
- package/dist/helper/update-snapshot.js +1 -2
- package/dist/helper/util/checkSourceMap.js +1 -1
- package/dist/helper/util/filterUtil.d.ts +4 -4
- package/dist/helper/util/identifier.d.ts +9 -9
- package/dist/helper/win.js +2 -3
- package/dist/processor/defaults.d.ts +2 -5
- package/dist/processor/defaults.js +2 -36
- package/dist/processor/error.d.ts +4 -6
- package/dist/processor/error.js +5 -66
- package/dist/processor/hook.d.ts +0 -1
- package/dist/processor/hot-new-incremental.js +1 -9
- package/dist/processor/stats-api.d.ts +0 -3
- package/dist/processor/stats-api.js +0 -4
- package/dist/processor/stats.js +7 -28
- package/dist/processor/watch.js +39 -1
- package/dist/runner/type.d.ts +0 -2
- package/dist/runner/type.js +1 -1
- package/dist/test/simple.js +1 -2
- package/dist/type.d.ts +0 -3
- package/dist/type.js +3 -3
- package/package.json +5 -4
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
export = EventSource;
|
|
3
2
|
declare class EventSource {
|
|
4
3
|
constructor(url: any);
|
|
5
4
|
response: import("http").IncomingMessage | undefined;
|
|
6
5
|
close(): void;
|
|
7
|
-
set onopen(
|
|
8
|
-
set onmessage(
|
|
6
|
+
set onopen(value: any);
|
|
7
|
+
set onmessage(value: any);
|
|
9
8
|
}
|
|
@@ -37,10 +37,10 @@ export class FakeElement {
|
|
|
37
37
|
removeAttribute(name: any): void;
|
|
38
38
|
getAttribute(name: any): any;
|
|
39
39
|
_toRealUrl(value: any): any;
|
|
40
|
-
set src(
|
|
40
|
+
set src(value: any);
|
|
41
41
|
get src(): any;
|
|
42
42
|
get children(): any[];
|
|
43
|
-
set href(
|
|
43
|
+
set href(value: any);
|
|
44
44
|
get href(): any;
|
|
45
45
|
}
|
|
46
46
|
export class FakeSheet {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export function register(name: any, deps: any, fn: any): void;
|
|
2
2
|
export function set(name: any, exports: any): void;
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
3
|
+
export let registry: undefined;
|
|
4
|
+
export let _require: undefined;
|
|
5
|
+
export let _nextName: string;
|
|
6
6
|
export function setRequire(req: any): void;
|
|
7
7
|
export function init(modules: any): void;
|
|
8
8
|
export function execute(name: any): any;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
declare namespace _exports {
|
|
2
|
+
export { CssTokenCallbacks, CharHandler };
|
|
3
|
+
}
|
|
1
4
|
declare function _exports(input: string, callbacks: CssTokenCallbacks): void;
|
|
2
5
|
declare namespace _exports {
|
|
3
6
|
export { isIdentStartCodePoint };
|
|
@@ -5,10 +8,9 @@ declare namespace _exports {
|
|
|
5
8
|
export function eatWhitespace(input: string, pos: number): number;
|
|
6
9
|
export function eatWhitespaceAndComments(input: string, pos: number): number;
|
|
7
10
|
export function eatWhiteLine(input: string, pos: number): number;
|
|
8
|
-
export { CssTokenCallbacks, CharHandler };
|
|
9
11
|
}
|
|
10
12
|
export = _exports;
|
|
11
|
-
|
|
13
|
+
type CssTokenCallbacks = {
|
|
12
14
|
isSelector?: ((arg0: string, arg1: number) => boolean) | undefined;
|
|
13
15
|
url?: ((arg0: string, arg1: number, arg2: number, arg3: number, arg4: number) => number) | undefined;
|
|
14
16
|
string?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
|
|
@@ -26,7 +28,7 @@ export type CssTokenCallbacks = {
|
|
|
26
28
|
semicolon?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
|
|
27
29
|
comma?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
|
|
28
30
|
};
|
|
29
|
-
|
|
31
|
+
type CharHandler = (arg0: string, arg1: number, arg2: CssTokenCallbacks) => number;
|
|
30
32
|
/**
|
|
31
33
|
* ident-start code point
|
|
32
34
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseModules =
|
|
3
|
+
exports.parseModules = parseModules;
|
|
4
4
|
const BOOTSTRAP_SPLIT_LINE = "/************************************************************************/";
|
|
5
5
|
const MODULE_START_FLAG = "/* start::";
|
|
6
6
|
const MODULE_END_FLAG = "/* end::";
|
|
@@ -71,4 +71,3 @@ function parseModules(content, options = {}) {
|
|
|
71
71
|
runtimeModules
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
exports.parseModules = parseModules;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readConfigFile =
|
|
6
|
+
exports.readConfigFile = readConfigFile;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
function readConfigFile(files, functionApply) {
|
|
9
9
|
const existsFile = files.find(i => fs_extra_1.default.existsSync(i));
|
|
@@ -11,4 +11,3 @@ function readConfigFile(files, functionApply) {
|
|
|
11
11
|
const configArr = Array.isArray(fileConfig) ? fileConfig : [fileConfig];
|
|
12
12
|
return functionApply ? functionApply(configArr) : configArr;
|
|
13
13
|
}
|
|
14
|
-
exports.readConfigFile = readConfigFile;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.replacePaths =
|
|
6
|
+
exports.replacePaths = replacePaths;
|
|
7
7
|
const node_os_1 = __importDefault(require("node:os"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const serializer = require("jest-serializer-path");
|
|
@@ -22,4 +22,3 @@ function replacePaths(input) {
|
|
|
22
22
|
}
|
|
23
23
|
return normalizePaths(paths).split(rspackRoot).join("<RSPACK_ROOT>");
|
|
24
24
|
}
|
|
25
|
-
exports.replacePaths = replacePaths;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/helper/setup-env.js
CHANGED
|
@@ -1,12 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// @ts-nocheck
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const char_1 = require("./expect/char");
|
|
4
|
+
const diff_1 = require("./expect/diff");
|
|
5
|
+
const error_1 = require("./expect/error");
|
|
6
|
+
const placeholder_1 = require("./expect/placeholder");
|
|
7
|
+
const rspack_1 = require("./expect/rspack");
|
|
4
8
|
const to_be_typeof_1 = require("./expect/to-be-typeof");
|
|
5
9
|
const to_end_with_1 = require("./expect/to-end-with");
|
|
6
10
|
const to_match_file_snapshot_1 = require("./expect/to-match-file-snapshot");
|
|
11
|
+
const { normalizePaths } = require("jest-serializer-path");
|
|
7
12
|
expect.extend({
|
|
8
13
|
// CHANGE: new test matcher for `rspack-test-tools`
|
|
14
|
+
// @ts-ignore
|
|
9
15
|
toMatchFileSnapshot: to_match_file_snapshot_1.toMatchFileSnapshot,
|
|
10
16
|
toBeTypeOf: to_be_typeof_1.toBeTypeOf,
|
|
11
17
|
toEndWith: to_end_with_1.toEndWith
|
|
12
18
|
});
|
|
19
|
+
const pipes = [
|
|
20
|
+
char_1.normalizeSlash,
|
|
21
|
+
char_1.normalizeCLR,
|
|
22
|
+
char_1.normalizeCRLF,
|
|
23
|
+
placeholder_1.normalizePlaceholder,
|
|
24
|
+
normalizePaths
|
|
25
|
+
];
|
|
26
|
+
const serialize = (str, extra = []) => [...pipes, ...extra].reduce((res, transform) => transform(res), str);
|
|
27
|
+
expect.addSnapshotSerializer({
|
|
28
|
+
test(received) {
|
|
29
|
+
return typeof received === "string";
|
|
30
|
+
},
|
|
31
|
+
print(received) {
|
|
32
|
+
return serialize(received.trim());
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
// for diff
|
|
36
|
+
expect.addSnapshotSerializer({
|
|
37
|
+
test(received) {
|
|
38
|
+
return received?.constructor?.name === "RspackTestDiff";
|
|
39
|
+
},
|
|
40
|
+
print(received, next) {
|
|
41
|
+
return next((0, diff_1.normalizeDiff)(received));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
// for errors
|
|
45
|
+
expect.addSnapshotSerializer({
|
|
46
|
+
test(received) {
|
|
47
|
+
return received?.constructor?.name === "RspackStatsDiagnostics";
|
|
48
|
+
},
|
|
49
|
+
print(received, next) {
|
|
50
|
+
return next((0, error_1.normalizeDignostics)(received));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
expect.addSnapshotSerializer({
|
|
54
|
+
test(received) {
|
|
55
|
+
return typeof received?.message === "string";
|
|
56
|
+
},
|
|
57
|
+
print(received, next) {
|
|
58
|
+
return next((0, error_1.normalizeError)(received));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
// for stats
|
|
62
|
+
expect.addSnapshotSerializer({
|
|
63
|
+
test(received) {
|
|
64
|
+
return received?.constructor?.name === "RspackStats";
|
|
65
|
+
},
|
|
66
|
+
print(received, next) {
|
|
67
|
+
return next((0, rspack_1.normalizeStats)(received));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUpdateSnapshot =
|
|
3
|
+
exports.isUpdateSnapshot = isUpdateSnapshot;
|
|
4
4
|
function isUpdateSnapshot() {
|
|
5
5
|
return global.updateSnapshot || process.env.UPDATE_SNAPSHOT === "true";
|
|
6
6
|
}
|
|
7
|
-
exports.isUpdateSnapshot = isUpdateSnapshot;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = checkSourceMap;
|
|
3
4
|
// @ts-nocheck
|
|
4
5
|
// Check the mapping of various key locations back to the original source
|
|
5
6
|
async function checkSourceMap(out, outCodeMap, toSearch, _checkColumn = true // passing `false` indicating it's an `OriginalSource`.
|
|
@@ -93,4 +94,3 @@ async function checkSourceMap(out, outCodeMap, toSearch, _checkColumn = true //
|
|
|
93
94
|
}
|
|
94
95
|
return !failed;
|
|
95
96
|
}
|
|
96
|
-
exports.default = checkSourceMap;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export namespace FilteredStatus {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
let TODO: string;
|
|
3
|
+
let PARTIAL_PASS: string;
|
|
4
|
+
let FAILED: string;
|
|
5
|
+
let NO_PLAN: string;
|
|
6
6
|
}
|
|
7
7
|
export function decodeFilteredTest(encoded: any): any;
|
|
8
8
|
export function normalizeFilteredTestName(flag: any, testName: any): string;
|
|
@@ -24,8 +24,8 @@ export namespace makePathsRelative {
|
|
|
24
24
|
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
|
|
25
25
|
* @returns {string} the returned relative path
|
|
26
26
|
*/
|
|
27
|
-
export function
|
|
28
|
-
export namespace
|
|
27
|
+
export function makePathsRelative(context: string, identifier: string, associatedObjectForCache?: Object | undefined): string;
|
|
28
|
+
export namespace makePathsRelative { }
|
|
29
29
|
/**
|
|
30
30
|
* @param {string} str the path with query and fragment
|
|
31
31
|
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
|
|
@@ -40,8 +40,8 @@ export namespace parseResource {
|
|
|
40
40
|
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
|
|
41
41
|
* @returns {ParsedResource} parsed parts
|
|
42
42
|
*/
|
|
43
|
-
export function
|
|
44
|
-
export namespace
|
|
43
|
+
export function parseResource(str: string, associatedObjectForCache?: Object | undefined): ParsedResource;
|
|
44
|
+
export namespace parseResource { }
|
|
45
45
|
export function getUndoPath(filename: string, outputPath: string, enforceRelative: boolean): string;
|
|
46
46
|
export type MakeRelativePathsCache = {
|
|
47
47
|
relativePaths?: Map<string, Map<string, string>> | undefined;
|
|
@@ -63,14 +63,14 @@ export type ParsedResourceWithoutFragment = {
|
|
|
63
63
|
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
|
|
64
64
|
* @returns {string} the returned relative path
|
|
65
65
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
declare function makePathsRelative(context: string, identifier: string, associatedObjectForCache?: Object | undefined): string;
|
|
67
|
+
declare namespace makePathsRelative { }
|
|
68
68
|
/**
|
|
69
69
|
* @param {string} context context used to create relative path
|
|
70
70
|
* @param {string} identifier identifier used to create relative path
|
|
71
71
|
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
|
|
72
72
|
* @returns {string} the returned relative path
|
|
73
73
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
declare function makePathsRelative(context: string, identifier: string, associatedObjectForCache?: Object | undefined): string;
|
|
75
|
+
declare namespace makePathsRelative { }
|
|
76
|
+
export { contextify, absolutify };
|
package/dist/helper/win.js
CHANGED
|
@@ -3,13 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.escapeSep = escapeSep;
|
|
7
|
+
exports.escapeEOL = escapeEOL;
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
function escapeSep(str) {
|
|
9
10
|
return str.split(node_path_1.default.win32.sep).join(node_path_1.default.posix.sep);
|
|
10
11
|
}
|
|
11
|
-
exports.escapeSep = escapeSep;
|
|
12
12
|
function escapeEOL(str) {
|
|
13
13
|
return str.split("\r\n").join("\n").trim();
|
|
14
14
|
}
|
|
15
|
-
exports.escapeEOL = escapeEOL;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
|
-
/// <reference types="../jest.d.ts" />
|
|
3
1
|
import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
|
|
4
2
|
import { SimpleTaskProcessor } from "./simple";
|
|
5
|
-
declare class
|
|
3
|
+
declare class RspackTestDiff {
|
|
6
4
|
value: string;
|
|
7
5
|
constructor(value: string);
|
|
8
6
|
}
|
|
@@ -10,7 +8,7 @@ export interface IDefaultsConfigProcessorOptions<T extends ECompilerType> {
|
|
|
10
8
|
options?: (context: ITestContext) => TCompilerOptions<T>;
|
|
11
9
|
cwd?: string;
|
|
12
10
|
name: string;
|
|
13
|
-
diff: (diff: jest.JestMatchers<
|
|
11
|
+
diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<TCompilerOptions<T>>) => Promise<void>;
|
|
14
12
|
compilerType: T;
|
|
15
13
|
}
|
|
16
14
|
export declare class DefaultsConfigProcessor<T extends ECompilerType> extends SimpleTaskProcessor<T> {
|
|
@@ -27,6 +25,5 @@ export declare class DefaultsConfigProcessor<T extends ECompilerType> extends Si
|
|
|
27
25
|
afterAll(context: ITestContext): Promise<void>;
|
|
28
26
|
protected getCompiler(context: ITestContext): import("../type").ITestCompilerManager<T>;
|
|
29
27
|
static getDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
|
|
30
|
-
static addSnapshotSerializer(expectImpl: jest.Expect): void;
|
|
31
28
|
}
|
|
32
29
|
export {};
|
|
@@ -8,23 +8,7 @@ const jest_diff_1 = require("jest-diff");
|
|
|
8
8
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
9
9
|
const simple_1 = require("./simple");
|
|
10
10
|
const CURRENT_CWD = process.cwd();
|
|
11
|
-
|
|
12
|
-
const cwdRegExp = new RegExp(`${quoteMeta(CURRENT_CWD)}((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)`, "g");
|
|
13
|
-
const escapedCwd = JSON.stringify(CURRENT_CWD).slice(1, -1);
|
|
14
|
-
const escapedCwdRegExp = new RegExp(`${quoteMeta(escapedCwd)}((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)`, "g");
|
|
15
|
-
const normalize = (str) => {
|
|
16
|
-
let normalizedStr;
|
|
17
|
-
if (CURRENT_CWD.startsWith("/")) {
|
|
18
|
-
normalizedStr = str.replace(new RegExp(quoteMeta(CURRENT_CWD), "g"), "<cwd>");
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
normalizedStr = str.replace(cwdRegExp, (_, g) => `<cwd>${g.replace(/\\/g, "/")}`);
|
|
22
|
-
normalizedStr = normalizedStr.replace(escapedCwdRegExp, (_, g) => `<cwd>${g.replace(/\\\\/g, "/")}`);
|
|
23
|
-
}
|
|
24
|
-
normalizedStr = normalizedStr.replace(/@@ -\d+,\d+ \+\d+,\d+ @@/g, "@@ ... @@");
|
|
25
|
-
return normalizedStr;
|
|
26
|
-
};
|
|
27
|
-
class Diff {
|
|
11
|
+
class RspackTestDiff {
|
|
28
12
|
constructor(value) {
|
|
29
13
|
this.value = value;
|
|
30
14
|
}
|
|
@@ -60,7 +44,7 @@ class DefaultsConfigProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
60
44
|
const compiler = this.getCompiler(context);
|
|
61
45
|
const config = DefaultsConfigProcessor.getDefaultConfig(this._defaultsConfigOptions.cwd || CURRENT_CWD, compiler.getOptions());
|
|
62
46
|
const diff = (0, strip_ansi_1.default)((0, jest_diff_1.diff)(this.defaultConfig, config, { expand: false, contextLines: 0 }));
|
|
63
|
-
await this._defaultsConfigOptions.diff(env.expect(new
|
|
47
|
+
await this._defaultsConfigOptions.diff(env.expect(new RspackTestDiff(diff)), env.expect(this.defaultConfig));
|
|
64
48
|
}
|
|
65
49
|
async before(context) { }
|
|
66
50
|
async after(context) { }
|
|
@@ -80,23 +64,5 @@ class DefaultsConfigProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
80
64
|
process.chdir(CURRENT_CWD);
|
|
81
65
|
return normalizedConfig;
|
|
82
66
|
}
|
|
83
|
-
static addSnapshotSerializer(expectImpl) {
|
|
84
|
-
expectImpl.addSnapshotSerializer({
|
|
85
|
-
test(value) {
|
|
86
|
-
return value instanceof Diff;
|
|
87
|
-
},
|
|
88
|
-
print(received) {
|
|
89
|
-
return normalize(received.value);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
expectImpl.addSnapshotSerializer({
|
|
93
|
-
test(value) {
|
|
94
|
-
return typeof value === "string";
|
|
95
|
-
},
|
|
96
|
-
print(received) {
|
|
97
|
-
return JSON.stringify(normalize(received));
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
67
|
}
|
|
102
68
|
exports.DefaultsConfigProcessor = DefaultsConfigProcessor;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
|
-
/// <reference types="../jest.d.ts" />
|
|
3
1
|
import type { StatsError } from "@rspack/core";
|
|
4
2
|
import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
|
|
5
3
|
import { SimpleTaskProcessor } from "./simple";
|
|
6
|
-
|
|
4
|
+
declare class RspackStatsDiagnostics {
|
|
7
5
|
errors: StatsError[];
|
|
8
6
|
warnings: StatsError[];
|
|
9
|
-
|
|
7
|
+
constructor(errors: StatsError[], warnings: StatsError[]);
|
|
8
|
+
}
|
|
10
9
|
export interface IErrorProcessorOptions<T extends ECompilerType> {
|
|
11
10
|
name: string;
|
|
12
11
|
compilerType: T;
|
|
13
12
|
options?: (options: TCompilerOptions<T>, context: ITestContext) => TCompilerOptions<T>;
|
|
14
13
|
build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
15
|
-
check?: (stats:
|
|
14
|
+
check?: (stats: RspackStatsDiagnostics) => Promise<void>;
|
|
16
15
|
}
|
|
17
16
|
export declare class ErrorProcessor<T extends ECompilerType> extends SimpleTaskProcessor<T> {
|
|
18
17
|
protected _errorOptions: IErrorProcessorOptions<T>;
|
|
@@ -20,6 +19,5 @@ export declare class ErrorProcessor<T extends ECompilerType> extends SimpleTaskP
|
|
|
20
19
|
compiler(context: ITestContext): Promise<void>;
|
|
21
20
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
22
21
|
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
23
|
-
static addSnapshotSerializer(expectImpl: jest.Expect): void;
|
|
24
22
|
}
|
|
25
23
|
export {};
|
package/dist/processor/error.js
CHANGED
|
@@ -5,51 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ErrorProcessor = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const pretty_format_1 = __importDefault(require("pretty-format"));
|
|
9
8
|
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
10
9
|
const simple_1 = require("./simple");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
function cleanError(err) {
|
|
17
|
-
const result = {};
|
|
18
|
-
for (const key of Object.getOwnPropertyNames(err)) {
|
|
19
|
-
result[key] = err[key];
|
|
20
|
-
}
|
|
21
|
-
if (result.message) {
|
|
22
|
-
result.message = cleanErrorStack(err.message);
|
|
10
|
+
class RspackStatsDiagnostics {
|
|
11
|
+
constructor(errors, warnings) {
|
|
12
|
+
this.errors = errors;
|
|
13
|
+
this.warnings = warnings;
|
|
23
14
|
}
|
|
24
|
-
if (result.stack) {
|
|
25
|
-
result.stack = cleanErrorStack(result.stack);
|
|
26
|
-
}
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
function serialize(received) {
|
|
30
|
-
return ((0, pretty_format_1.default)(received, prettyFormatOptions)
|
|
31
|
-
.replace(CWD_PATTERN, "<cwd>")
|
|
32
|
-
// replace line numbers in error stacks
|
|
33
|
-
.replace(/:\d+:\d+/g, ":<line>:<col>")
|
|
34
|
-
.trim());
|
|
35
15
|
}
|
|
36
|
-
const prettyFormatOptions = {
|
|
37
|
-
escapeRegex: false,
|
|
38
|
-
printFunctionName: false,
|
|
39
|
-
plugins: [
|
|
40
|
-
{
|
|
41
|
-
test(val) {
|
|
42
|
-
return typeof val === "string";
|
|
43
|
-
},
|
|
44
|
-
print(val) {
|
|
45
|
-
return `"${val
|
|
46
|
-
.replace(/\\/gm, "/")
|
|
47
|
-
.replace(/"/gm, '\\"')
|
|
48
|
-
.replace(/\r?\n/gm, "\\n")}"`;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
};
|
|
53
16
|
class ErrorProcessor extends simple_1.SimpleTaskProcessor {
|
|
54
17
|
constructor(_errorOptions) {
|
|
55
18
|
super({
|
|
@@ -126,31 +89,7 @@ class ErrorProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
126
89
|
const { errors, warnings } = statsResult;
|
|
127
90
|
env.expect(Array.isArray(errors)).toBe(true);
|
|
128
91
|
env.expect(Array.isArray(warnings)).toBe(true);
|
|
129
|
-
await this._errorOptions.check?.(
|
|
130
|
-
errors: errors,
|
|
131
|
-
warnings: warnings
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
static addSnapshotSerializer(expectImpl) {
|
|
135
|
-
expectImpl.addSnapshotSerializer({
|
|
136
|
-
test(received) {
|
|
137
|
-
return received.errors || received.warnings;
|
|
138
|
-
},
|
|
139
|
-
print(received) {
|
|
140
|
-
return serialize({
|
|
141
|
-
errors: received.errors.map(e => cleanError(e)),
|
|
142
|
-
warnings: received.warnings.map(e => cleanError(e))
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
expectImpl.addSnapshotSerializer({
|
|
147
|
-
test(received) {
|
|
148
|
-
return received.message;
|
|
149
|
-
},
|
|
150
|
-
print(received) {
|
|
151
|
-
return serialize(cleanError(received));
|
|
152
|
-
}
|
|
153
|
-
});
|
|
92
|
+
await this._errorOptions.check?.(new RspackStatsDiagnostics(errors, warnings));
|
|
154
93
|
}
|
|
155
94
|
}
|
|
156
95
|
exports.ErrorProcessor = ErrorProcessor;
|
package/dist/processor/hook.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { type TTestContextOptions, TestContext } from "../test/context";
|
|
3
2
|
import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
|
|
4
3
|
import { type ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";
|
|
@@ -29,15 +29,7 @@ class HotNewIncrementalProcessor extends hot_1.HotProcessor {
|
|
|
29
29
|
if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
|
|
30
30
|
const rspackOptions = options;
|
|
31
31
|
rspackOptions.experiments ??= {};
|
|
32
|
-
rspackOptions.experiments.incremental ??=
|
|
33
|
-
make: true,
|
|
34
|
-
emitAssets: true,
|
|
35
|
-
inferAsyncModules: true,
|
|
36
|
-
providedExports: true,
|
|
37
|
-
moduleHashes: true,
|
|
38
|
-
moduleCodegen: true,
|
|
39
|
-
moduleRuntimeRequirements: true
|
|
40
|
-
};
|
|
32
|
+
rspackOptions.experiments.incremental ??= true;
|
|
41
33
|
}
|
|
42
34
|
else {
|
|
43
35
|
throw new Error("HotNewIncrementalProcessor should only used for Rspack.");
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
|
-
/// <reference types="../jest.d.ts" />
|
|
3
1
|
import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
|
|
4
2
|
import { SimpleTaskProcessor } from "./simple";
|
|
5
3
|
export interface IStatsAPIProcessorOptions<T extends ECompilerType> {
|
|
@@ -16,5 +14,4 @@ export declare class StatsAPIProcessor<T extends ECompilerType> extends SimpleTa
|
|
|
16
14
|
compiler(context: ITestContext): Promise<void>;
|
|
17
15
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
18
16
|
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
19
|
-
static addSnapshotSerializer(expectImpl: jest.Expect): void;
|
|
20
17
|
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.StatsAPIProcessor = void 0;
|
|
4
4
|
const memfs_1 = require("memfs");
|
|
5
5
|
const simple_1 = require("./simple");
|
|
6
|
-
const serializer = require("jest-serializer-path");
|
|
7
6
|
class StatsAPIProcessor extends simple_1.SimpleTaskProcessor {
|
|
8
7
|
constructor(_statsAPIOptions) {
|
|
9
8
|
super({
|
|
@@ -40,8 +39,5 @@ class StatsAPIProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
40
39
|
env.expect(typeof stats).toBe("object");
|
|
41
40
|
await this._statsAPIOptions.check?.(stats, compiler.getCompiler());
|
|
42
41
|
}
|
|
43
|
-
static addSnapshotSerializer(expectImpl) {
|
|
44
|
-
expectImpl.addSnapshotSerializer(serializer);
|
|
45
|
-
}
|
|
46
42
|
}
|
|
47
43
|
exports.StatsAPIProcessor = StatsAPIProcessor;
|
package/dist/processor/stats.js
CHANGED
|
@@ -10,9 +10,11 @@ const helper_1 = require("../helper");
|
|
|
10
10
|
const captureStdio_1 = __importDefault(require("../helper/legacy/captureStdio"));
|
|
11
11
|
const multi_1 = require("./multi");
|
|
12
12
|
const REG_ERROR_CASE = /error$/;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
class RspackStats {
|
|
14
|
+
constructor(value) {
|
|
15
|
+
this.value = value;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
16
18
|
class StatsProcessor extends multi_1.MultiTaskProcessor {
|
|
17
19
|
constructor(_statsOptions) {
|
|
18
20
|
super({
|
|
@@ -124,37 +126,14 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
|
|
|
124
126
|
}
|
|
125
127
|
let actual = stats.toString(toStringOptions);
|
|
126
128
|
env.expect(typeof actual).toBe("string");
|
|
129
|
+
actual = this.stderr.toString() + actual;
|
|
127
130
|
if (!hasColorSetting) {
|
|
128
|
-
actual = this.stderr.toString() + actual;
|
|
129
131
|
actual = actual
|
|
130
132
|
.replace(/\u001b\[[0-9;]*m/g, "")
|
|
131
133
|
// CHANGE: The time unit display in Rspack is second
|
|
132
134
|
.replace(/[.0-9]+(\s?s)/g, "X$1");
|
|
133
135
|
}
|
|
134
|
-
|
|
135
|
-
actual = this.stderr.toStringRaw() + actual;
|
|
136
|
-
// eslint-disable-no-control-regex
|
|
137
|
-
actual = actual
|
|
138
|
-
.replace(/\u001b\[1m\u001b\[([0-9;]*)m/g, "<CLR=$1,BOLD>")
|
|
139
|
-
.replace(/\u001b\[1m/g, "<CLR=BOLD>")
|
|
140
|
-
.replace(/\u001b\[39m\u001b\[22m/g, "</CLR>")
|
|
141
|
-
.replace(/\u001b\[([0-9;]*)m/g, "<CLR=$1>")
|
|
142
|
-
// CHANGE: The time unit display in Rspack is second
|
|
143
|
-
.replace(/[.0-9]+(<\/CLR>)?(\s?s)/g, "X$1$2");
|
|
144
|
-
}
|
|
145
|
-
// cspell:ignore Xdir
|
|
146
|
-
const testPath = context.getSource();
|
|
147
|
-
actual = actual
|
|
148
|
-
.replace(/\r\n?/g, "\n")
|
|
149
|
-
// CHANGE: Remove potential line break and "|" caused by long text
|
|
150
|
-
.replace(/((ERROR|WARNING)([\s\S](?!╭|├))*?)(\n {2}│ )/g, "$1")
|
|
151
|
-
// CHANGE: Update the regular expression to replace the 'Rspack' version string
|
|
152
|
-
.replace(/Rspack [^ )]+(\)?) compiled/g, "Rspack x.x.x$1 compiled")
|
|
153
|
-
.replace(new RegExp(quoteMeta(testPath), "g"), `Xdir/${node_path_1.default.basename(this._options.name)}`)
|
|
154
|
-
.replace(/(\w)\\(\w)/g, "$1/$2")
|
|
155
|
-
.replace(/, additional resolving: X ms/g, "")
|
|
156
|
-
.replace(/Unexpected identifier '.+?'/g, "Unexpected identifier");
|
|
157
|
-
env.expect(actual).toMatchSnapshot();
|
|
136
|
+
env.expect(new RspackStats(actual)).toMatchSnapshot();
|
|
158
137
|
const testConfig = context.getTestConfig();
|
|
159
138
|
if (typeof testConfig?.validate === "function") {
|
|
160
139
|
testConfig.validate(stats, this.stderr.toString());
|