@rspack-canary/test-tools 1.6.1-canary-d808219f-20251101173657 → 1.6.1-canary-46a54daf-20251103113814
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.
package/dist/case/esm-output.js
CHANGED
|
@@ -39,4 +39,3 @@ export declare class NodeRunner implements ITestRunner {
|
|
|
39
39
|
protected createCjsRequirer(): TRunnerRequirer;
|
|
40
40
|
protected createEsmRequirer(): TRunnerRequirer;
|
|
41
41
|
}
|
|
42
|
-
export declare const createLocatedError: (collectedErrors: Error[], offset: number) => (e: Error, file: TRunnerFile) => Error;
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.NodeRunner = void 0;
|
|
40
40
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
41
41
|
const node_path_1 = __importDefault(require("node:path"));
|
|
42
42
|
const node_url_1 = require("node:url");
|
|
@@ -45,7 +45,6 @@ const asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
|
|
|
45
45
|
const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
|
|
46
46
|
const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
|
|
47
47
|
const type_1 = require("../../type");
|
|
48
|
-
const EVAL_LOCATION_REGEX = /<anonymous>:(\d+)/;
|
|
49
48
|
const isRelativePath = (p) => /^\.\.?\//.test(p);
|
|
50
49
|
const getSubPath = (p) => {
|
|
51
50
|
const lastSlash = p.lastIndexOf("/");
|
|
@@ -347,37 +346,31 @@ class NodeRunner {
|
|
|
347
346
|
currentModuleScope.__STATS_I__ = statsIndex;
|
|
348
347
|
}
|
|
349
348
|
}
|
|
350
|
-
const createNodeLocatedError = (0, exports.createLocatedError)(this._options.errors || [], 2);
|
|
351
|
-
const originIt = currentModuleScope.it;
|
|
352
|
-
currentModuleScope.it = (description, fn) => {
|
|
353
|
-
originIt(description, async () => {
|
|
354
|
-
try {
|
|
355
|
-
await fn();
|
|
356
|
-
}
|
|
357
|
-
catch (err) {
|
|
358
|
-
throw createNodeLocatedError(err, file);
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
};
|
|
362
|
-
currentModuleScope.__CREATE_LOCATED_ERROR__ = createNodeLocatedError;
|
|
363
|
-
currentModuleScope.__FILE__ = file;
|
|
364
349
|
const args = Object.keys(currentModuleScope);
|
|
365
350
|
const argValues = args.map(arg => currentModuleScope[arg]);
|
|
366
351
|
const code = `(function(${args.join(", ")}) {
|
|
367
|
-
|
|
368
|
-
${file.content}
|
|
369
|
-
} catch(err) {
|
|
370
|
-
throw __CREATE_LOCATED_ERROR__(err, __FILE__);
|
|
371
|
-
}
|
|
352
|
+
${file.content}
|
|
372
353
|
})`;
|
|
373
354
|
this.preExecute(code, file);
|
|
374
355
|
this.log(`run mode: ${this._options.runInNewContext ? "new context" : "this context"}`);
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
356
|
+
try {
|
|
357
|
+
const fn = this._options.runInNewContext
|
|
358
|
+
? node_vm_1.default.runInNewContext(code, this.globalContext, {
|
|
359
|
+
filename: file.path,
|
|
360
|
+
lineOffset: -1
|
|
361
|
+
})
|
|
362
|
+
: node_vm_1.default.runInThisContext(code, {
|
|
363
|
+
filename: file.path,
|
|
364
|
+
lineOffset: -1
|
|
365
|
+
});
|
|
366
|
+
fn.call(this._options.testConfig.nonEsmThis
|
|
367
|
+
? this._options.testConfig.nonEsmThis(modulePath)
|
|
368
|
+
: m.exports, ...argValues);
|
|
369
|
+
}
|
|
370
|
+
catch (e) {
|
|
371
|
+
this._options.errors?.push(e);
|
|
372
|
+
throw e;
|
|
373
|
+
}
|
|
381
374
|
this.postExecute(m, file);
|
|
382
375
|
this.log(`end cjs: ${modulePath}`);
|
|
383
376
|
return m.exports;
|
|
@@ -454,29 +447,3 @@ class NodeRunner {
|
|
|
454
447
|
}
|
|
455
448
|
}
|
|
456
449
|
exports.NodeRunner = NodeRunner;
|
|
457
|
-
const createLocatedError = (collectedErrors, offset) => {
|
|
458
|
-
return (e, file) => {
|
|
459
|
-
const match = (e.stack || e.message).match(EVAL_LOCATION_REGEX);
|
|
460
|
-
if (match) {
|
|
461
|
-
const [, line] = match;
|
|
462
|
-
const realLine = Number(line) - offset;
|
|
463
|
-
const codeLines = file.content.split("\n");
|
|
464
|
-
const lineContents = [
|
|
465
|
-
...codeLines
|
|
466
|
-
.slice(Math.max(0, realLine - 3), Math.max(0, realLine - 1))
|
|
467
|
-
.map(line => `│ ${line}`),
|
|
468
|
-
`│> ${codeLines[realLine - 1]}`,
|
|
469
|
-
...codeLines.slice(realLine, realLine + 2).map(line => `│ ${line}`)
|
|
470
|
-
];
|
|
471
|
-
const message = `Error in JSDOM when running file '${file.path}' at line ${realLine}: ${e.message}\n${lineContents.join("\n")}`;
|
|
472
|
-
const finalError = new Error(message);
|
|
473
|
-
finalError.stack = undefined;
|
|
474
|
-
collectedErrors.push(finalError);
|
|
475
|
-
return finalError;
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
return e;
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
};
|
|
482
|
-
exports.createLocatedError = createLocatedError;
|
package/dist/runner/web/index.js
CHANGED
|
@@ -234,18 +234,6 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
234
234
|
return Reflect.set(target, prop, value, receiver);
|
|
235
235
|
}
|
|
236
236
|
});`;
|
|
237
|
-
const createJSDOMLocatedError = (0, node_1.createLocatedError)(this._options.errors || [], proxyCode.split("\n").length + 2);
|
|
238
|
-
const originIt = currentModuleScope.it;
|
|
239
|
-
currentModuleScope.it = (description, fn) => {
|
|
240
|
-
originIt(description, async () => {
|
|
241
|
-
try {
|
|
242
|
-
await fn();
|
|
243
|
-
}
|
|
244
|
-
catch (err) {
|
|
245
|
-
throw createJSDOMLocatedError(err, file);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
237
|
const scopeKey = (0, helper_1.escapeSep)(file.path);
|
|
250
238
|
const args = Object.keys(currentModuleScope).filter(arg => !["window", "self", "globalThis", "console"].includes(arg));
|
|
251
239
|
const argValues = args
|
|
@@ -253,18 +241,13 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
253
241
|
.join(", ");
|
|
254
242
|
this.dom.window[scopeKey] = currentModuleScope;
|
|
255
243
|
this.dom.window["__GLOBAL_SHARED__"] = this.globalContext;
|
|
256
|
-
this.dom.window["__FILE__"] = file;
|
|
257
|
-
this.dom.window["__CREATE_LOCATED_ERROR__"] = createJSDOMLocatedError;
|
|
258
244
|
return [
|
|
259
245
|
m,
|
|
260
246
|
`${proxyCode}
|
|
261
247
|
(function(window, self, globalThis, console, ${args.join(", ")}) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
throw __CREATE_LOCATED_ERROR__(err, __FILE__);
|
|
266
|
-
}
|
|
267
|
-
})($$g$$, $$self$$, $$g$$, window["console"], ${argValues});`
|
|
248
|
+
${file.content}
|
|
249
|
+
})($$g$$, $$self$$, $$g$$, window["console"], ${argValues});`,
|
|
250
|
+
proxyCode.split("\n").length + 1
|
|
268
251
|
];
|
|
269
252
|
}
|
|
270
253
|
createJSDOMRequirer() {
|
|
@@ -277,15 +260,20 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
277
260
|
if (file.path in this.requireCache) {
|
|
278
261
|
return this.requireCache[file.path].exports;
|
|
279
262
|
}
|
|
280
|
-
const [m, code] = this.getModuleContent(file);
|
|
263
|
+
const [m, code, lineOffset] = this.getModuleContent(file);
|
|
281
264
|
this.preExecute(code, file);
|
|
282
265
|
try {
|
|
283
266
|
const script = new node_vm_1.Script(code);
|
|
284
267
|
const vmContext = this.dom.getInternalVMContext();
|
|
285
|
-
script.runInContext(vmContext
|
|
268
|
+
script.runInContext(vmContext, {
|
|
269
|
+
filename: file.path,
|
|
270
|
+
lineOffset: -lineOffset
|
|
271
|
+
});
|
|
286
272
|
}
|
|
287
273
|
catch (e) {
|
|
288
|
-
|
|
274
|
+
const error = new Error(`Parse script '${file.path}' failed: ${e.message}`);
|
|
275
|
+
this._options.errors?.push(error);
|
|
276
|
+
throw error;
|
|
289
277
|
}
|
|
290
278
|
this.postExecute(m, file);
|
|
291
279
|
this.requireCache[file.path] = m;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack-canary/test-tools",
|
|
3
|
-
"version": "1.6.1-canary-
|
|
3
|
+
"version": "1.6.1-canary-46a54daf-20251103113814",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@types/jsdom": "^21.1.7",
|
|
69
69
|
"typescript": "^5.9.3",
|
|
70
70
|
"wast-loader": "^1.14.1",
|
|
71
|
-
"@rspack/core": "npm:@rspack-canary/core@1.6.1-canary-
|
|
71
|
+
"@rspack/core": "npm:@rspack-canary/core@1.6.1-canary-46a54daf-20251103113814"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@rspack/core": ">=1.0.0"
|