@rspack/test-tools 1.3.12 → 1.3.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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <picture>
2
- <img alt="Rspack Banner" src="https://assets.rspack.dev/rspack/rspack-banner.png">
2
+ <img alt="Rspack Banner" src="https://assets.rspack.rs/rspack/rspack-banner.png">
3
3
  </picture>
4
4
 
5
5
  # @rspack/test-tools
@@ -10,7 +10,7 @@ Test tools for rspack.
10
10
 
11
11
  ## Documentation
12
12
 
13
- See [https://rspack.dev](https://rspack.dev) for details.
13
+ See [https://rspack.rs](https://rspack.rs) for details.
14
14
 
15
15
  ## License
16
16
 
@@ -11,6 +11,8 @@ const creator = new creator_1.BasicCaseCreator({
11
11
  new processor_1.DiagnosticProcessor({
12
12
  name,
13
13
  snapshot: "./stats.err",
14
+ snapshotErrors: "./raw-error.err",
15
+ snapshotWarning: "./raw-warning.err",
14
16
  configFiles: ["rspack.config.js", "webpack.config.js"],
15
17
  compilerType: type_1.ECompilerType.Rspack,
16
18
  format: (output) => {
@@ -1,5 +1,5 @@
1
- import { ECompilerType, type EDocumentType, type TCompilerOptions } from "../type";
2
- export declare function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], documentType: EDocumentType): void;
1
+ import { ECompilerType, type TCompilerOptions } from "../type";
2
+ export declare function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
3
3
  export type WatchNewIncrementalOptions = {
4
4
  ignoreNotFriendlyForIncrementalWarnings?: boolean;
5
5
  };
@@ -13,8 +13,8 @@ const runner_1 = require("../runner");
13
13
  const creator_1 = require("../test/creator");
14
14
  const type_1 = require("../type");
15
15
  const hotCreators = new Map();
16
- function getHotCreator(target, documentType) {
17
- const key = JSON.stringify({ target, documentType });
16
+ function getHotCreator(target, webpackCases) {
17
+ const key = JSON.stringify({ target, webpackCases });
18
18
  if (!hotCreators.has(key)) {
19
19
  hotCreators.set(key, new creator_1.BasicCaseCreator({
20
20
  clean: true,
@@ -26,7 +26,7 @@ function getHotCreator(target, documentType) {
26
26
  target: target,
27
27
  compilerType: type_1.ECompilerType.Rspack,
28
28
  configFiles: ["rspack.config.js", "webpack.config.js"],
29
- documentType
29
+ webpackCases
30
30
  })
31
31
  ],
32
32
  runner: runner_1.HotRunnerFactory,
@@ -35,8 +35,8 @@ function getHotCreator(target, documentType) {
35
35
  }
36
36
  return hotCreators.get(key);
37
37
  }
38
- function createHotNewIncrementalCase(name, src, dist, target, documentType) {
39
- const creator = getHotCreator(target, documentType);
38
+ function createHotNewIncrementalCase(name, src, dist, target, webpackCases) {
39
+ const creator = getHotCreator(target, webpackCases);
40
40
  creator.create(name, src, dist);
41
41
  }
42
42
  const watchCreators = new Map();
@@ -11,7 +11,10 @@ const node_path_1 = __importDefault(require("node:path"));
11
11
  const chalk_1 = __importDefault(require("chalk"));
12
12
  const filenamify_1 = __importDefault(require("filenamify"));
13
13
  const jest_diff_1 = require("jest-diff");
14
+ const serializers_1 = require("../serializers");
14
15
  const { serialize } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve("jest-snapshot")), "./utils.js"));
16
+ // get jest builtin serializers
17
+ const { getSerializers } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve("jest-snapshot")), "./plugins.js"));
15
18
  /**
16
19
  * Check if 2 strings or buffer are equal
17
20
  */
@@ -27,9 +30,15 @@ const isEqual = (a, b) => {
27
30
  * @param options Additional options for matching
28
31
  */
29
32
  function toMatchFileSnapshot(rawContent, filepath, options = {}) {
30
- const content = Buffer.isBuffer(rawContent) || typeof rawContent === "string"
33
+ const content = Buffer.isBuffer(rawContent)
31
34
  ? rawContent
32
- : serialize(rawContent);
35
+ : serialize(rawContent, /* ident */ 2, {
36
+ plugins: [
37
+ ...getSerializers(),
38
+ // Rspack serializers
39
+ ...serializers_1.serializers
40
+ ]
41
+ });
33
42
  const { isNot, snapshotState } = this;
34
43
  const filename = filepath === undefined
35
44
  ? // If file name is not specified, generate one from the test title
@@ -0,0 +1,2 @@
1
+ import type { Plugins } from "pretty-format";
2
+ export declare const serializers: Plugins;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializers = void 0;
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");
8
+ exports.serializers = [
9
+ {
10
+ test(received) {
11
+ return typeof received === "string";
12
+ },
13
+ print(received) {
14
+ return (0, placeholder_1.normalizePlaceholder)(received.trim());
15
+ }
16
+ },
17
+ // for diff
18
+ {
19
+ test(received) {
20
+ return received?.constructor?.name === "RspackTestDiff";
21
+ },
22
+ print(received, next) {
23
+ return next((0, diff_1.normalizeDiff)(received));
24
+ }
25
+ },
26
+ // for errors
27
+ {
28
+ test(received) {
29
+ return received?.constructor?.name === "RspackStatsDiagnostics";
30
+ },
31
+ print(received, next) {
32
+ return next((0, error_1.normalizeDignostics)(received));
33
+ }
34
+ },
35
+ {
36
+ test(received) {
37
+ return typeof received?.message === "string";
38
+ },
39
+ print(received, next) {
40
+ return next((0, error_1.normalizeError)(received));
41
+ }
42
+ },
43
+ // for stats
44
+ {
45
+ test(received) {
46
+ return received?.constructor?.name === "RspackStats";
47
+ },
48
+ print(received, next) {
49
+ return next((0, rspack_1.normalizeStats)(received));
50
+ }
51
+ }
52
+ ];
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const diff_1 = require("./expect/diff");
4
- const error_1 = require("./expect/error");
5
- const placeholder_1 = require("./expect/placeholder");
6
- const rspack_1 = require("./expect/rspack");
7
3
  const to_be_typeof_1 = require("./expect/to-be-typeof");
8
4
  const to_end_with_1 = require("./expect/to-end-with");
9
5
  const to_match_file_snapshot_1 = require("./expect/to-match-file-snapshot");
6
+ const serializers_1 = require("./serializers");
10
7
  expect.extend({
11
8
  // CHANGE: new test matcher for `rspack-test-tools`
12
9
  // @ts-ignore
@@ -14,46 +11,6 @@ expect.extend({
14
11
  toBeTypeOf: to_be_typeof_1.toBeTypeOf,
15
12
  toEndWith: to_end_with_1.toEndWith
16
13
  });
17
- expect.addSnapshotSerializer({
18
- test(received) {
19
- return typeof received === "string";
20
- },
21
- print(received) {
22
- return (0, placeholder_1.normalizePlaceholder)(received.trim());
23
- }
24
- });
25
- // for diff
26
- expect.addSnapshotSerializer({
27
- test(received) {
28
- return received?.constructor?.name === "RspackTestDiff";
29
- },
30
- print(received, next) {
31
- return next((0, diff_1.normalizeDiff)(received));
32
- }
33
- });
34
- // for errors
35
- expect.addSnapshotSerializer({
36
- test(received) {
37
- return received?.constructor?.name === "RspackStatsDiagnostics";
38
- },
39
- print(received, next) {
40
- return next((0, error_1.normalizeDignostics)(received));
41
- }
42
- });
43
- expect.addSnapshotSerializer({
44
- test(received) {
45
- return typeof received?.message === "string";
46
- },
47
- print(received, next) {
48
- return next((0, error_1.normalizeError)(received));
49
- }
50
- });
51
- // for stats
52
- expect.addSnapshotSerializer({
53
- test(received) {
54
- return received?.constructor?.name === "RspackStats";
55
- },
56
- print(received, next) {
57
- return next((0, rspack_1.normalizeStats)(received));
58
- }
59
- });
14
+ for (const serializer of serializers_1.serializers) {
15
+ expect.addSnapshotSerializer(serializer);
16
+ }
@@ -2,6 +2,8 @@ import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "..
2
2
  import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
3
3
  export interface IDiagnosticProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
4
4
  snapshot: string;
5
+ snapshotErrors: string;
6
+ snapshotWarning: string;
5
7
  format?: (output: string) => string;
6
8
  }
7
9
  export declare class DiagnosticProcessor<T extends ECompilerType> extends BasicProcessor<T> {
@@ -29,11 +29,40 @@ class DiagnosticProcessor extends basic_1.BasicProcessor {
29
29
  errors: true,
30
30
  warnings: true
31
31
  })).replaceAll("\\", "/"); // stats has some win32 paths that path-serializer can not handle
32
+ const statsJson = stats.toJson({
33
+ all: false,
34
+ errors: true,
35
+ warnings: true
36
+ });
37
+ const errors = (statsJson.errors || []).map(e => {
38
+ // @ts-expect-error error message is already serialized in `stats.err`
39
+ delete e.message;
40
+ delete e.stack;
41
+ return e;
42
+ });
43
+ const warnings = (statsJson.warnings || []).map(e => {
44
+ // @ts-expect-error error message is already serialized in `stats.err`
45
+ delete e.message;
46
+ delete e.stack;
47
+ return e;
48
+ });
32
49
  if (typeof this._diagnosticOptions.format === "function") {
33
50
  output = this._diagnosticOptions.format(output);
34
51
  }
52
+ env.expect.addSnapshotSerializer({
53
+ test(received) {
54
+ return typeof received === "string";
55
+ },
56
+ serialize(received) {
57
+ return (0, placeholder_1.normalizePlaceholder)(received.trim());
58
+ }
59
+ });
35
60
  const errorOutputPath = node_path_1.default.resolve(context.getSource(this._diagnosticOptions.snapshot));
61
+ const errorStatsOutputPath = node_path_1.default.resolve(context.getSource(this._diagnosticOptions.snapshotErrors));
62
+ const warningStatsOutputPath = node_path_1.default.resolve(context.getSource(this._diagnosticOptions.snapshotWarning));
36
63
  env.expect(output).toMatchFileSnapshot(errorOutputPath);
64
+ env.expect(errors).toMatchFileSnapshot(errorStatsOutputPath);
65
+ env.expect(warnings).toMatchFileSnapshot(warningStatsOutputPath);
37
66
  }
38
67
  static defaultOptions(context) {
39
68
  return {
@@ -1,9 +1,9 @@
1
- import { ECompilerType, EDocumentType, type ITestContext, type ITestEnv, type TCompilerOptions } from "../type";
1
+ import { ECompilerType, type ITestContext, type ITestEnv, type TCompilerOptions } from "../type";
2
2
  import type { IBasicProcessorOptions } from "./basic";
3
3
  import { HotProcessor } from "./hot";
4
4
  export interface IHotNewIncrementalProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
5
5
  target: TCompilerOptions<T>["target"];
6
- documentType?: EDocumentType;
6
+ webpackCases: boolean;
7
7
  }
8
8
  export declare class HotNewIncrementalProcessor<T extends ECompilerType> extends HotProcessor<T> {
9
9
  protected _hotOptions: IHotNewIncrementalProcessorOptions<T>;
@@ -5,11 +5,14 @@ const type_1 = require("../type");
5
5
  const hot_1 = require("./hot");
6
6
  class HotNewIncrementalProcessor extends hot_1.HotProcessor {
7
7
  constructor(_hotOptions) {
8
- super(_hotOptions);
8
+ super({
9
+ defaultOptions: HotNewIncrementalProcessor.defaultOptions,
10
+ ..._hotOptions
11
+ });
9
12
  this._hotOptions = _hotOptions;
10
13
  }
11
14
  async run(env, context) {
12
- context.setValue(this._options.name, "documentType", this._hotOptions.documentType);
15
+ context.setValue(this._options.name, "documentType", this._hotOptions.webpackCases ? type_1.EDocumentType.Fake : type_1.EDocumentType.JSDOM);
13
16
  await super.run(env, context);
14
17
  }
15
18
  async afterAll(context) {
@@ -29,7 +32,7 @@ class HotNewIncrementalProcessor extends hot_1.HotProcessor {
29
32
  if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
30
33
  const rspackOptions = options;
31
34
  rspackOptions.experiments ??= {};
32
- rspackOptions.experiments.incremental ??= "advance";
35
+ rspackOptions.experiments.incremental ??= "advance-silent";
33
36
  }
34
37
  else {
35
38
  throw new Error("HotNewIncrementalProcessor should only used for Rspack.");
@@ -106,7 +106,7 @@ class NormalProcessor extends basic_1.BasicProcessor {
106
106
  .concat(function () {
107
107
  this.hooks.compilation.tap("TestCasesTest", compilation => {
108
108
  const hooks = [
109
- // CHANGE: the follwing hooks are not supported yet, so comment it out
109
+ // CHANGE: the following hooks are not supported yet, so comment it out
110
110
  // "optimize",
111
111
  // "optimizeModules",
112
112
  // "optimizeChunks",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.3.12",
3
+ "version": "1.3.14",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "access": "public",
24
24
  "provenance": true
25
25
  },
26
- "homepage": "https://rspack.dev",
26
+ "homepage": "https://rspack.rs",
27
27
  "bugs": "https://github.com/web-infra-dev/rspack/issues",
28
28
  "repository": {
29
29
  "type": "git",
@@ -31,10 +31,10 @@
31
31
  "directory": "packages/rspack-test-tools"
32
32
  },
33
33
  "dependencies": {
34
- "@babel/generator": "7.27.1",
35
- "@babel/parser": "7.27.2",
36
- "@babel/traverse": "7.27.1",
37
- "@babel/types": "7.27.1",
34
+ "@babel/generator": "7.27.5",
35
+ "@babel/parser": "7.27.5",
36
+ "@babel/traverse": "7.27.4",
37
+ "@babel/types": "7.27.3",
38
38
  "cross-env": "^7.0.3",
39
39
  "csv-to-markdown-table": "^1.5.0",
40
40
  "deepmerge": "^4.3.1",
@@ -47,6 +47,7 @@
47
47
  "jest-snapshot": "29.7.0",
48
48
  "jsdom": "^26.1.0",
49
49
  "memfs": "4.17.2",
50
+ "loader-utils": "^2.0.4",
50
51
  "path-serializer": "0.4.0",
51
52
  "pretty-format": "29.7.0",
52
53
  "rimraf": "^5.0.10",
@@ -65,7 +66,7 @@
65
66
  "@types/babel__traverse": "7.20.7",
66
67
  "@types/fs-extra": "11.0.4",
67
68
  "@types/jsdom": "^21.1.7",
68
- "@types/react": "^19.1.4",
69
+ "@types/react": "^19.1.6",
69
70
  "@types/react-dom": "^19.1.5",
70
71
  "@webdiscus/pug-loader": "^2.11.1",
71
72
  "acorn": "^8.14.1",
@@ -90,13 +91,13 @@
90
91
  "source-map": "^0.7.4",
91
92
  "source-map-loader": "^5.0.0",
92
93
  "style-loader": "^4.0.0",
93
- "terser": "5.39.2",
94
+ "terser": "5.40.0",
94
95
  "typescript": "^5.8.3",
95
96
  "wast-loader": "^1.14.1",
96
97
  "worker-rspack-loader": "^3.1.2",
97
- "@rspack/test-tools": "1.3.12",
98
- "@rspack/cli": "1.3.12",
99
- "@rspack/core": "1.3.12"
98
+ "@rspack/core": "1.3.14",
99
+ "@rspack/cli": "1.3.14",
100
+ "@rspack/test-tools": "1.3.14"
100
101
  },
101
102
  "peerDependencies": {
102
103
  "@rspack/core": ">=1.0.0"