@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.
Files changed (72) hide show
  1. package/dist/case/builtin.js +1 -2
  2. package/dist/case/compiler.js +1 -2
  3. package/dist/case/config.js +1 -2
  4. package/dist/case/defaults.js +1 -2
  5. package/dist/case/diagnostic.js +1 -2
  6. package/dist/case/diff.js +1 -2
  7. package/dist/case/error.js +1 -3
  8. package/dist/case/hash.js +1 -2
  9. package/dist/case/hook.js +1 -2
  10. package/dist/case/hot-step.js +1 -2
  11. package/dist/case/hot.js +1 -2
  12. package/dist/case/new-incremental.js +3 -12
  13. package/dist/case/normal.js +2 -3
  14. package/dist/case/stats-api.js +1 -3
  15. package/dist/case/stats-output.js +1 -2
  16. package/dist/case/treeshaking.js +1 -2
  17. package/dist/case/watch.js +1 -2
  18. package/dist/compare/compare.js +3 -4
  19. package/dist/compare/format-code.js +1 -2
  20. package/dist/compare/replace-module-argument.js +1 -2
  21. package/dist/compare/replace-runtime-module-name.js +2 -3
  22. package/dist/compiler.d.ts +0 -1
  23. package/dist/compiler.js +1 -1
  24. package/dist/helper/directory.d.ts +0 -1
  25. package/dist/helper/directory.js +2 -2
  26. package/dist/helper/expect/char.d.ts +4 -0
  27. package/dist/helper/expect/char.js +25 -0
  28. package/dist/helper/expect/diff.d.ts +3 -0
  29. package/dist/helper/expect/diff.js +21 -0
  30. package/dist/helper/expect/error.d.ts +5 -0
  31. package/dist/helper/expect/error.js +51 -0
  32. package/dist/helper/expect/placeholder.d.ts +1 -0
  33. package/dist/helper/expect/placeholder.js +34 -0
  34. package/dist/helper/expect/rspack.d.ts +3 -0
  35. package/dist/helper/expect/rspack.js +14 -0
  36. package/dist/helper/expect/to-be-typeof.js +1 -2
  37. package/dist/helper/expect/to-end-with.js +1 -2
  38. package/dist/helper/expect/to-match-file-snapshot.d.ts +0 -1
  39. package/dist/helper/expect/to-match-file-snapshot.js +1 -2
  40. package/dist/helper/legacy/EventSourceForNode.d.ts +2 -3
  41. package/dist/helper/legacy/FakeDocument.d.ts +2 -2
  42. package/dist/helper/legacy/asModule.d.ts +0 -1
  43. package/dist/helper/legacy/createFakeWorker.d.ts +0 -1
  44. package/dist/helper/legacy/fakeSystem.d.ts +3 -3
  45. package/dist/helper/legacy/walkCssTokens.d.ts +5 -3
  46. package/dist/helper/parse-modules.js +1 -2
  47. package/dist/helper/read-config-file.js +1 -2
  48. package/dist/helper/replace-paths.js +1 -2
  49. package/dist/helper/setup-env.d.ts +1 -0
  50. package/dist/helper/setup-env.js +1 -0
  51. package/dist/helper/setup-expect.js +58 -1
  52. package/dist/helper/update-snapshot.js +1 -2
  53. package/dist/helper/util/checkSourceMap.js +1 -1
  54. package/dist/helper/util/filterUtil.d.ts +4 -4
  55. package/dist/helper/util/identifier.d.ts +9 -9
  56. package/dist/helper/win.js +2 -3
  57. package/dist/processor/defaults.d.ts +2 -5
  58. package/dist/processor/defaults.js +2 -36
  59. package/dist/processor/error.d.ts +4 -6
  60. package/dist/processor/error.js +5 -66
  61. package/dist/processor/hook.d.ts +0 -1
  62. package/dist/processor/hot-new-incremental.js +1 -9
  63. package/dist/processor/stats-api.d.ts +0 -3
  64. package/dist/processor/stats-api.js +0 -4
  65. package/dist/processor/stats.js +7 -28
  66. package/dist/processor/watch.js +39 -1
  67. package/dist/runner/type.d.ts +0 -2
  68. package/dist/runner/type.js +1 -1
  69. package/dist/test/simple.js +1 -2
  70. package/dist/type.d.ts +0 -3
  71. package/dist/type.js +3 -3
  72. 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(arg: any);
8
- set onmessage(arg: any);
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(arg: any);
40
+ set src(value: any);
41
41
  get src(): any;
42
42
  get children(): any[];
43
- set href(arg: any);
43
+ set href(value: any);
44
44
  get href(): any;
45
45
  }
46
46
  export class FakeSheet {
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  declare function _exports(something: any, context: any, unlinked: any): Promise<vm.Module>;
3
2
  export = _exports;
4
3
  import vm = require("node:vm");
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  declare function _exports(env: any, { outputDirectory }: {
3
2
  outputDirectory: any;
4
3
  }): {
@@ -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 const registry: undefined;
4
- export const _require: undefined;
5
- export const _nextName: string;
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
- export type CssTokenCallbacks = {
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
- export type CharHandler = (arg0: string, arg1: number, arg2: CssTokenCallbacks) => number;
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 = void 0;
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 = void 0;
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 = void 0;
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 {};
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
+ Object.defineProperty(exports, "__esModule", { value: true });
3
4
  if (process.env.ALTERNATIVE_SORT) {
4
5
  const oldSort = Array.prototype.sort;
5
6
  Array.prototype.sort = function (cmp) {
@@ -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 = void 0;
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
- const TODO: string;
3
- const PARTIAL_PASS: string;
4
- const FAILED: string;
5
- const NO_PLAN: string;
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 makePathsAbsolute(context: string, identifier: string, associatedObjectForCache?: Object | undefined): string;
28
- export namespace makePathsAbsolute { }
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 parseResourceWithoutFragment(str: string, associatedObjectForCache?: Object | undefined): ParsedResource;
44
- export namespace parseResourceWithoutFragment { }
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
- export function contextify(context: string, identifier: string, associatedObjectForCache?: Object | undefined): string;
67
- export namespace contextify { }
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
- export function absolutify(context: string, identifier: string, associatedObjectForCache?: Object | undefined): string;
75
- export namespace absolutify { }
76
- import path = require("path");
74
+ declare function makePathsRelative(context: string, identifier: string, associatedObjectForCache?: Object | undefined): string;
75
+ declare namespace makePathsRelative { }
76
+ export { contextify, absolutify };
@@ -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.escapeEOL = exports.escapeSep = void 0;
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 Diff {
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<Diff>, defaults: jest.JestMatchers<TCompilerOptions<T>>) => Promise<void>;
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
- const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
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 Diff(diff)), env.expect(this.defaultConfig));
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
- type TStatsDiagnostics = {
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: TStatsDiagnostics) => Promise<void>;
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 {};
@@ -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
- const CWD_PATTERN = new RegExp(node_path_1.default.join(process.cwd(), "../../").replace(/\\/g, "/"), "gm");
12
- const ERROR_STACK_PATTERN = /(│.* at ).*/g;
13
- function cleanErrorStack(message) {
14
- return message.replace(ERROR_STACK_PATTERN, "$1xxx");
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;
@@ -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;
@@ -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
- const quoteMeta = (str) => {
14
- return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
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
- else {
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());