@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
@@ -1,143 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FakeDocumentWebRunner = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const createFakeWorker_1 = __importDefault(require("../../../helper/legacy/createFakeWorker"));
10
- const currentScript_1 = __importDefault(require("../../../helper/legacy/currentScript"));
11
- const EventSourceForNode_1 = __importDefault(require("../../../helper/legacy/EventSourceForNode"));
12
- const FakeDocument_1 = __importDefault(require("../../../helper/legacy/FakeDocument"));
13
- const urlToRelativePath_1 = __importDefault(require("../../../helper/legacy/urlToRelativePath"));
14
- const cjs_1 = require("../cjs");
15
- class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
16
- constructor(_webOptions) {
17
- super(_webOptions);
18
- this._webOptions = _webOptions;
19
- this.oldCurrentScript = null;
20
- this.document = new FakeDocument_1.default(_webOptions.dist, {
21
- onScript: (node) => {
22
- this.getRequire.bind(this)()(_webOptions.dist, (0, urlToRelativePath_1.default)(node.src));
23
- }
24
- });
25
- }
26
- run(file) {
27
- if (!file.endsWith(".js")) {
28
- const cssElement = this.document.createElement("link");
29
- cssElement.href = file;
30
- cssElement.rel = "stylesheet";
31
- this.document.head.appendChild(cssElement);
32
- return Promise.resolve();
33
- }
34
- return super.run(file);
35
- }
36
- createGlobalContext() {
37
- const globalContext = super.createGlobalContext();
38
- globalContext.document = this.document;
39
- globalContext.getComputedStyle = this.document.getComputedStyle.bind(this.document);
40
- const urlToPath = (url) => {
41
- return node_path_1.default.resolve(this._options.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`);
42
- };
43
- globalContext.fetch = async (url) => {
44
- try {
45
- const buffer = await new Promise((resolve, reject) => node_fs_1.default.readFile(urlToPath(url), (err, b) => err ? reject(err) : resolve(b)));
46
- return {
47
- status: 200,
48
- ok: true,
49
- json: async () => JSON.parse(buffer.toString("utf-8"))
50
- };
51
- }
52
- catch (err) {
53
- if (err.code === "ENOENT") {
54
- return {
55
- status: 404,
56
- ok: false
57
- };
58
- }
59
- throw err;
60
- }
61
- };
62
- globalContext.importScripts = (url) => {
63
- this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
64
- this.requirers.get("entry")(this._options.dist, (0, urlToRelativePath_1.default)(url));
65
- };
66
- globalContext.document = this.document;
67
- globalContext.Worker = (0, createFakeWorker_1.default)(this._options.env, {
68
- outputDirectory: this._options.dist
69
- });
70
- globalContext.EventSource = EventSourceForNode_1.default;
71
- globalContext.location = {
72
- href: "https://test.cases/path/index.html",
73
- origin: "https://test.cases",
74
- toString() {
75
- return "https://test.cases/path/index.html";
76
- }
77
- };
78
- return globalContext;
79
- }
80
- createModuleScope(requireFn, m, file) {
81
- const subModuleScope = super.createModuleScope(requireFn, m, file);
82
- subModuleScope.importScripts = (url) => {
83
- this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
84
- this.getRequire()(this._options.dist, `.${url.slice("https://test.cases/path".length)}`);
85
- };
86
- return subModuleScope;
87
- }
88
- createBaseModuleScope() {
89
- const moduleScope = super.createBaseModuleScope();
90
- moduleScope.window = this.globalContext;
91
- moduleScope.self = this.globalContext;
92
- moduleScope.globalThis = this.globalContext;
93
- moduleScope.document = this.globalContext.document;
94
- moduleScope.getComputedStyle = this.globalContext.getComputedStyle.bind(this.globalContext);
95
- moduleScope.fetch = this.globalContext.fetch;
96
- moduleScope.importScripts = this.globalContext.importScripts;
97
- moduleScope.Worker = this.globalContext.Worker;
98
- moduleScope.EventSource = this.globalContext.EventSource;
99
- moduleScope.URL = URL;
100
- moduleScope.Worker = (0, createFakeWorker_1.default)(this._options.env, {
101
- outputDirectory: this._options.dist
102
- });
103
- moduleScope.__dirname = this._options.dist;
104
- return moduleScope;
105
- }
106
- createJsonRequirer() {
107
- return (currentDirectory, modulePath, context = {}) => {
108
- if (Array.isArray(modulePath)) {
109
- throw new Error("Array module path is not supported in hot cases");
110
- }
111
- const file = context.file || this.getFile(modulePath, currentDirectory);
112
- if (!file) {
113
- return this.requirers.get("miss")(currentDirectory, modulePath);
114
- }
115
- return JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(this._options.dist, modulePath), "utf-8"));
116
- };
117
- }
118
- createRunner() {
119
- super.createRunner();
120
- this.requirers.set("cjs", this.getRequire());
121
- this.requirers.set("json", this.createJsonRequirer());
122
- this.requirers.set("entry", (_, modulePath, context) => {
123
- if (Array.isArray(modulePath)) {
124
- throw new Error("Array module path is not supported in web runner");
125
- }
126
- if (modulePath.endsWith(".json")) {
127
- return this.requirers.get("json")(this._options.dist, modulePath, context);
128
- }
129
- return this.requirers.get("cjs")(this._options.dist, modulePath, context);
130
- });
131
- }
132
- preExecute(_, file) {
133
- this.oldCurrentScript = this.document.currentScript;
134
- this.document.currentScript = new currentScript_1.default(file.subPath);
135
- super.preExecute(_, file);
136
- }
137
- postExecute(_, file) {
138
- super.postExecute(_, file);
139
- this.document.currentScript = this.oldCurrentScript;
140
- this.oldCurrentScript = null;
141
- }
142
- }
143
- exports.FakeDocumentWebRunner = FakeDocumentWebRunner;
@@ -1,26 +0,0 @@
1
- import type { ECompilerType } from "../../../type";
2
- import type { TBasicRunnerFile, TRunnerRequirer } from "../../type";
3
- import type { IBasicRunnerOptions } from "../basic";
4
- import { CommonJsRunner } from "../cjs";
5
- export declare class JSDOMWebRunner<T extends ECompilerType = ECompilerType.Rspack> extends CommonJsRunner<T> {
6
- protected _webOptions: IBasicRunnerOptions<T>;
7
- private dom;
8
- private requireCache;
9
- constructor(_webOptions: IBasicRunnerOptions<T>);
10
- run(file: string): Promise<unknown>;
11
- getGlobal(name: string): unknown;
12
- protected createResourceLoader(): {
13
- fetch(url: string, _: {
14
- element: HTMLScriptElement;
15
- }): any;
16
- };
17
- protected createBaseModuleScope(): import("../../type").IBasicModuleScope;
18
- protected getModuleContent(file: TBasicRunnerFile): [
19
- {
20
- exports: Record<string, unknown>;
21
- },
22
- string
23
- ];
24
- protected createJSDOMRequirer(): TRunnerRequirer;
25
- protected createRunner(): void;
26
- }
@@ -1,219 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.JSDOMWebRunner = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const jsdom_1 = require("jsdom");
10
- const helper_1 = require("../../../helper");
11
- const createFakeWorker_1 = __importDefault(require("../../../helper/legacy/createFakeWorker"));
12
- const EventSourceForNode_1 = __importDefault(require("../../../helper/legacy/EventSourceForNode"));
13
- const urlToRelativePath_1 = __importDefault(require("../../../helper/legacy/urlToRelativePath"));
14
- const cjs_1 = require("../cjs");
15
- // Compatibility code to suppress iconv-lite warnings
16
- require("iconv-lite").skipDecodeWarning = true;
17
- class JSDOMWebRunner extends cjs_1.CommonJsRunner {
18
- constructor(_webOptions) {
19
- super(_webOptions);
20
- this._webOptions = _webOptions;
21
- this.requireCache = Object.create(null);
22
- const virtualConsole = new jsdom_1.VirtualConsole();
23
- virtualConsole.sendTo(console);
24
- this.dom = new jsdom_1.JSDOM(`
25
- <!doctype html>
26
- <html>
27
- <head></head>
28
- <body></body>
29
- </html>
30
- `, {
31
- url: "https://test.cases/path/index.html",
32
- resources: this.createResourceLoader(),
33
- runScripts: "dangerously",
34
- virtualConsole
35
- });
36
- this.dom.window.console = console;
37
- // compat with FakeDocument
38
- this.dom.window.eval(`
39
- Object.defineProperty(document.head, "_children", {
40
- get: function() {
41
- return Array.from(document.head.children).map(function(ele) {
42
- var type = ele.tagName.toLowerCase();
43
- return new Proxy(ele, {
44
- get(target, prop, receiver) {
45
- if (prop === "_type") {
46
- return target.tagName.toLowerCase();
47
- }
48
- if (prop === "_href") {
49
- return Reflect.get(target, "href", receiver);
50
- }
51
- return Reflect.get(target, prop, receiver);
52
- },
53
- });
54
- });
55
- }
56
- });
57
- `);
58
- const vmContext = this.dom.getInternalVMContext();
59
- vmContext.global = {};
60
- }
61
- run(file) {
62
- if (!file.endsWith(".js")) {
63
- const cssElement = this.dom.window.document.createElement("link");
64
- cssElement.href = file;
65
- cssElement.rel = "stylesheet";
66
- this.dom.window.document.head.appendChild(cssElement);
67
- return Promise.resolve();
68
- }
69
- return super.run(file);
70
- }
71
- getGlobal(name) {
72
- return this.dom.window[name];
73
- }
74
- createResourceLoader() {
75
- const urlToPath = (url) => {
76
- return node_path_1.default
77
- .resolve(this._webOptions.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`)
78
- .split("?")[0];
79
- };
80
- const that = this;
81
- class CustomResourceLoader extends jsdom_1.ResourceLoader {
82
- fetch(url, _) {
83
- const filePath = urlToPath(url);
84
- let finalCode;
85
- if (node_path_1.default.extname(filePath) === ".js") {
86
- const currentDirectory = node_path_1.default.dirname(filePath);
87
- const file = that.getFile(filePath, currentDirectory);
88
- if (!file) {
89
- throw new Error(`File not found: ${filePath}`);
90
- }
91
- const [_m, code] = that.getModuleContent(file);
92
- finalCode = code;
93
- }
94
- else {
95
- finalCode = node_fs_1.default.readFileSync(filePath);
96
- }
97
- try {
98
- return Promise.resolve(finalCode);
99
- }
100
- catch (err) {
101
- console.error(err);
102
- if (err.code === "ENOENT") {
103
- return null;
104
- }
105
- throw err;
106
- }
107
- }
108
- }
109
- return new CustomResourceLoader();
110
- }
111
- createBaseModuleScope() {
112
- const moduleScope = super.createBaseModuleScope();
113
- moduleScope.EventSource = EventSourceForNode_1.default;
114
- moduleScope.Worker = (0, createFakeWorker_1.default)(this._options.env, {
115
- outputDirectory: this._options.dist
116
- });
117
- const urlToPath = (url) => {
118
- return node_path_1.default.resolve(this._webOptions.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`);
119
- };
120
- moduleScope.fetch = async (url) => {
121
- try {
122
- const buffer = await new Promise((resolve, reject) => node_fs_1.default.readFile(urlToPath(url), (err, b) => err ? reject(err) : resolve(b)));
123
- return {
124
- status: 200,
125
- ok: true,
126
- json: async () => JSON.parse(buffer.toString("utf-8"))
127
- };
128
- }
129
- catch (err) {
130
- if (err.code === "ENOENT") {
131
- return {
132
- status: 404,
133
- ok: false
134
- };
135
- }
136
- throw err;
137
- }
138
- };
139
- moduleScope.URL = URL;
140
- moduleScope.importScripts = (url) => {
141
- this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
142
- this.requirers.get("entry")(this._options.dist, (0, urlToRelativePath_1.default)(url));
143
- };
144
- moduleScope.getComputedStyle = function () {
145
- const computedStyle = this.dom.window.getComputedStyle(this.dom.window);
146
- const getPropertyValue = computedStyle.getPropertyValue.bind(computedStyle);
147
- return {
148
- ...computedStyle,
149
- getPropertyValue(v) {
150
- return getPropertyValue(v);
151
- }
152
- };
153
- };
154
- return moduleScope;
155
- }
156
- getModuleContent(file) {
157
- const m = {
158
- exports: {}
159
- };
160
- const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
161
- if (this._options.testConfig.moduleScope) {
162
- this._options.testConfig.moduleScope(currentModuleScope);
163
- }
164
- const scopeKey = (0, helper_1.escapeSep)(file.path);
165
- const args = Object.keys(currentModuleScope).filter(arg => !["window", "self", "globalThis", "console"].includes(arg));
166
- const argValues = args
167
- .map(arg => `window["${scopeKey}"]["${arg}"]`)
168
- .join(", ");
169
- this.dom.window[scopeKey] = currentModuleScope;
170
- return [
171
- m,
172
- `
173
- // hijack document.currentScript for auto public path
174
- var $$g$$ = new Proxy(window, {
175
- get(target, prop, receiver) {
176
- if (prop === "document") {
177
- return new Proxy(window.document, {
178
- get(target, prop, receiver) {
179
- if (prop === "currentScript") {
180
- var script = target.createElement("script");
181
- script.src = "https://test.cases/path/${(0, helper_1.escapeSep)(file.subPath)}index.js";
182
- return script;
183
- }
184
- return Reflect.get(target, prop, receiver);
185
- }
186
- });
187
- }
188
- return Reflect.get(target, prop, receiver);
189
- }
190
- });
191
- (function(window, self, globalThis, console, ${args.join(", ")}) {
192
- ${file.content}
193
- })($$g$$, $$g$$, $$g$$, window["console"], ${argValues});
194
- `
195
- ];
196
- }
197
- createJSDOMRequirer() {
198
- return (currentDirectory, modulePath, context = {}) => {
199
- const file = context.file || this.getFile(modulePath, currentDirectory);
200
- if (!file) {
201
- return this.requirers.get("miss")(currentDirectory, modulePath);
202
- }
203
- if (file.path in this.requireCache) {
204
- return this.requireCache[file.path].exports;
205
- }
206
- const [m, code] = this.getModuleContent(file);
207
- this.preExecute(code, file);
208
- this.dom.window.eval(code);
209
- this.postExecute(m, file);
210
- this.requireCache[file.path] = m;
211
- return m.exports;
212
- };
213
- }
214
- createRunner() {
215
- super.createRunner();
216
- this.requirers.set("entry", this.createJSDOMRequirer());
217
- }
218
- }
219
- exports.JSDOMWebRunner = JSDOMWebRunner;
@@ -1,15 +0,0 @@
1
- import { type ECompilerType, EDocumentType, type ITestRunner } from "../../type";
2
- import type { IBasicRunnerOptions } from "./basic";
3
- import type { CommonJsRunner } from "./cjs";
4
- export interface IWebRunnerOptions<T extends ECompilerType = ECompilerType.Rspack> extends IBasicRunnerOptions<T> {
5
- dom: EDocumentType;
6
- }
7
- export declare class WebRunner<T extends ECompilerType = ECompilerType.Rspack> implements ITestRunner {
8
- protected _webOptions: IWebRunnerOptions<T>;
9
- protected originMethods: Partial<CommonJsRunner>;
10
- private implement;
11
- constructor(_webOptions: IWebRunnerOptions<T>);
12
- run(file: string): Promise<unknown>;
13
- getRequire(): import("..").TRunnerRequirer;
14
- getGlobal(name: string): unknown;
15
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebRunner = void 0;
4
- const type_1 = require("../../type");
5
- const fake_1 = require("./web/fake");
6
- const jsdom_1 = require("./web/jsdom");
7
- class WebRunner {
8
- constructor(_webOptions) {
9
- this._webOptions = _webOptions;
10
- this.originMethods = {};
11
- const { dom } = _webOptions;
12
- if (dom === type_1.EDocumentType.Fake) {
13
- this.implement = new fake_1.FakeDocumentWebRunner(_webOptions);
14
- }
15
- else if (dom === type_1.EDocumentType.JSDOM) {
16
- this.implement = new jsdom_1.JSDOMWebRunner(_webOptions);
17
- }
18
- else {
19
- throw new Error(`Dom type "${dom}" of web runner is not support yet`);
20
- }
21
- }
22
- run(file) {
23
- return this.implement.run(file);
24
- }
25
- getRequire() {
26
- return this.implement.getRequire();
27
- }
28
- getGlobal(name) {
29
- return this.implement.getGlobal(name);
30
- }
31
- }
32
- exports.WebRunner = WebRunner;
@@ -1,42 +0,0 @@
1
- import type { ITestEnv } from "../type";
2
- export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
3
- file?: TBasicRunnerFile;
4
- esmMode?: EEsmMode;
5
- }) => Object | Promise<Object>;
6
- export type TBasicRunnerFile = {
7
- path: string;
8
- content: string;
9
- subPath: string;
10
- };
11
- export declare enum EEsmMode {
12
- Unknown = 0,
13
- Evaluated = 1,
14
- Unlinked = 2
15
- }
16
- export interface IBasicModuleScope extends ITestEnv {
17
- console: Record<string, (...args: any[]) => void>;
18
- expect: jest.Expect;
19
- [key: string]: any;
20
- }
21
- export interface IBasicGlobalContext {
22
- console: Record<string, (...args: any[]) => void>;
23
- setTimeout: typeof setTimeout;
24
- clearTimeout: typeof clearTimeout;
25
- [key: string]: any;
26
- }
27
- export type TModuleObject = {
28
- exports: unknown;
29
- };
30
- export type THotStepRuntimeLangData = {
31
- outdatedModules: string[];
32
- outdatedDependencies: Record<string, string[]>;
33
- updatedModules: string[];
34
- updatedRuntime: string[];
35
- acceptedModules: string[];
36
- disposedModules: string[];
37
- };
38
- export type THotStepRuntimeData = {
39
- javascript: THotStepRuntimeLangData;
40
- css: THotStepRuntimeLangData;
41
- statusPath: string[];
42
- };
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EEsmMode = void 0;
4
- var EEsmMode;
5
- (function (EEsmMode) {
6
- EEsmMode[EEsmMode["Unknown"] = 0] = "Unknown";
7
- EEsmMode[EEsmMode["Evaluated"] = 1] = "Evaluated";
8
- EEsmMode[EEsmMode["Unlinked"] = 2] = "Unlinked";
9
- })(EEsmMode || (exports.EEsmMode = EEsmMode = {}));
@@ -1,7 +0,0 @@
1
- import type { ECompilerType, ITestEnv, ITestRunner, TCompilerOptions, TCompilerStatsCompilation } from "../type";
2
- import { BasicRunnerFactory } from "./basic";
3
- export declare class WatchRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
4
- protected getRunnerKey(file: string): string;
5
- protected createStatsGetter(): () => TCompilerStatsCompilation<T>;
6
- protected createRunner(file: string, stats: () => TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
7
- }
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WatchRunnerFactory = void 0;
4
- const basic_1 = require("./basic");
5
- const watch_1 = require("./runner/watch");
6
- class WatchRunnerFactory extends basic_1.BasicRunnerFactory {
7
- getRunnerKey(file) {
8
- const stepName = this.context.getValue(this.name, "watchStepName");
9
- return `${this.name}-${stepName}`;
10
- }
11
- createStatsGetter() {
12
- const compiler = this.context.getCompiler(this.name);
13
- const stepName = this.context.getValue(this.name, "watchStepName");
14
- const statsGetter = (() => {
15
- const cached = {};
16
- return () => {
17
- if (cached[stepName]) {
18
- return cached[stepName];
19
- }
20
- cached[stepName] = compiler.getStats().toJson({
21
- errorDetails: true
22
- });
23
- return cached[stepName];
24
- };
25
- })();
26
- return statsGetter;
27
- }
28
- createRunner(file, stats, compilerOptions, env) {
29
- this.context.getCompiler(this.name);
30
- const stepName = this.context.getValue(this.name, "watchStepName");
31
- if (!stepName) {
32
- throw new Error("Can not get watch step name from context");
33
- }
34
- const state = this.context.getValue(this.name, "watchState");
35
- if (!state) {
36
- throw new Error("Can not get watch state from context");
37
- }
38
- const isWeb = Array.isArray(compilerOptions)
39
- ? compilerOptions.some(option => {
40
- return option.target === "web" || option.target === "webworker";
41
- })
42
- : compilerOptions.target === "web" ||
43
- compilerOptions.target === "webworker";
44
- return new watch_1.WatchRunner({
45
- env,
46
- stats,
47
- name: this.name,
48
- state,
49
- stepName,
50
- runInNewContext: isWeb,
51
- isWeb,
52
- cachable: false,
53
- testConfig: this.context.getTestConfig(),
54
- source: this.context.getSource(),
55
- dist: this.context.getDist(),
56
- compilerOptions
57
- });
58
- }
59
- }
60
- exports.WatchRunnerFactory = WatchRunnerFactory;
@@ -1,5 +0,0 @@
1
- import type { ITestContext, ITestEnv, ITestProcessor } from "../type";
2
- export declare function getSimpleProcessorRunner(src: string, dist: string, options?: {
3
- env?: () => ITestEnv;
4
- context?: (src: string, dist: string) => ITestContext;
5
- }): (name: string, processor: ITestProcessor) => Promise<void>;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSimpleProcessorRunner = getSimpleProcessorRunner;
4
- const context_1 = require("./context");
5
- const CONTEXT_MAP = new Map();
6
- function getSimpleProcessorRunner(src, dist, options = {}) {
7
- const createEnv = options.env || (() => ({ expect, it, beforeEach, afterEach, jest }));
8
- const createContext = options.context ||
9
- ((src, dist) => new context_1.TestContext({ src, dist }));
10
- const key = `src: ${src}, dist: ${dist}`;
11
- if (!CONTEXT_MAP.has(key)) {
12
- const context = createContext(src, dist);
13
- const runner = async function run(name, processor) {
14
- try {
15
- await processor.beforeAll?.(context);
16
- await processor.before?.(context);
17
- await processor.config?.(context);
18
- await processor.compiler?.(context);
19
- await processor.build?.(context);
20
- }
21
- catch (e) {
22
- context.emitError(name, e);
23
- }
24
- finally {
25
- if (!context.hasError()) {
26
- await processor.run?.(createEnv(), context);
27
- }
28
- await processor.check?.(createEnv(), context);
29
- await processor.after?.(context);
30
- await processor.afterAll?.(context);
31
- }
32
- if (context.hasError()) {
33
- const errors = context
34
- .getError()
35
- .map(i => `${i.stack}`.split("\n").join("\t\n"))
36
- .join("\n\n");
37
- throw new Error(`Case "${name}" failed:\n${errors}`);
38
- }
39
- };
40
- CONTEXT_MAP.set(key, runner);
41
- }
42
- return CONTEXT_MAP.get(key);
43
- }
package/jest.d.ts DELETED
@@ -1,25 +0,0 @@
1
- /// <reference types="jest" />
2
-
3
- import type { DiffOptions } from "jest-diff";
4
-
5
- declare interface FileMatcherOptions {
6
- diff?: DiffOptions;
7
- }
8
-
9
- declare global {
10
- namespace jest {
11
- interface Matchers<R, T> {
12
- toMatchFileSnapshot: (
13
- filename?: string,
14
- options?: FileMatcherOptions
15
- ) => void;
16
- }
17
-
18
- interface Expect {
19
- toMatchFileSnapshot: (
20
- filename?: string,
21
- options?: FileMatcherOptions
22
- ) => void;
23
- }
24
- }
25
- }