@rspack/test-tools 1.6.0-beta.0 → 1.6.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 (118) hide show
  1. package/dist/case/builtin.d.ts +3 -2
  2. package/dist/case/builtin.js +1 -1
  3. package/dist/case/cache.d.ts +2 -2
  4. package/dist/case/cache.js +13 -9
  5. package/dist/case/common.d.ts +11 -10
  6. package/dist/case/common.js +49 -43
  7. package/dist/case/compiler.d.ts +9 -8
  8. package/dist/case/compiler.js +5 -6
  9. package/dist/case/config.d.ts +6 -5
  10. package/dist/case/config.js +4 -1
  11. package/dist/case/defaults.d.ts +5 -4
  12. package/dist/case/defaults.js +10 -10
  13. package/dist/case/diagnostic.js +5 -6
  14. package/dist/case/error.d.ts +5 -5
  15. package/dist/case/error.js +7 -8
  16. package/dist/case/esm-output.js +30 -9
  17. package/dist/case/example.js +2 -2
  18. package/dist/case/hash.d.ts +2 -2
  19. package/dist/case/hash.js +1 -1
  20. package/dist/case/hook.d.ts +4 -3
  21. package/dist/case/hook.js +3 -2
  22. package/dist/case/hot-step.d.ts +2 -2
  23. package/dist/case/hot-step.js +4 -9
  24. package/dist/case/hot.d.ts +5 -4
  25. package/dist/case/hot.js +37 -49
  26. package/dist/case/incremental.d.ts +2 -2
  27. package/dist/case/incremental.js +1 -20
  28. package/dist/case/index.d.ts +0 -1
  29. package/dist/case/index.js +1 -3
  30. package/dist/case/multi-compiler.d.ts +9 -8
  31. package/dist/case/multi-compiler.js +3 -4
  32. package/dist/case/normal.js +5 -2
  33. package/dist/case/runner.d.ts +5 -4
  34. package/dist/case/runner.js +16 -11
  35. package/dist/case/serial.d.ts +2 -2
  36. package/dist/case/serial.js +1 -1
  37. package/dist/case/stats-api.d.ts +6 -5
  38. package/dist/case/stats-api.js +5 -7
  39. package/dist/case/stats-output.d.ts +3 -2
  40. package/dist/case/stats-output.js +1 -1
  41. package/dist/case/treeshaking.js +1 -1
  42. package/dist/case/watch.d.ts +8 -6
  43. package/dist/case/watch.js +21 -19
  44. package/dist/compiler.d.ts +16 -17
  45. package/dist/compiler.js +116 -16
  46. package/dist/helper/hot-update/loader.d.ts +2 -1
  47. package/dist/helper/hot-update/loader.js +5 -30
  48. package/dist/helper/hot-update/plugin.js +10 -14
  49. package/dist/helper/index.d.ts +1 -0
  50. package/dist/helper/index.js +1 -0
  51. package/dist/helper/legacy/asModule.js +0 -2
  52. package/dist/helper/legacy/checkArrayExpectation.js +1 -1
  53. package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
  54. package/dist/helper/legacy/createLazyTestEnv.js +4 -3
  55. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  56. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  57. package/dist/helper/read-config-file.d.ts +3 -2
  58. package/dist/helper/read-config-file.js +12 -2
  59. package/dist/helper/setup-env.js +19 -2
  60. package/dist/helper/stringify-config.d.ts +2 -0
  61. package/dist/helper/stringify-config.js +43 -0
  62. package/dist/helper/util/expectWarningFactory.js +2 -4
  63. package/dist/index.d.ts +0 -1
  64. package/dist/index.js +0 -1
  65. package/dist/plugin/index.d.ts +0 -3
  66. package/dist/plugin/index.js +0 -3
  67. package/dist/runner/node/index.d.ts +13 -8
  68. package/dist/runner/node/index.js +88 -10
  69. package/dist/runner/web/index.d.ts +24 -10
  70. package/dist/runner/web/index.js +286 -18
  71. package/dist/test/context.d.ts +15 -16
  72. package/dist/test/context.js +44 -59
  73. package/dist/test/creator.d.ts +14 -14
  74. package/dist/test/creator.js +17 -12
  75. package/dist/test/debug.d.ts +15 -0
  76. package/dist/test/debug.js +205 -0
  77. package/dist/test/tester.d.ts +1 -0
  78. package/dist/test/tester.js +23 -4
  79. package/dist/type.d.ts +42 -55
  80. package/dist/type.js +1 -11
  81. package/jest.d.ts +2 -0
  82. package/package.json +10 -48
  83. package/dist/case/diff.d.ts +0 -19
  84. package/dist/case/diff.js +0 -274
  85. package/dist/compare/comparator.d.ts +0 -17
  86. package/dist/compare/comparator.js +0 -52
  87. package/dist/compare/compare.d.ts +0 -17
  88. package/dist/compare/compare.js +0 -178
  89. package/dist/compare/format-code.d.ts +0 -16
  90. package/dist/compare/format-code.js +0 -244
  91. package/dist/compare/index.d.ts +0 -5
  92. package/dist/compare/index.js +0 -21
  93. package/dist/compare/replace-module-argument.d.ts +0 -1
  94. package/dist/compare/replace-module-argument.js +0 -8
  95. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  96. package/dist/compare/replace-runtime-module-name.js +0 -71
  97. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  98. package/dist/helper/legacy/FakeDocument.js +0 -280
  99. package/dist/helper/legacy/update.d.ts +0 -2
  100. package/dist/helper/legacy/update.esm.d.ts +0 -1
  101. package/dist/helper/legacy/update.esm.js +0 -23
  102. package/dist/helper/legacy/update.js +0 -19
  103. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  104. package/dist/helper/legacy/walkCssTokens.js +0 -761
  105. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  106. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  107. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  108. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  109. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  110. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  111. package/dist/runner/web/fake.d.ts +0 -15
  112. package/dist/runner/web/fake.js +0 -216
  113. package/dist/runner/web/jsdom.d.ts +0 -24
  114. package/dist/runner/web/jsdom.js +0 -224
  115. package/template/diff.bundle.css +0 -1
  116. package/template/diff.bundle.js +0 -144
  117. package/template/diff.html +0 -14
  118. package/template/editor.worker.js +0 -1
@@ -1,224 +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 EventSourceForNode_1 = __importDefault(require("../../helper/legacy/EventSourceForNode"));
12
- const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
13
- const node_1 = require("../node");
14
- // Compatibility code to suppress iconv-lite warnings
15
- require("iconv-lite").skipDecodeWarning = true;
16
- class JSDOMWebRunner extends node_1.NodeRunner {
17
- constructor(_webOptions) {
18
- super(_webOptions);
19
- this._webOptions = _webOptions;
20
- const virtualConsole = new jsdom_1.VirtualConsole();
21
- virtualConsole.sendTo(console);
22
- this.dom = new jsdom_1.JSDOM(`
23
- <!doctype html>
24
- <html>
25
- <head></head>
26
- <body></body>
27
- </html>
28
- `, {
29
- url: "https://test.cases/path/index.html",
30
- resources: this.createResourceLoader(),
31
- runScripts: "dangerously",
32
- virtualConsole
33
- });
34
- this.dom.window.console = console;
35
- // compat with FakeDocument
36
- this.dom.window.eval(`
37
- Object.defineProperty(document.head, "_children", {
38
- get: function() {
39
- return Array.from(document.head.children).map(function(ele) {
40
- var type = ele.tagName.toLowerCase();
41
- return new Proxy(ele, {
42
- get(target, prop, receiver) {
43
- if (prop === "_type") {
44
- return target.tagName.toLowerCase();
45
- }
46
- if (prop === "_href") {
47
- return Reflect.get(target, "href", receiver);
48
- }
49
- return Reflect.get(target, prop, receiver);
50
- },
51
- });
52
- });
53
- }
54
- });
55
- `);
56
- const vmContext = this.dom.getInternalVMContext();
57
- vmContext.global = {};
58
- }
59
- run(file) {
60
- if (!file.endsWith(".js") && !file.endsWith(".mjs")) {
61
- const cssElement = this.dom.window.document.createElement("link");
62
- cssElement.href = file;
63
- cssElement.rel = "stylesheet";
64
- this.dom.window.document.head.appendChild(cssElement);
65
- return Promise.resolve();
66
- }
67
- return super.run(file);
68
- }
69
- getGlobal(name) {
70
- return this.dom.window[name];
71
- }
72
- createResourceLoader() {
73
- const urlToPath = (url) => {
74
- return node_path_1.default
75
- .resolve(this._webOptions.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`)
76
- .split("?")[0];
77
- };
78
- const that = this;
79
- class CustomResourceLoader extends jsdom_1.ResourceLoader {
80
- fetch(url, _) {
81
- const filePath = urlToPath(url);
82
- let finalCode;
83
- if (node_path_1.default.extname(filePath) === ".js") {
84
- const currentDirectory = node_path_1.default.dirname(filePath);
85
- const file = that.getFile(filePath, currentDirectory);
86
- if (!file) {
87
- throw new Error(`File not found: ${filePath}`);
88
- }
89
- const [_scope, _m, code] = that.getModuleContent(file);
90
- finalCode = code;
91
- }
92
- else {
93
- finalCode = node_fs_1.default.readFileSync(filePath);
94
- }
95
- try {
96
- return Promise.resolve(finalCode);
97
- }
98
- catch (err) {
99
- console.error(err);
100
- if (err.code === "ENOENT") {
101
- return null;
102
- }
103
- throw err;
104
- }
105
- }
106
- }
107
- return new CustomResourceLoader();
108
- }
109
- createBaseModuleScope() {
110
- const moduleScope = super.createBaseModuleScope();
111
- moduleScope.EventSource = EventSourceForNode_1.default;
112
- const urlToPath = (url) => {
113
- return node_path_1.default.resolve(this._webOptions.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`);
114
- };
115
- moduleScope.fetch = async (url) => {
116
- try {
117
- const buffer = await new Promise((resolve, reject) => node_fs_1.default.readFile(urlToPath(url), (err, b) => err ? reject(err) : resolve(b)));
118
- return {
119
- status: 200,
120
- ok: true,
121
- json: async () => JSON.parse(buffer.toString("utf-8"))
122
- };
123
- }
124
- catch (err) {
125
- if (err.code === "ENOENT") {
126
- return {
127
- status: 404,
128
- ok: false
129
- };
130
- }
131
- throw err;
132
- }
133
- };
134
- moduleScope.URL = URL;
135
- moduleScope.importScripts = (url) => {
136
- this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
137
- this.requirers.get("entry")(this._options.dist, (0, urlToRelativePath_1.default)(url));
138
- };
139
- moduleScope.getComputedStyle = function () {
140
- const computedStyle = this.dom.window.getComputedStyle(this.dom.window);
141
- const getPropertyValue = computedStyle.getPropertyValue.bind(computedStyle);
142
- return {
143
- ...computedStyle,
144
- getPropertyValue(v) {
145
- return getPropertyValue(v);
146
- }
147
- };
148
- };
149
- return moduleScope;
150
- }
151
- getModuleContent(file) {
152
- const m = {
153
- exports: {}
154
- };
155
- const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
156
- if (this._options.testConfig.moduleScope) {
157
- this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
158
- }
159
- const scopeKey = (0, helper_1.escapeSep)(file.path);
160
- const args = Object.keys(currentModuleScope).filter(arg => !["window", "self", "globalThis", "console"].includes(arg));
161
- const argValues = args
162
- .map(arg => `window["${scopeKey}"]["${arg}"]`)
163
- .join(", ");
164
- this.dom.window[scopeKey] = currentModuleScope;
165
- return [
166
- this.dom.window[scopeKey],
167
- m,
168
- `
169
- // hijack document.currentScript for auto public path
170
- var $$g$$ = new Proxy(window, {
171
- get(target, prop, receiver) {
172
- if (prop === "document") {
173
- return new Proxy(window.document, {
174
- get(target, prop, receiver) {
175
- if (prop === "currentScript") {
176
- var script = target.createElement("script");
177
- script.src = "https://test.cases/path/${(0, helper_1.escapeSep)(file.subPath)}index.js";
178
- return script;
179
- }
180
- return Reflect.get(target, prop, receiver);
181
- }
182
- });
183
- }
184
- return Reflect.get(target, prop, receiver);
185
- }
186
- });
187
- (function(window, self, globalThis, console, ${args.join(", ")}) {
188
- ${file.content}
189
- })($$g$$, $$g$$, $$g$$, window["console"], ${argValues});
190
- `
191
- ];
192
- }
193
- createJSDOMRequirer() {
194
- return (currentDirectory, modulePath, context = {}) => {
195
- const file = context.file || this.getFile(modulePath, currentDirectory);
196
- if (!file) {
197
- return this.requirers.get("miss")(currentDirectory, modulePath);
198
- }
199
- if (file.path in this.requireCache) {
200
- return this.requireCache[file.path].exports;
201
- }
202
- const [scope, m, code] = this.getModuleContent(file);
203
- if (code.includes("__STATS__")) {
204
- scope.__STATS__ = this._options.stats?.();
205
- }
206
- if (code.includes("__STATS_I__")) {
207
- const statsIndex = this._options.stats?.()?.__index__;
208
- if (typeof statsIndex === "number") {
209
- scope.__STATS_I__ = statsIndex;
210
- }
211
- }
212
- this.preExecute(code, file);
213
- this.dom.window.eval(code);
214
- this.postExecute(m, file);
215
- this.requireCache[file.path] = m;
216
- return m.exports;
217
- };
218
- }
219
- createRunner() {
220
- super.createRunner();
221
- this.requirers.set("cjs", this.createJSDOMRequirer());
222
- }
223
- }
224
- exports.JSDOMWebRunner = JSDOMWebRunner;