@rspack/test-tools 1.0.5 → 1.0.7

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.
@@ -64,8 +64,14 @@ const watchCreator = new creator_1.BasicCaseCreator({
64
64
  compilerType: type_1.ECompilerType.Rspack,
65
65
  configFiles: ["rspack.config.js", "webpack.config.js"],
66
66
  experiments: {
67
- rspackFuture: {
68
- newIncremental: true
67
+ incremental: {
68
+ make: true,
69
+ emitAssets: true,
70
+ inferAsyncModules: true,
71
+ providedExports: true,
72
+ moduleHashes: true,
73
+ moduleCodegen: true,
74
+ moduleRuntimeRequirements: true
69
75
  }
70
76
  }
71
77
  })
@@ -1,2 +1,2 @@
1
1
  import type { ECompilerType, TCompilerOptions } from "../type";
2
- export declare function readConfigFile<T extends ECompilerType>(files: string[]): TCompilerOptions<T>[];
2
+ export declare function readConfigFile<T extends ECompilerType>(files: string[], functionApply?: (config: (TCompilerOptions<T> | ((...args: unknown[]) => TCompilerOptions<T>))[]) => TCompilerOptions<T>[]): TCompilerOptions<T>[];
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readConfigFile = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
- function readConfigFile(files) {
8
+ function readConfigFile(files, functionApply) {
9
9
  const existsFile = files.find(i => fs_extra_1.default.existsSync(i));
10
10
  const fileConfig = existsFile ? require(existsFile) : {};
11
- return Array.isArray(fileConfig) ? fileConfig : [fileConfig];
11
+ const configArr = Array.isArray(fileConfig) ? fileConfig : [fileConfig];
12
+ return functionApply ? functionApply(configArr) : configArr;
12
13
  }
13
14
  exports.readConfigFile = readConfigFile;
@@ -29,8 +29,15 @@ 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.rspackFuture ??= {};
33
- rspackOptions.experiments.rspackFuture.newIncremental = true;
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
+ };
34
41
  }
35
42
  else {
36
43
  throw new Error("HotNewIncrementalProcessor should only used for Rspack.");
@@ -43,7 +43,18 @@ class MultiTaskProcessor extends basic_1.BasicProcessor {
43
43
  async config(context) {
44
44
  this.multiCompilerOptions = [];
45
45
  const caseOptions = Array.isArray(this._multiOptions.configFiles)
46
- ? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i)))
46
+ ? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i)), configs => {
47
+ return configs.flatMap(c => {
48
+ if (typeof c === "function") {
49
+ const options = {
50
+ testPath: context.getDist(),
51
+ env: undefined
52
+ };
53
+ return c(options.env, options);
54
+ }
55
+ return c;
56
+ });
57
+ })
47
58
  : [{}];
48
59
  for (const [index, options] of caseOptions.entries()) {
49
60
  const compilerOptions = (0, webpack_merge_1.merge)(typeof this._multiOptions.defaultOptions === "function"
@@ -17,7 +17,9 @@ export declare class WatchProcessor<T extends ECompilerType> extends MultiTaskPr
17
17
  build(context: ITestContext): Promise<void>;
18
18
  run(env: ITestEnv, context: ITestContext): Promise<void>;
19
19
  check(env: ITestEnv, context: ITestContext): Promise<void>;
20
+ config(context: ITestContext): Promise<void>;
20
21
  static overrideOptions<T extends ECompilerType>({ tempDir, name, experiments, optimization }: IWatchProcessorOptions<T>): (index: number, context: ITestContext, options: TCompilerOptions<ECompilerType>) => void;
22
+ static findBundle<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): string | string[];
21
23
  }
22
24
  export interface IWatchStepProcessorOptions<T extends ECompilerType> extends Omit<IWatchProcessorOptions<T>, "experiments" | "optimization"> {
23
25
  }
@@ -6,9 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WatchStepProcessor = exports.WatchProcessor = void 0;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
+ const webpack_merge_1 = require("webpack-merge");
9
10
  const compiler_1 = require("../compiler");
11
+ const helper_1 = require("../helper");
10
12
  const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
11
- const config_1 = require("./config");
12
13
  const multi_1 = require("./multi");
13
14
  // This file is used to port step number to rspack.config.js/webpack.config.js
14
15
  const currentWatchStepModulePath = node_path_1.default.resolve(__dirname, "../helper/util/currentWatchStep");
@@ -16,7 +17,7 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
16
17
  constructor(_watchOptions) {
17
18
  super({
18
19
  overrideOptions: WatchProcessor.overrideOptions(_watchOptions),
19
- findBundle: (config_1.ConfigProcessor.findBundle),
20
+ findBundle: (WatchProcessor.findBundle),
20
21
  ..._watchOptions
21
22
  });
22
23
  this._watchOptions = _watchOptions;
@@ -56,6 +57,26 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
56
57
  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`));
57
58
  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`));
58
59
  }
60
+ async config(context) {
61
+ this.multiCompilerOptions = [];
62
+ const caseOptions = Array.isArray(this._multiOptions.configFiles)
63
+ ? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i)))
64
+ : [{}];
65
+ for (const [index, options] of caseOptions.entries()) {
66
+ const compilerOptions = (0, webpack_merge_1.merge)(typeof this._multiOptions.defaultOptions === "function"
67
+ ? this._multiOptions.defaultOptions(index, context)
68
+ : {}, options);
69
+ if (typeof this._multiOptions.overrideOptions === "function") {
70
+ this._multiOptions.overrideOptions(index, context, compilerOptions);
71
+ }
72
+ this.multiCompilerOptions.push(compilerOptions);
73
+ }
74
+ const compilerOptions = this.multiCompilerOptions.length === 1
75
+ ? this.multiCompilerOptions[0]
76
+ : this.multiCompilerOptions;
77
+ const compiler = this.getCompiler(context);
78
+ compiler.setOptions(compilerOptions);
79
+ }
59
80
  static overrideOptions({ tempDir, name, experiments, optimization }) {
60
81
  return (index, context, options) => {
61
82
  if (!options.mode)
@@ -66,6 +87,8 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
66
87
  options.entry = "./index.js";
67
88
  if (!options.target)
68
89
  options.target = "async-node";
90
+ if (!options.devtool)
91
+ options.devtool = false;
69
92
  if (!options.output)
70
93
  options.output = {};
71
94
  if (!options.output.path)
@@ -103,6 +126,13 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
103
126
  options.experiments.rspackFuture.bundlerInfo.force ??= false;
104
127
  };
105
128
  }
129
+ static findBundle(index, context, options) {
130
+ const testConfig = context.getTestConfig();
131
+ if (typeof testConfig.findBundle === "function") {
132
+ return testConfig.findBundle(index, options);
133
+ }
134
+ return "./bundle.js";
135
+ }
106
136
  }
107
137
  exports.WatchProcessor = WatchProcessor;
108
138
  class WatchStepProcessor extends WatchProcessor {
@@ -18,6 +18,7 @@ class WatchRunner extends fake_1.FakeDocumentWebRunner {
18
18
  moduleScope.document = this.globalContext.document;
19
19
  moduleScope.STATE = this.state;
20
20
  moduleScope.WATCH_STEP = this._watchOptions.stepName;
21
+ moduleScope.STATS_JSON = this._options.stats;
21
22
  return moduleScope;
22
23
  }
23
24
  run(file) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -102,8 +102,8 @@
102
102
  "terser": "5.27.2",
103
103
  "typescript": "5.0.2",
104
104
  "wast-loader": "^1.12.1",
105
- "@rspack/cli": "1.0.5",
106
- "@rspack/core": "1.0.5"
105
+ "@rspack/cli": "1.0.7",
106
+ "@rspack/core": "1.0.7"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@rspack/core": ">=0.7.0"
@@ -114,7 +114,7 @@
114
114
  "dev:viewer": "rspack serve",
115
115
  "dev": "tsc -b -w",
116
116
  "test": "sh -c 'run-s \"test:* -- $*\"' sh",
117
- "testu": "sh -c 'run-s \"test:* -u -- $*\"' sh",
117
+ "testu": "sh -c 'run-s \"test:* -- -u $*\"' sh",
118
118
  "test:base": "cross-env 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.js --passWithNoTests",
119
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",
120
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",