@rspack/test-tools 1.0.13 → 1.1.0-beta.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.
Files changed (77) 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 +4 -13
  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 +2 -3
  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/index.d.ts +1 -0
  41. package/dist/helper/index.js +1 -0
  42. package/dist/helper/legacy/EventSourceForNode.d.ts +2 -3
  43. package/dist/helper/legacy/FakeDocument.d.ts +2 -2
  44. package/dist/helper/legacy/asModule.d.ts +0 -1
  45. package/dist/helper/legacy/createFakeWorker.d.ts +0 -1
  46. package/dist/helper/legacy/fakeSystem.d.ts +3 -3
  47. package/dist/helper/legacy/walkCssTokens.d.ts +5 -3
  48. package/dist/helper/parse-modules.js +1 -2
  49. package/dist/helper/read-config-file.js +1 -2
  50. package/dist/helper/replace-paths.js +1 -2
  51. package/dist/helper/setup-env.d.ts +1 -0
  52. package/dist/helper/setup-env.js +1 -0
  53. package/dist/helper/setup-expect.js +58 -1
  54. package/dist/helper/update-snapshot.js +1 -2
  55. package/dist/helper/util/checkSourceMap.js +1 -1
  56. package/dist/helper/util/checkStats.d.ts +2 -0
  57. package/dist/helper/util/checkStats.js +43 -0
  58. package/dist/helper/util/filterUtil.d.ts +4 -4
  59. package/dist/helper/util/identifier.d.ts +9 -9
  60. package/dist/helper/win.js +2 -3
  61. package/dist/processor/defaults.d.ts +2 -5
  62. package/dist/processor/defaults.js +2 -36
  63. package/dist/processor/error.d.ts +4 -6
  64. package/dist/processor/error.js +5 -66
  65. package/dist/processor/hook.d.ts +0 -1
  66. package/dist/processor/hot-new-incremental.js +1 -9
  67. package/dist/processor/stats-api.d.ts +0 -3
  68. package/dist/processor/stats-api.js +0 -4
  69. package/dist/processor/stats.js +7 -28
  70. package/dist/processor/watch.js +39 -1
  71. package/dist/runner/runner/cjs.js +3 -0
  72. package/dist/runner/type.d.ts +0 -2
  73. package/dist/runner/type.js +1 -1
  74. package/dist/test/simple.js +1 -2
  75. package/dist/type.d.ts +0 -3
  76. package/dist/type.js +3 -3
  77. package/package.json +6 -5
@@ -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());
@@ -9,6 +9,7 @@ const node_path_1 = __importDefault(require("node:path"));
9
9
  const webpack_merge_1 = require("webpack-merge");
10
10
  const compiler_1 = require("../compiler");
11
11
  const helper_1 = require("../helper");
12
+ const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
12
13
  const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
13
14
  const multi_1 = require("./multi");
14
15
  // This file is used to port step number to rspack.config.js/webpack.config.js
@@ -52,7 +53,44 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
52
53
  await super.run(env, context);
53
54
  }
54
55
  async check(env, context) {
55
- await super.check(env, context);
56
+ const testConfig = context.getTestConfig();
57
+ if (testConfig.noTest)
58
+ return;
59
+ const errors = (context.getError(this._options.name) || []).map(e => ({
60
+ message: e.message,
61
+ stack: e.stack
62
+ }));
63
+ const warnings = [];
64
+ const compiler = this.getCompiler(context);
65
+ const stats = compiler.getStats();
66
+ if (stats) {
67
+ node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
68
+ preset: "verbose",
69
+ colors: false
70
+ }), "utf-8");
71
+ const jsonStats = stats.toJson({
72
+ errorDetails: true
73
+ });
74
+ node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(jsonStats, null, 2), "utf-8");
75
+ if (jsonStats.errors) {
76
+ errors.push(...jsonStats.errors);
77
+ }
78
+ if (jsonStats.warnings) {
79
+ warnings.push(...jsonStats.warnings);
80
+ }
81
+ }
82
+ await new Promise((resolve, reject) => {
83
+ (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { errors }, "error", "Error", reject);
84
+ resolve();
85
+ });
86
+ await new Promise((resolve, reject) => {
87
+ (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { warnings }, "warning", "Warning", reject);
88
+ resolve();
89
+ });
90
+ // clear error if checked
91
+ if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
92
+ context.clearError(this._options.name);
93
+ }
56
94
  // check hash
57
95
  node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.txt"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.txt`));
58
96
  node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.json"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.json`));
@@ -74,6 +74,9 @@ class CommonJsRunner extends basic_1.BasicRunner {
74
74
  createCjsRequirer() {
75
75
  const requireCache = Object.create(null);
76
76
  return (currentDirectory, modulePath, context = {}) => {
77
+ if (modulePath === "@rspack/test-tools") {
78
+ return require("@rspack/test-tools");
79
+ }
77
80
  const file = context.file || this.getFile(modulePath, currentDirectory);
78
81
  if (!file) {
79
82
  return this.requirers.get("miss")(currentDirectory, modulePath);
@@ -1,5 +1,3 @@
1
- /// <reference types="jest" />
2
- /// <reference types="../jest.d.ts" />
3
1
  import type { ITestEnv } from "../type";
4
2
  export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
5
3
  file?: TBasicRunnerFile;
@@ -6,4 +6,4 @@ var EEsmMode;
6
6
  EEsmMode[EEsmMode["Unknown"] = 0] = "Unknown";
7
7
  EEsmMode[EEsmMode["Evaluated"] = 1] = "Evaluated";
8
8
  EEsmMode[EEsmMode["Unlinked"] = 2] = "Unlinked";
9
- })(EEsmMode = exports.EEsmMode || (exports.EEsmMode = {}));
9
+ })(EEsmMode || (exports.EEsmMode = EEsmMode = {}));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSimpleProcessorRunner = void 0;
3
+ exports.getSimpleProcessorRunner = getSimpleProcessorRunner;
4
4
  const context_1 = require("./context");
5
5
  const CONTEXT_MAP = new Map();
6
6
  function getSimpleProcessorRunner(src, dist, options = {}) {
@@ -41,4 +41,3 @@ function getSimpleProcessorRunner(src, dist, options = {}) {
41
41
  }
42
42
  return CONTEXT_MAP.get(key);
43
43
  }
44
- exports.getSimpleProcessorRunner = getSimpleProcessorRunner;
package/dist/type.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="jest" />
3
- /// <reference types="../jest.d.ts" />
4
1
  import type EventEmitter from "node:events";
5
2
  import type { Compiler as RspackCompiler, RspackOptions, Stats as RspackStats, StatsCompilation as RspackStatsCompilation } from "@rspack/core";
6
3
  import type { Compiler as WebpackCompiler, Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack";
package/dist/type.js CHANGED
@@ -6,7 +6,7 @@ var ECompilerType;
6
6
  (function (ECompilerType) {
7
7
  ECompilerType["Rspack"] = "rspack";
8
8
  ECompilerType["Webpack"] = "webpack";
9
- })(ECompilerType = exports.ECompilerType || (exports.ECompilerType = {}));
9
+ })(ECompilerType || (exports.ECompilerType = ECompilerType = {}));
10
10
  var ECompareResultType;
11
11
  (function (ECompareResultType) {
12
12
  ECompareResultType["Same"] = "same";
@@ -14,9 +14,9 @@ var ECompareResultType;
14
14
  ECompareResultType["OnlyDist"] = "only-dist";
15
15
  ECompareResultType["OnlySource"] = "only-source";
16
16
  ECompareResultType["Different"] = "different";
17
- })(ECompareResultType = exports.ECompareResultType || (exports.ECompareResultType = {}));
17
+ })(ECompareResultType || (exports.ECompareResultType = ECompareResultType = {}));
18
18
  var EDocumentType;
19
19
  (function (EDocumentType) {
20
20
  EDocumentType["Fake"] = "fake";
21
21
  EDocumentType["JSDOM"] = "jsdom";
22
- })(EDocumentType = exports.EDocumentType || (exports.EDocumentType = {}));
22
+ })(EDocumentType || (exports.EDocumentType = EDocumentType = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.0.13",
3
+ "version": "1.1.0-beta.0",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -48,6 +48,7 @@
48
48
  "jsdom": "^25.0.0",
49
49
  "memfs": "4.8.1",
50
50
  "mkdirp": "0.5.6",
51
+ "path-serializer": "0.1.2",
51
52
  "pretty-format": "29.7.0",
52
53
  "rimraf": "3.0.2",
53
54
  "strip-ansi": "6.0.1",
@@ -99,10 +100,10 @@
99
100
  "source-map-loader": "^5.0.0",
100
101
  "style-loader": "^4.0.0",
101
102
  "terser": "5.27.2",
102
- "typescript": "5.0.2",
103
+ "typescript": "^5.6.3",
103
104
  "wast-loader": "^1.12.1",
104
- "@rspack/core": "1.0.13",
105
- "@rspack/cli": "1.0.13"
105
+ "@rspack/cli": "1.1.0-beta.0",
106
+ "@rspack/core": "1.1.0-beta.0"
106
107
  },
107
108
  "peerDependencies": {
108
109
  "@rspack/core": ">=0.7.0"
@@ -118,6 +119,6 @@
118
119
  "test:hot": "cross-env RSPACK_HOT_TEST=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.hot.js --passWithNoTests",
119
120
  "test:diff": "cross-env RSPACK_DIFF=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.diff.js --passWithNoTests",
120
121
  "api-extractor": "api-extractor run --verbose",
121
- "api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
122
+ "api-extractor:ci": "api-extractor run --verbose || diff temp/test-tools.api.md etc/test-tools.api.md"
122
123
  }
123
124
  }