@rspack-debug/test-tools 1.4.11 → 1.6.4

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 (259) hide show
  1. package/README.md +1 -1
  2. package/dist/case/builtin.d.ts +3 -0
  3. package/dist/case/builtin.js +152 -14
  4. package/dist/case/cache.d.ts +2 -2
  5. package/dist/case/cache.js +214 -12
  6. package/dist/case/common.d.ts +11 -0
  7. package/dist/case/common.js +249 -0
  8. package/dist/case/compiler.d.ts +17 -4
  9. package/dist/case/compiler.js +149 -12
  10. package/dist/case/config.d.ts +7 -2
  11. package/dist/case/config.js +106 -18
  12. package/dist/case/defaults.d.ts +13 -4
  13. package/dist/case/defaults.js +73 -18
  14. package/dist/case/diagnostic.d.ts +6 -0
  15. package/dist/case/diagnostic.js +121 -14
  16. package/dist/case/error.d.ts +15 -4
  17. package/dist/case/error.js +137 -12
  18. package/dist/case/esm-output.d.ts +1 -0
  19. package/dist/case/esm-output.js +117 -0
  20. package/dist/case/example.d.ts +1 -0
  21. package/dist/case/example.js +57 -0
  22. package/dist/case/hash.d.ts +2 -2
  23. package/dist/case/hash.js +72 -9
  24. package/dist/case/hook.d.ts +36 -4
  25. package/dist/case/hook.js +209 -20
  26. package/dist/case/hot-step.d.ts +2 -2
  27. package/dist/case/hot-step.js +309 -13
  28. package/dist/case/hot.d.ts +11 -2
  29. package/dist/case/hot.js +217 -12
  30. package/dist/case/incremental.d.ts +2 -2
  31. package/dist/case/incremental.js +24 -45
  32. package/dist/case/index.d.ts +31 -20
  33. package/dist/case/index.js +50 -34
  34. package/dist/case/multi-compiler.d.ts +19 -0
  35. package/dist/case/multi-compiler.js +97 -0
  36. package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
  37. package/dist/case/normal.d.ts +3 -0
  38. package/dist/case/normal.js +202 -18
  39. package/dist/case/runner.d.ts +19 -0
  40. package/dist/case/runner.js +113 -0
  41. package/dist/case/serial.d.ts +2 -2
  42. package/dist/case/serial.js +10 -14
  43. package/dist/case/stats-api.d.ts +8 -3
  44. package/dist/case/stats-api.js +69 -10
  45. package/dist/case/stats-output.d.ts +11 -0
  46. package/dist/case/stats-output.js +199 -8
  47. package/dist/case/treeshaking.js +34 -7
  48. package/dist/case/watch.d.ts +27 -0
  49. package/dist/case/watch.js +318 -22
  50. package/dist/compiler.d.ts +16 -16
  51. package/dist/compiler.js +120 -15
  52. package/dist/helper/directory.d.ts +1 -1
  53. package/dist/helper/directory.js +6 -2
  54. package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
  55. package/dist/helper/disable-iconv-lite-warning.js +12 -0
  56. package/dist/helper/expect/error.js +1 -1
  57. package/dist/helper/expect/placeholder.js +7 -7
  58. package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
  59. package/dist/helper/expect/to-match-file-snapshot.js +3 -3
  60. package/dist/helper/hot-update/loader.d.ts +2 -1
  61. package/dist/helper/hot-update/loader.js +5 -30
  62. package/dist/helper/hot-update/plugin.d.ts +1 -1
  63. package/dist/helper/hot-update/plugin.js +14 -13
  64. package/dist/helper/index.d.ts +2 -1
  65. package/dist/helper/index.js +2 -1
  66. package/dist/helper/is.d.ts +2 -0
  67. package/dist/helper/is.js +15 -0
  68. package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
  69. package/dist/helper/legacy/LogTestPlugin.js +35 -0
  70. package/dist/helper/legacy/asModule.js +0 -2
  71. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
  72. package/dist/helper/legacy/checkArrayExpectation.js +8 -8
  73. package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
  74. package/dist/helper/legacy/createFakeWorker.js +44 -20
  75. package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
  76. package/dist/helper/legacy/createLazyTestEnv.js +3 -3
  77. package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
  78. package/dist/helper/legacy/deprecationTracking.js +41 -0
  79. package/dist/helper/legacy/expectSource.d.ts +10 -0
  80. package/dist/helper/legacy/expectSource.js +23 -0
  81. package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
  82. package/dist/helper/legacy/findOutputFiles.js +14 -0
  83. package/dist/helper/legacy/regexEscape.d.ts +2 -0
  84. package/dist/helper/legacy/regexEscape.js +5 -0
  85. package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
  86. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  87. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  88. package/dist/helper/legacy/supportsUsing.d.ts +2 -0
  89. package/dist/helper/legacy/supportsUsing.js +26 -0
  90. package/dist/helper/legacy/urlToRelativePath.js +5 -2
  91. package/dist/helper/read-config-file.d.ts +3 -2
  92. package/dist/helper/read-config-file.js +12 -2
  93. package/dist/helper/setup-env.js +26 -4
  94. package/dist/helper/setup-expect.js +2 -2
  95. package/dist/helper/setup-wasm.js +2 -2
  96. package/dist/helper/stringify-config.d.ts +2 -0
  97. package/dist/helper/stringify-config.js +43 -0
  98. package/dist/helper/util/checkStats.d.ts +0 -1
  99. package/dist/helper/util/checkStats.js +0 -18
  100. package/dist/helper/util/expectWarningFactory.js +2 -4
  101. package/dist/index.d.ts +0 -4
  102. package/dist/index.js +1 -4
  103. package/dist/plugin/index.d.ts +0 -3
  104. package/dist/plugin/index.js +0 -3
  105. package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
  106. package/dist/runner/index.d.ts +2 -9
  107. package/dist/runner/index.js +2 -9
  108. package/dist/runner/node/index.d.ts +41 -0
  109. package/dist/runner/node/index.js +450 -0
  110. package/dist/runner/web/index.d.ts +30 -0
  111. package/dist/runner/web/index.js +343 -0
  112. package/dist/test/context.d.ts +15 -18
  113. package/dist/test/context.js +52 -57
  114. package/dist/test/creator.d.ts +20 -19
  115. package/dist/test/creator.js +69 -57
  116. package/dist/test/debug.d.ts +15 -0
  117. package/dist/test/debug.js +205 -0
  118. package/dist/test/tester.d.ts +1 -0
  119. package/dist/test/tester.js +44 -6
  120. package/dist/type.d.ts +94 -64
  121. package/dist/type.js +8 -12
  122. package/package.json +22 -61
  123. package/rstest.d.ts +24 -0
  124. package/dist/case/diff.d.ts +0 -3
  125. package/dist/case/diff.js +0 -126
  126. package/dist/compare/comparator.d.ts +0 -17
  127. package/dist/compare/comparator.js +0 -52
  128. package/dist/compare/compare.d.ts +0 -17
  129. package/dist/compare/compare.js +0 -175
  130. package/dist/compare/format-code.d.ts +0 -16
  131. package/dist/compare/format-code.js +0 -239
  132. package/dist/compare/index.d.ts +0 -5
  133. package/dist/compare/index.js +0 -21
  134. package/dist/compare/replace-module-argument.d.ts +0 -1
  135. package/dist/compare/replace-module-argument.js +0 -8
  136. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  137. package/dist/compare/replace-runtime-module-name.js +0 -71
  138. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  139. package/dist/helper/legacy/FakeDocument.js +0 -278
  140. package/dist/helper/legacy/createLogger.d.ts +0 -23
  141. package/dist/helper/legacy/createLogger.js +0 -20
  142. package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
  143. package/dist/helper/legacy/supportsImportFn.js +0 -15
  144. package/dist/helper/legacy/supportsWorker.js +0 -17
  145. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  146. package/dist/helper/legacy/walkCssTokens.js +0 -761
  147. package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
  148. package/dist/helper/legacy/warmup-webpack.js +0 -26
  149. package/dist/helper/loaders/hot-update.d.ts +0 -1
  150. package/dist/helper/loaders/hot-update.js +0 -40
  151. package/dist/helper/plugins/hot-update.d.ts +0 -7
  152. package/dist/helper/plugins/hot-update.js +0 -40
  153. package/dist/helper/plugins/index.d.ts +0 -1
  154. package/dist/helper/plugins/index.js +0 -17
  155. package/dist/helper/util/currentWatchStep.d.ts +0 -1
  156. package/dist/helper/util/currentWatchStep.js +0 -2
  157. package/dist/helper/util/identifier.d.ts +0 -76
  158. package/dist/helper/util/identifier.js +0 -339
  159. package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
  160. package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
  161. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  162. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  163. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  164. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  165. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  166. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  167. package/dist/processor/basic.d.ts +0 -24
  168. package/dist/processor/basic.js +0 -146
  169. package/dist/processor/builtin.d.ts +0 -9
  170. package/dist/processor/builtin.js +0 -171
  171. package/dist/processor/cache.d.ts +0 -20
  172. package/dist/processor/cache.js +0 -128
  173. package/dist/processor/config.d.ts +0 -11
  174. package/dist/processor/config.js +0 -81
  175. package/dist/processor/defaults.d.ts +0 -30
  176. package/dist/processor/defaults.js +0 -72
  177. package/dist/processor/diagnostic.d.ts +0 -15
  178. package/dist/processor/diagnostic.js +0 -102
  179. package/dist/processor/diff.d.ts +0 -30
  180. package/dist/processor/diff.js +0 -140
  181. package/dist/processor/error.d.ts +0 -23
  182. package/dist/processor/error.js +0 -95
  183. package/dist/processor/hash.d.ts +0 -10
  184. package/dist/processor/hash.js +0 -63
  185. package/dist/processor/hook.d.ts +0 -44
  186. package/dist/processor/hook.js +0 -204
  187. package/dist/processor/hot-incremental.d.ts +0 -14
  188. package/dist/processor/hot-incremental.js +0 -43
  189. package/dist/processor/hot-step.d.ts +0 -18
  190. package/dist/processor/hot-step.js +0 -304
  191. package/dist/processor/hot.d.ts +0 -17
  192. package/dist/processor/hot.js +0 -140
  193. package/dist/processor/index.d.ts +0 -20
  194. package/dist/processor/index.js +0 -36
  195. package/dist/processor/multi.d.ts +0 -17
  196. package/dist/processor/multi.js +0 -73
  197. package/dist/processor/normal.d.ts +0 -12
  198. package/dist/processor/normal.js +0 -150
  199. package/dist/processor/simple.d.ts +0 -23
  200. package/dist/processor/simple.js +0 -49
  201. package/dist/processor/snapshot.d.ts +0 -12
  202. package/dist/processor/snapshot.js +0 -66
  203. package/dist/processor/stats-api.d.ts +0 -18
  204. package/dist/processor/stats-api.js +0 -48
  205. package/dist/processor/stats.d.ts +0 -18
  206. package/dist/processor/stats.js +0 -206
  207. package/dist/processor/treeshaking.d.ts +0 -10
  208. package/dist/processor/treeshaking.js +0 -33
  209. package/dist/processor/watch.d.ts +0 -30
  210. package/dist/processor/watch.js +0 -241
  211. package/dist/reporter/diff-html.d.ts +0 -15
  212. package/dist/reporter/diff-html.js +0 -69
  213. package/dist/reporter/diff-stats.d.ts +0 -24
  214. package/dist/reporter/diff-stats.js +0 -131
  215. package/dist/reporter/index.d.ts +0 -2
  216. package/dist/reporter/index.js +0 -18
  217. package/dist/runner/basic.d.ts +0 -10
  218. package/dist/runner/basic.js +0 -63
  219. package/dist/runner/cache.d.ts +0 -5
  220. package/dist/runner/cache.js +0 -90
  221. package/dist/runner/hot-step.d.ts +0 -5
  222. package/dist/runner/hot-step.js +0 -87
  223. package/dist/runner/hot.d.ts +0 -5
  224. package/dist/runner/hot.js +0 -83
  225. package/dist/runner/multiple.d.ts +0 -11
  226. package/dist/runner/multiple.js +0 -38
  227. package/dist/runner/normal.d.ts +0 -5
  228. package/dist/runner/normal.js +0 -20
  229. package/dist/runner/runner/basic.d.ts +0 -30
  230. package/dist/runner/runner/basic.js +0 -107
  231. package/dist/runner/runner/cjs.d.ts +0 -14
  232. package/dist/runner/runner/cjs.js +0 -151
  233. package/dist/runner/runner/esm.d.ts +0 -7
  234. package/dist/runner/runner/esm.js +0 -125
  235. package/dist/runner/runner/index.d.ts +0 -8
  236. package/dist/runner/runner/index.js +0 -24
  237. package/dist/runner/runner/normal.d.ts +0 -9
  238. package/dist/runner/runner/normal.js +0 -23
  239. package/dist/runner/runner/watch.d.ts +0 -16
  240. package/dist/runner/runner/watch.js +0 -27
  241. package/dist/runner/runner/web/fake.d.ts +0 -18
  242. package/dist/runner/runner/web/fake.js +0 -143
  243. package/dist/runner/runner/web/jsdom.d.ts +0 -26
  244. package/dist/runner/runner/web/jsdom.js +0 -219
  245. package/dist/runner/runner/web.d.ts +0 -15
  246. package/dist/runner/runner/web.js +0 -32
  247. package/dist/runner/type.d.ts +0 -42
  248. package/dist/runner/type.js +0 -9
  249. package/dist/runner/watch.d.ts +0 -7
  250. package/dist/runner/watch.js +0 -60
  251. package/dist/test/simple.d.ts +0 -5
  252. package/dist/test/simple.js +0 -43
  253. package/jest.d.ts +0 -25
  254. package/template/diff.bundle.css +0 -1
  255. package/template/diff.bundle.js +0 -144
  256. package/template/diff.html +0 -14
  257. package/template/editor.worker.js +0 -1
  258. /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
  259. /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
@@ -0,0 +1,450 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.NodeRunner = void 0;
40
+ const node_fs_1 = __importDefault(require("node:fs"));
41
+ const node_path_1 = __importDefault(require("node:path"));
42
+ const node_url_1 = require("node:url");
43
+ const node_vm_1 = __importStar(require("node:vm"));
44
+ const asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
45
+ const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
46
+ const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
47
+ const type_1 = require("../../type");
48
+ const isRelativePath = (p) => /^\.\.?\//.test(p);
49
+ const getSubPath = (p) => {
50
+ const lastSlash = p.lastIndexOf("/");
51
+ let firstSlash = p.indexOf("/");
52
+ if (lastSlash !== -1 && firstSlash !== lastSlash) {
53
+ if (firstSlash !== -1) {
54
+ let next = p.indexOf("/", firstSlash + 1);
55
+ let dir = p.slice(firstSlash + 1, next);
56
+ while (dir === ".") {
57
+ firstSlash = next;
58
+ next = p.indexOf("/", firstSlash + 1);
59
+ dir = p.slice(firstSlash + 1, next);
60
+ }
61
+ }
62
+ return p.slice(firstSlash + 1, lastSlash + 1);
63
+ }
64
+ return "";
65
+ };
66
+ const cached = new Map();
67
+ class NodeRunner {
68
+ constructor(_options) {
69
+ this._options = _options;
70
+ this.requireCache = Object.create(null);
71
+ this.globalContext = null;
72
+ this.baseModuleScope = null;
73
+ this.requirers = new Map();
74
+ }
75
+ log(message) {
76
+ this._options.logs?.push(`[NodeRunner] ${message}`);
77
+ }
78
+ run(file) {
79
+ if (!this.globalContext) {
80
+ this.globalContext = this.createGlobalContext();
81
+ }
82
+ this.baseModuleScope = this.createBaseModuleScope();
83
+ if (typeof this._options.testConfig.moduleScope === "function") {
84
+ this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats, this._options.compilerOptions);
85
+ }
86
+ this.createRunner();
87
+ const res = this.getRequire()(node_path_1.default.isAbsolute(file) ? node_path_1.default.dirname(file) : this._options.dist, file.startsWith("./") ||
88
+ file.startsWith("https://test.cases/") ||
89
+ node_path_1.default.isAbsolute(file)
90
+ ? file
91
+ : `./${file}`);
92
+ if (typeof res === "object" && "then" in res) {
93
+ return res;
94
+ }
95
+ return Promise.resolve(res);
96
+ }
97
+ getRequire() {
98
+ const entryRequire = this.requirers.get("entry");
99
+ const runner = this;
100
+ return function (currentDirectory, modulePath, context = {}) {
101
+ const from = this?.from;
102
+ if (from) {
103
+ runner.log(`require: ${modulePath} from ${from}`);
104
+ }
105
+ else {
106
+ runner.log(`require: ${modulePath}`);
107
+ }
108
+ const p = Array.isArray(modulePath)
109
+ ? modulePath
110
+ : modulePath.split("?")[0];
111
+ return entryRequire(currentDirectory, p, context);
112
+ };
113
+ }
114
+ getGlobal(name) {
115
+ return (this.globalContext || {})[name];
116
+ }
117
+ createGlobalContext() {
118
+ return {
119
+ console: {
120
+ log: (...args) => {
121
+ if (printLogger) {
122
+ console.log(...args);
123
+ }
124
+ },
125
+ warn: (...args) => {
126
+ if (printLogger) {
127
+ console.warn(...args);
128
+ }
129
+ },
130
+ error: (...args) => {
131
+ console.error(...args);
132
+ },
133
+ info: (...args) => {
134
+ if (printLogger) {
135
+ console.info(...args);
136
+ }
137
+ },
138
+ debug: (...args) => {
139
+ if (printLogger) {
140
+ console.info(...args);
141
+ }
142
+ },
143
+ trace: (...args) => {
144
+ if (printLogger) {
145
+ console.info(...args);
146
+ }
147
+ },
148
+ assert: (...args) => {
149
+ console.assert(...args);
150
+ },
151
+ clear: () => {
152
+ console.clear();
153
+ }
154
+ },
155
+ setTimeout: ((cb, ms, ...args) => {
156
+ const timeout = setTimeout(cb, ms, ...args);
157
+ timeout.unref();
158
+ return timeout;
159
+ }),
160
+ clearTimeout: clearTimeout
161
+ };
162
+ }
163
+ createBaseModuleScope() {
164
+ const baseModuleScope = {
165
+ console: this.globalContext.console,
166
+ setTimeout: this.globalContext.setTimeout,
167
+ clearTimeout: this.globalContext.clearTimeout,
168
+ nsObj: (m) => {
169
+ Object.defineProperty(m, Symbol.toStringTag, {
170
+ value: "Module"
171
+ });
172
+ return m;
173
+ },
174
+ process,
175
+ URL,
176
+ Blob,
177
+ Symbol,
178
+ Buffer,
179
+ setImmediate,
180
+ self: this.globalContext,
181
+ __TEST_PATH__: __TEST_PATH__,
182
+ __MODE__: this._options.compilerOptions.mode,
183
+ __SNAPSHOT__: node_path_1.default.join(this._options.source, "__snapshot__"),
184
+ Worker: (0, createFakeWorker_1.default)(this._options.env, {
185
+ outputDirectory: this._options.dist
186
+ }),
187
+ ...this._options.env
188
+ };
189
+ return baseModuleScope;
190
+ }
191
+ createModuleScope(requireFn, m, file) {
192
+ const requirer = requireFn.bind({
193
+ from: file.path,
194
+ module: m
195
+ }, node_path_1.default.dirname(file.path));
196
+ requirer.webpackTestSuiteRequire = true;
197
+ return {
198
+ ...this.baseModuleScope,
199
+ require: requirer,
200
+ module: m,
201
+ exports: m.exports,
202
+ __dirname: node_path_1.default.dirname(file.path),
203
+ __filename: file.path,
204
+ _globalAssign: {
205
+ expect: this._options.env.expect
206
+ }
207
+ };
208
+ }
209
+ getFile(modulePath, currentDirectory) {
210
+ const cacheKey = `${currentDirectory}|${modulePath}`;
211
+ if (this._options.cachable && cached.has(cacheKey)) {
212
+ return cached.get(cacheKey);
213
+ }
214
+ let res = null;
215
+ if (Array.isArray(modulePath)) {
216
+ res = {
217
+ path: node_path_1.default.join(currentDirectory, ".array-require.js"),
218
+ content: `module.exports = (${modulePath
219
+ .map(arg => {
220
+ return `require(${JSON.stringify(`./${arg}`)})`;
221
+ })
222
+ .join(", ")});`,
223
+ subPath: ""
224
+ };
225
+ }
226
+ else if (modulePath.startsWith("https://test.cases/")) {
227
+ const relativePath = (0, urlToRelativePath_1.default)(modulePath);
228
+ const absPath = node_path_1.default.join(currentDirectory, relativePath);
229
+ res = {
230
+ path: absPath,
231
+ content: node_fs_1.default.readFileSync(absPath, "utf-8"),
232
+ subPath: ""
233
+ };
234
+ }
235
+ else if (isRelativePath(modulePath)) {
236
+ const p = node_path_1.default.join(currentDirectory, modulePath);
237
+ res = {
238
+ path: p,
239
+ content: node_fs_1.default.readFileSync(p, "utf-8"),
240
+ subPath: getSubPath(modulePath)
241
+ };
242
+ }
243
+ else if (node_path_1.default.isAbsolute(modulePath)) {
244
+ res = {
245
+ path: modulePath,
246
+ content: node_fs_1.default.readFileSync(modulePath, "utf-8"),
247
+ subPath: "absolute_path"
248
+ };
249
+ }
250
+ if (this._options.cachable && res) {
251
+ cached.set(cacheKey, res);
252
+ }
253
+ return res;
254
+ }
255
+ preExecute(code, file) { }
256
+ postExecute(m, file) { }
257
+ createRunner() {
258
+ this.requirers.set("cjs", this.createCjsRequirer());
259
+ this.requirers.set("esm", this.createEsmRequirer());
260
+ this.requirers.set("miss", this.createMissRequirer());
261
+ this.requirers.set("json", this.createJsonRequirer());
262
+ this.requirers.set("entry", (currentDirectory, modulePath, context) => {
263
+ const file = this.getFile(modulePath, currentDirectory);
264
+ this.log(`entry: ${modulePath} -> ${file?.path}`);
265
+ if (!file) {
266
+ return this.requirers.get("miss")(currentDirectory, modulePath);
267
+ }
268
+ if (file.path.endsWith(".json")) {
269
+ return this.requirers.get("json")(currentDirectory, modulePath, {
270
+ ...context,
271
+ file
272
+ });
273
+ }
274
+ if (file.path.endsWith(".mjs") &&
275
+ this._options.compilerOptions.experiments?.outputModule) {
276
+ return this.requirers.get("esm")(currentDirectory, modulePath, {
277
+ ...context,
278
+ file
279
+ });
280
+ }
281
+ return this.requirers.get("cjs")(currentDirectory, modulePath, {
282
+ ...context,
283
+ file
284
+ });
285
+ });
286
+ }
287
+ createMissRequirer() {
288
+ return (currentDirectory, modulePath, context = {}) => {
289
+ this.log(`missing: ${modulePath}`);
290
+ const modulePathStr = modulePath;
291
+ const modules = this._options.testConfig.modules;
292
+ if (modules && modulePathStr in modules) {
293
+ this.log(`mock module: ${modulePathStr}`);
294
+ return modules[modulePathStr];
295
+ }
296
+ this.log(`native require: ${modulePathStr}`);
297
+ return require(modulePathStr.startsWith("node:")
298
+ ? modulePathStr.slice(5)
299
+ : modulePathStr);
300
+ };
301
+ }
302
+ createJsonRequirer() {
303
+ return (currentDirectory, modulePath, context = {}) => {
304
+ if (Array.isArray(modulePath)) {
305
+ throw new Error("Array module path is not supported in hot cases");
306
+ }
307
+ const file = context.file || this.getFile(modulePath, currentDirectory);
308
+ this.log(`json: ${modulePath} -> ${file?.path}`);
309
+ if (!file) {
310
+ return this.requirers.get("miss")(currentDirectory, modulePath);
311
+ }
312
+ return JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(this._options.dist, modulePath), "utf-8"));
313
+ };
314
+ }
315
+ createCjsRequirer() {
316
+ return (currentDirectory, modulePath, context = {}) => {
317
+ if (modulePath === "@rspack/test-tools") {
318
+ return require("@rspack/test-tools");
319
+ }
320
+ const file = context.file || this.getFile(modulePath, currentDirectory);
321
+ this.log(`cjs: ${modulePath} -> ${file?.path}`);
322
+ if (!file) {
323
+ return this.requirers.get("miss")(currentDirectory, modulePath);
324
+ }
325
+ if (file.path in this.requireCache) {
326
+ this.log(`cjs cache hit: ${file.path}`);
327
+ return this.requireCache[file.path].exports;
328
+ }
329
+ const m = {
330
+ exports: {},
331
+ webpackTestSuiteModule: true
332
+ };
333
+ this.requireCache[file.path] = m;
334
+ if (!this._options.runInNewContext) {
335
+ file.content = `Object.assign(global, _globalAssign);${file.content}`;
336
+ }
337
+ const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
338
+ if (this._options.testConfig.moduleScope) {
339
+ this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
340
+ }
341
+ if (file.content.includes("__STATS__") && this._options.stats) {
342
+ currentModuleScope.__STATS__ = this._options.stats();
343
+ }
344
+ if (file.content.includes("__STATS_I__")) {
345
+ const statsIndex = this._options.stats?.()?.__index__;
346
+ if (typeof statsIndex === "number") {
347
+ currentModuleScope.__STATS_I__ = statsIndex;
348
+ }
349
+ }
350
+ const args = Object.keys(currentModuleScope);
351
+ const argValues = args.map(arg => currentModuleScope[arg]);
352
+ const code = `(function(${args.join(", ")}) {
353
+ ${file.content}
354
+ })`;
355
+ this.preExecute(code, file);
356
+ this.log(`run mode: ${this._options.runInNewContext ? "new context" : "this context"}`);
357
+ try {
358
+ const fn = this._options.runInNewContext
359
+ ? node_vm_1.default.runInNewContext(code, this.globalContext, {
360
+ filename: file.path,
361
+ lineOffset: -1
362
+ })
363
+ : node_vm_1.default.runInThisContext(code, {
364
+ filename: file.path,
365
+ lineOffset: -1
366
+ });
367
+ fn.call(this._options.testConfig.nonEsmThis
368
+ ? this._options.testConfig.nonEsmThis(modulePath)
369
+ : m.exports, ...argValues);
370
+ }
371
+ catch (e) {
372
+ this._options.errors?.push(e);
373
+ throw e;
374
+ }
375
+ this.postExecute(m, file);
376
+ this.log(`end cjs: ${modulePath}`);
377
+ return m.exports;
378
+ };
379
+ }
380
+ createEsmRequirer() {
381
+ const esmContext = node_vm_1.default.createContext(this.baseModuleScope, {
382
+ name: "context for esm"
383
+ });
384
+ const esmCache = new Map();
385
+ const esmIdentifier = this._options.name;
386
+ return (currentDirectory, modulePath, context = {}) => {
387
+ if (!node_vm_1.SourceTextModule) {
388
+ throw new Error("Running this test requires '--experimental-vm-modules'.\nRun with 'node --experimental-vm-modules node_modules/@rstest/core/bin/rstest'.");
389
+ }
390
+ const _require = this.getRequire();
391
+ const file = context.file || this.getFile(modulePath, currentDirectory);
392
+ this.log(`esm: ${modulePath} -> ${file?.path}`);
393
+ if (!file) {
394
+ return this.requirers.get("miss")(currentDirectory, modulePath);
395
+ }
396
+ if (file.content.includes("__STATS__")) {
397
+ esmContext.__STATS__ = this._options.stats?.();
398
+ }
399
+ if (file.content.includes("__STATS_I__")) {
400
+ const statsIndex = this._options.stats?.()?.__index__;
401
+ if (typeof statsIndex === "number") {
402
+ esmContext.__STATS_I__ = statsIndex;
403
+ }
404
+ }
405
+ let esm = esmCache.get(file.path);
406
+ if (!esm) {
407
+ esm = new node_vm_1.SourceTextModule(file.content, {
408
+ identifier: `${esmIdentifier}-${file.path}`,
409
+ // no attribute
410
+ url: `${(0, node_url_1.pathToFileURL)(file.path).href}?${esmIdentifier}`,
411
+ context: esmContext,
412
+ initializeImportMeta: (meta, _) => {
413
+ meta.url = (0, node_url_1.pathToFileURL)(file.path).href;
414
+ meta.dirname = node_path_1.default.dirname(file.path);
415
+ meta.filename = file.path;
416
+ },
417
+ importModuleDynamically: async (specifier, module) => {
418
+ this.log(`import: ${specifier} from ${file?.path}`);
419
+ const result = await _require(node_path_1.default.dirname(file.path), specifier, {
420
+ esmMode: type_1.EEsmMode.Evaluated
421
+ });
422
+ return await (0, asModule_1.default)(result, module.context);
423
+ }
424
+ });
425
+ esmCache.set(file.path, esm);
426
+ }
427
+ if (context.esmMode === type_1.EEsmMode.Unlinked)
428
+ return esm;
429
+ return (async () => {
430
+ if (esm.status === "unlinked") {
431
+ await esm.link(async (specifier, referencingModule) => {
432
+ return await (0, asModule_1.default)(await _require(node_path_1.default.dirname(referencingModule.identifier
433
+ ? referencingModule.identifier.slice(esmIdentifier.length + 1)
434
+ : (0, node_url_1.fileURLToPath)(referencingModule.url)), specifier, {
435
+ esmMode: type_1.EEsmMode.Unlinked
436
+ }), referencingModule.context, true);
437
+ });
438
+ }
439
+ await esm.evaluate();
440
+ if (context.esmMode === type_1.EEsmMode.Evaluated) {
441
+ return esm;
442
+ }
443
+ const ns = esm.namespace;
444
+ this.log(`end esm: ${modulePath}`);
445
+ return ns.default && ns.default instanceof Promise ? ns.default : ns;
446
+ })();
447
+ };
448
+ }
449
+ }
450
+ exports.NodeRunner = NodeRunner;
@@ -0,0 +1,30 @@
1
+ import type { TRunnerFile, TRunnerRequirer } from "../../type";
2
+ import { type INodeRunnerOptions, NodeRunner } from "../node";
3
+ export interface IWebRunnerOptions extends INodeRunnerOptions {
4
+ location: string;
5
+ }
6
+ export declare class WebRunner extends NodeRunner {
7
+ protected _webOptions: IWebRunnerOptions;
8
+ private dom;
9
+ constructor(_webOptions: IWebRunnerOptions);
10
+ run(file: string): Promise<unknown>;
11
+ getGlobal(name: string): unknown;
12
+ protected log(message: string): void;
13
+ protected createResourceLoader(): {
14
+ fetch(url: string, options: {
15
+ element: HTMLScriptElement;
16
+ }): any;
17
+ };
18
+ private urlToPath;
19
+ protected createBaseModuleScope(): import("../../type").IModuleScope;
20
+ protected getModuleContent(file: TRunnerFile): [
21
+ {
22
+ exports: Record<string, unknown>;
23
+ },
24
+ string,
25
+ number
26
+ ];
27
+ protected createJSDOMRequirer(): TRunnerRequirer;
28
+ protected createRunner(): void;
29
+ }
30
+ export declare const createLocatedError: (collectedErrors: Error[], offset: number) => (e: Error, file: TRunnerFile) => Error;