@rspack-canary/test-tools 1.6.0-canary-beafb11e-20251019174144 → 1.6.0-canary-0eb13821-20251021173640

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 (39) hide show
  1. package/dist/case/cache.js +3 -0
  2. package/dist/case/common.d.ts +1 -0
  3. package/dist/case/common.js +15 -12
  4. package/dist/case/config.js +4 -1
  5. package/dist/case/esm-output.js +28 -2
  6. package/dist/case/hot.d.ts +1 -1
  7. package/dist/case/hot.js +4 -3
  8. package/dist/case/incremental.d.ts +1 -1
  9. package/dist/case/incremental.js +1 -20
  10. package/dist/case/normal.js +3 -0
  11. package/dist/case/runner.d.ts +1 -1
  12. package/dist/case/runner.js +4 -3
  13. package/dist/case/watch.d.ts +3 -1
  14. package/dist/case/watch.js +5 -4
  15. package/dist/helper/hot-update/plugin.js +1 -1
  16. package/dist/helper/legacy/asModule.js +0 -2
  17. package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
  18. package/dist/helper/legacy/createLazyTestEnv.js +3 -1
  19. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  20. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  21. package/dist/helper/setup-env.js +15 -0
  22. package/dist/runner/node/index.js +7 -3
  23. package/dist/runner/web/index.d.ts +20 -7
  24. package/dist/runner/web/index.js +293 -18
  25. package/dist/test/creator.js +13 -7
  26. package/dist/test/tester.d.ts +1 -0
  27. package/dist/test/tester.js +5 -0
  28. package/dist/type.d.ts +5 -5
  29. package/dist/type.js +1 -6
  30. package/jest.d.ts +2 -0
  31. package/package.json +3 -3
  32. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  33. package/dist/helper/legacy/FakeDocument.js +0 -280
  34. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  35. package/dist/helper/legacy/walkCssTokens.js +0 -761
  36. package/dist/runner/web/fake.d.ts +0 -15
  37. package/dist/runner/web/fake.js +0 -215
  38. package/dist/runner/web/jsdom.d.ts +0 -24
  39. package/dist/runner/web/jsdom.js +0 -241
@@ -1,280 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FakeSheet = exports.FakeElement = void 0;
4
- // @ts-nocheck
5
- const fs = require("node:fs");
6
- const path = require("node:path");
7
- const getPropertyValue = function (property) {
8
- return this[property];
9
- };
10
- class FakeDocument {
11
- constructor(basePath, options = {}) {
12
- this.head = this.createElement("head");
13
- this.body = this.createElement("body");
14
- this.baseURI = "https://test.cases/path/index.html";
15
- this._elementsByTagName = new Map([
16
- ["head", [this.head]],
17
- ["body", [this.body]]
18
- ]);
19
- this._basePath = basePath;
20
- this.currentScript = undefined;
21
- this._options = options || {};
22
- }
23
- createElement(type) {
24
- return new FakeElement(this, type, this._basePath);
25
- }
26
- _onElementAttached(element) {
27
- const type = element._type;
28
- let list = this._elementsByTagName.get(type);
29
- if (list === undefined) {
30
- list = [];
31
- this._elementsByTagName.set(type, list);
32
- }
33
- list.push(element);
34
- }
35
- _onElementRemoved(element) {
36
- const type = element._type;
37
- const list = this._elementsByTagName.get(type);
38
- const idx = list.indexOf(element);
39
- list.splice(idx, 1);
40
- }
41
- getElementsByTagName(name) {
42
- return this._elementsByTagName.get(name) || [];
43
- }
44
- querySelectorAll(name) {
45
- return this._elementsByTagName.get(name) || [];
46
- }
47
- getComputedStyle(element) {
48
- const style = { getPropertyValue };
49
- const links = this.getElementsByTagName("link");
50
- for (const link of links) {
51
- for (const rule of link.sheet.cssRules) {
52
- if (rule.selectorText === element._type) {
53
- Object.assign(style, rule.style);
54
- }
55
- }
56
- }
57
- return style;
58
- }
59
- }
60
- exports.default = FakeDocument;
61
- class FakeElement {
62
- constructor(document, type, basePath) {
63
- this._document = document;
64
- this._type = type;
65
- this._basePath = basePath;
66
- this._children = [];
67
- this._attributes = Object.create(null);
68
- this._src = undefined;
69
- this._href = undefined;
70
- this.rel = undefined;
71
- this.parentNode = undefined;
72
- this.sheet = type === "link" ? new FakeSheet(this, basePath) : undefined;
73
- }
74
- cloneNode() {
75
- return new FakeElement(this._document, this._type, this._basePath);
76
- }
77
- addEventListener() { }
78
- insertBefore(node, before) {
79
- this._document._onElementAttached(node);
80
- node.parentNode = this;
81
- this._children.unshift(node);
82
- Promise.resolve().then(() => {
83
- if (node.onload) {
84
- node.onload({ type: "load", target: node });
85
- }
86
- });
87
- }
88
- appendChild(node) {
89
- this._document._onElementAttached(node);
90
- this._children.push(node);
91
- node.parentNode = this;
92
- if (node._type === "link") {
93
- setTimeout(() => {
94
- if (node.onload)
95
- node.onload({ type: "load", target: node });
96
- }, 100);
97
- }
98
- else if (node._type === "script") {
99
- Promise.resolve().then(() => {
100
- if (typeof this._document._options.onScript === "function") {
101
- this._document._options.onScript(node);
102
- }
103
- if (node.onload) {
104
- node.onload({
105
- type: "load",
106
- target: node
107
- });
108
- }
109
- });
110
- }
111
- else {
112
- if (node.onload) {
113
- node.onload({ type: "load", target: node });
114
- }
115
- }
116
- }
117
- removeChild(node) {
118
- const idx = this._children.indexOf(node);
119
- if (idx >= 0) {
120
- this._children.splice(idx, 1);
121
- this._document._onElementRemoved(node);
122
- node.parentNode = undefined;
123
- }
124
- }
125
- setAttribute(name, value) {
126
- if (this._type === "link" && name === "href") {
127
- this.href(value);
128
- }
129
- else {
130
- this._attributes[name] = value;
131
- }
132
- }
133
- removeAttribute(name) {
134
- delete this._attributes[name];
135
- }
136
- getAttribute(name) {
137
- if (this._type === "link" && name === "href") {
138
- return this.href;
139
- }
140
- return this._attributes[name];
141
- }
142
- _toRealUrl(value) {
143
- if (/^\//.test(value)) {
144
- return `https://test.cases${value}`;
145
- }
146
- else if (/^\.\.\//.test(value)) {
147
- return `https://test.cases${value.slice(2)}`;
148
- }
149
- else if (/^\.\//.test(value)) {
150
- return `https://test.cases/path${value.slice(1)}`;
151
- }
152
- else if (/^\w+:\/\//.test(value)) {
153
- return value;
154
- }
155
- else if (/^\/\//.test(value)) {
156
- return `https:${value}`;
157
- }
158
- else {
159
- return `https://test.cases/path/${value}`;
160
- }
161
- }
162
- set src(value) {
163
- if (this._type === "script") {
164
- this._src = this._toRealUrl(value);
165
- }
166
- }
167
- get children() {
168
- return this._children;
169
- }
170
- get src() {
171
- return this._src;
172
- }
173
- set href(value) {
174
- if (this._type === "link") {
175
- this._href = this._toRealUrl(value);
176
- }
177
- }
178
- get href() {
179
- return this._href;
180
- }
181
- }
182
- exports.FakeElement = FakeElement;
183
- class FakeSheet {
184
- constructor(element, basePath) {
185
- this._element = element;
186
- this._basePath = basePath;
187
- this.cachedCss = undefined;
188
- this.cachedCssRules = undefined;
189
- }
190
- get css() {
191
- if (this.cachedCss) {
192
- return this.cachedCss;
193
- }
194
- let css = fs.readFileSync(path.resolve(this._basePath, this._element.href
195
- .replace(/^https:\/\/test\.cases\/path\//, "")
196
- .replace(/^https:\/\/example\.com\//, "")), "utf-8");
197
- css = css.replace(/@import url\("([^"]+)"\);/g, (match, url) => {
198
- if (!/^https:\/\/test\.cases\/path\//.test(url)) {
199
- return `@import url("${url}");`;
200
- }
201
- if (url.startsWith("#")) {
202
- return url;
203
- }
204
- return fs.readFileSync(path.resolve(this._basePath, url.replace(/^https:\/\/test\.cases\/path\//, "")), "utf-8");
205
- });
206
- this.cachedCss = css;
207
- return css;
208
- }
209
- get cssRules() {
210
- if (this.cachedCssRules) {
211
- return this.cachedCssRules;
212
- }
213
- const walkCssTokens = require("./walkCssTokens");
214
- const rules = [];
215
- let currentRule = { getPropertyValue };
216
- let selector = undefined;
217
- let last = 0;
218
- const processDeclaration = str => {
219
- const colon = str.indexOf(":");
220
- if (colon > 0) {
221
- const property = str.slice(0, colon).trim();
222
- const value = str.slice(colon + 1);
223
- currentRule[property] = value;
224
- }
225
- };
226
- let filepath = /file:\/\//.test(this._element.href)
227
- ? new URL(this._element.href).pathname
228
- : path.resolve(this._basePath, this._element.href
229
- .replace(/^https:\/\/test\.cases\/path\//, "")
230
- .replace(/^https:\/\/example\.com\/public\/path\//, "")
231
- .replace(/^https:\/\/example\.com\//, ""));
232
- if (require("os").platform() === "win32" && filepath.startsWith("/")) {
233
- filepath = filepath.slice(1);
234
- }
235
- let css = fs.readFileSync(filepath.replace(/\?hmr=\d*/, ""), "utf-8");
236
- css = css.replace(/@import url\("([^"]+)"\);/g, (match, url) => {
237
- if (!/^https:\/\/test\.cases\/path\//.test(url)) {
238
- return url;
239
- }
240
- if (url.startsWith("#")) {
241
- return url;
242
- }
243
- return fs.readFileSync(path.resolve(this._basePath, url.replace(/^https:\/\/test\.cases\/path\//, "")), "utf-8");
244
- })
245
- .replace(/\/\*[\s\S]*?\*\//g, '');
246
- walkCssTokens(css, {
247
- isSelector() {
248
- return selector === undefined;
249
- },
250
- leftCurlyBracket(source, start, end) {
251
- if (selector === undefined) {
252
- selector = source.slice(last, start).trim();
253
- last = end;
254
- }
255
- return end;
256
- },
257
- rightCurlyBracket(source, start, end) {
258
- processDeclaration(source.slice(last, start));
259
- rules.push({
260
- selectorText: selector,
261
- style: currentRule,
262
- // hack cssText, css hmr needs this fields to detect changes
263
- cssText: css
264
- });
265
- last = end;
266
- selector = undefined;
267
- currentRule = { getPropertyValue };
268
- return end;
269
- },
270
- semicolon(source, start, end) {
271
- processDeclaration(source.slice(last, start));
272
- last = end;
273
- return end;
274
- }
275
- });
276
- this.cachedCssRules = rules;
277
- return rules;
278
- }
279
- }
280
- exports.FakeSheet = FakeSheet;
@@ -1,40 +0,0 @@
1
- declare namespace _exports {
2
- export { CssTokenCallbacks, CharHandler };
3
- }
4
- declare function _exports(input: string, callbacks: CssTokenCallbacks): void;
5
- declare namespace _exports {
6
- export { isIdentStartCodePoint };
7
- export function eatComments(input: string, pos: number): number;
8
- export function eatWhitespace(input: string, pos: number): number;
9
- export function eatWhitespaceAndComments(input: string, pos: number): number;
10
- export function eatWhiteLine(input: string, pos: number): number;
11
- }
12
- export = _exports;
13
- type CssTokenCallbacks = {
14
- isSelector?: ((arg0: string, arg1: number) => boolean) | undefined;
15
- url?: ((arg0: string, arg1: number, arg2: number, arg3: number, arg4: number) => number) | undefined;
16
- string?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
17
- leftParenthesis?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
18
- rightParenthesis?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
19
- pseudoFunction?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
20
- function?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
21
- pseudoClass?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
22
- atKeyword?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
23
- class?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
24
- identifier?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
25
- id?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
26
- leftCurlyBracket?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
27
- rightCurlyBracket?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
28
- semicolon?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
29
- comma?: ((arg0: string, arg1: number, arg2: number) => number) | undefined;
30
- };
31
- type CharHandler = (arg0: string, arg1: number, arg2: CssTokenCallbacks) => number;
32
- /**
33
- * ident-start code point
34
- *
35
- * A letter, a non-ASCII code point, or U+005F LOW LINE (_).
36
- *
37
- * @param {number} cc char code
38
- * @returns {boolean} true, if cc is a start code point of an identifier
39
- */
40
- declare function isIdentStartCodePoint(cc: number): boolean;