@rspack/test-tools 1.5.3 → 1.5.5
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/compiler.d.ts +11 -2
- package/dist/case/compiler.js +111 -8
- package/dist/case/config.js +2 -2
- package/dist/case/normal.d.ts +1 -0
- package/dist/case/normal.js +27 -15
- package/dist/case/serial.js +2 -2
- package/dist/compiler.d.ts +4 -3
- package/dist/compiler.js +7 -2
- package/dist/helper/expect/placeholder.js +1 -1
- package/dist/helper/legacy/FakeDocument.js +6 -4
- package/dist/helper/legacy/createFakeWorker.d.ts +1 -1
- package/dist/helper/legacy/createFakeWorker.js +44 -20
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
- package/dist/helper/legacy/deprecationTracking.js +41 -0
- package/dist/helper/legacy/expectSource.d.ts +10 -0
- package/dist/helper/legacy/expectSource.js +23 -0
- package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
- package/dist/helper/legacy/findOutputFiles.js +14 -0
- package/dist/helper/legacy/regexEscape.d.ts +2 -0
- package/dist/helper/legacy/regexEscape.js +5 -0
- package/dist/helper/legacy/supportDefaultAssignment.d.ts +2 -0
- package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
- package/dist/helper/legacy/supportsBlob.d.ts +2 -0
- package/dist/helper/legacy/supportsBlob.js +10 -0
- package/dist/helper/legacy/supportsClassFields.d.ts +2 -0
- package/dist/helper/legacy/supportsClassFields.js +11 -0
- package/dist/helper/legacy/supportsES6.d.ts +2 -0
- package/dist/helper/legacy/supportsES6.js +11 -0
- package/dist/helper/legacy/supportsForOf.d.ts +2 -0
- package/dist/helper/legacy/supportsForOf.js +11 -0
- package/dist/helper/legacy/supportsIteratorDestructuring.d.ts +2 -0
- package/dist/helper/legacy/supportsIteratorDestructuring.js +11 -0
- package/dist/helper/legacy/supportsLogicalAssignment.d.ts +2 -0
- package/dist/helper/legacy/supportsLogicalAssignment.js +11 -0
- package/dist/helper/legacy/supportsObjectDestructuring.d.ts +2 -0
- package/dist/helper/legacy/supportsObjectDestructuring.js +11 -0
- package/dist/helper/legacy/supportsOptionalCatchBinding.d.ts +2 -0
- package/dist/helper/legacy/supportsOptionalCatchBinding.js +11 -0
- package/dist/helper/legacy/supportsOptionalChaining.d.ts +2 -0
- package/dist/helper/legacy/supportsOptionalChaining.js +11 -0
- package/dist/helper/legacy/supportsRequireInModule.d.ts +2 -0
- package/dist/helper/legacy/supportsRequireInModule.js +5 -0
- package/dist/helper/legacy/supportsResponse.d.ts +2 -0
- package/dist/helper/legacy/supportsResponse.js +10 -0
- package/dist/helper/legacy/supportsSpread.d.ts +2 -0
- package/dist/helper/legacy/supportsSpread.js +12 -0
- package/dist/helper/legacy/supportsTemplateStrings.d.ts +2 -0
- package/dist/helper/legacy/supportsTemplateStrings.js +11 -0
- package/dist/helper/legacy/supportsUsing.d.ts +2 -0
- package/dist/helper/legacy/supportsUsing.js +26 -0
- package/dist/helper/legacy/supportsWebAssembly.d.ts +2 -0
- package/dist/helper/legacy/supportsWebAssembly.js +10 -0
- package/dist/helper/legacy/supportsWorker.d.ts +2 -0
- package/dist/helper/legacy/supportsWorker.js +17 -0
- package/dist/helper/legacy/urlToRelativePath.js +5 -2
- package/dist/processor/basic.js +5 -5
- package/dist/processor/config.js +5 -0
- package/dist/processor/error.js +1 -1
- package/dist/processor/hook.js +2 -2
- package/dist/processor/hot.d.ts +1 -1
- package/dist/processor/hot.js +6 -2
- package/dist/processor/normal.js +21 -2
- package/dist/processor/simple.d.ts +1 -0
- package/dist/processor/simple.js +3 -1
- package/dist/processor/watch.js +1 -1
- package/dist/runner/cache.js +1 -1
- package/dist/runner/hot-step.js +1 -1
- package/dist/runner/hot.js +1 -1
- package/dist/runner/multiple.js +16 -2
- package/dist/runner/runner/basic.js +13 -11
- package/dist/runner/runner/cjs.d.ts +2 -0
- package/dist/runner/runner/cjs.js +42 -13
- package/dist/runner/runner/esm.js +3 -0
- package/dist/runner/runner/normal.js +4 -1
- package/dist/runner/runner/web/fake.d.ts +0 -1
- package/dist/runner/runner/web/fake.js +0 -12
- package/dist/runner/runner/web/jsdom.d.ts +0 -1
- package/dist/runner/runner/web/jsdom.js +1 -2
- package/dist/test/creator.js +1 -1
- package/dist/type.d.ts +11 -9
- package/package.json +22 -24
package/dist/case/compiler.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { type ISimpleProcessorOptions } from "../processor";
|
|
2
|
-
import { ECompilerType } from "../type";
|
|
3
|
-
export type TCompilerCaseConfig = Omit<ISimpleProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
|
|
2
|
+
import { ECompilerType, type ITestContext, type TCompilation, type TCompiler, type TCompilerStatsCompilation } from "../type";
|
|
3
|
+
export type TCompilerCaseConfig = Omit<ISimpleProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType" | "check"> & {
|
|
4
4
|
description: string;
|
|
5
|
+
error?: boolean;
|
|
6
|
+
skip?: boolean;
|
|
7
|
+
check?: ({ context, stats, files, compiler, compilation }: {
|
|
8
|
+
context: ITestContext;
|
|
9
|
+
stats?: TCompilerStatsCompilation<ECompilerType.Rspack>;
|
|
10
|
+
files?: Record<string, string>;
|
|
11
|
+
compiler: TCompiler<ECompilerType.Rspack>;
|
|
12
|
+
compilation?: TCompilation<ECompilerType.Rspack>;
|
|
13
|
+
}) => Promise<void>;
|
|
5
14
|
};
|
|
6
15
|
export declare function createCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
|
package/dist/case/compiler.js
CHANGED
|
@@ -5,13 +5,116 @@ const processor_1 = require("../processor");
|
|
|
5
5
|
const simple_1 = require("../test/simple");
|
|
6
6
|
const type_1 = require("../type");
|
|
7
7
|
function createCompilerCase(name, src, dist, testConfig) {
|
|
8
|
-
|
|
8
|
+
let caseConfigList = require(testConfig);
|
|
9
|
+
if (!Array.isArray(caseConfigList)) {
|
|
10
|
+
caseConfigList = [caseConfigList];
|
|
11
|
+
}
|
|
9
12
|
const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
for (const caseConfig of caseConfigList) {
|
|
14
|
+
const testFn = caseConfig.skip ? it.skip : it;
|
|
15
|
+
testFn(caseConfig.description, async () => {
|
|
16
|
+
const logs = {
|
|
17
|
+
mkdir: [],
|
|
18
|
+
writeFile: []
|
|
19
|
+
};
|
|
20
|
+
const files = {};
|
|
21
|
+
await runner(name, new processor_1.SimpleTaskProcessor({
|
|
22
|
+
name: name,
|
|
23
|
+
compilerType: type_1.ECompilerType.Rspack,
|
|
24
|
+
compilerCallback: caseConfig.compilerCallback,
|
|
25
|
+
build: caseConfig.build,
|
|
26
|
+
options: context => {
|
|
27
|
+
const options = caseConfig.options?.(context) || {};
|
|
28
|
+
options.mode ??= "production";
|
|
29
|
+
options.context ??= context.getSource();
|
|
30
|
+
options.entry ??= "./a.js";
|
|
31
|
+
options.output ??= {};
|
|
32
|
+
options.output.path ??= "/";
|
|
33
|
+
options.output.pathinfo ??= true;
|
|
34
|
+
options.optimization ??= {};
|
|
35
|
+
options.optimization.minimize ??= false;
|
|
36
|
+
return options;
|
|
37
|
+
},
|
|
38
|
+
async compiler(context, compiler) {
|
|
39
|
+
compiler.outputFileSystem = {
|
|
40
|
+
// CHANGE: Added support for the `options` parameter to enable recursive directory creation,
|
|
41
|
+
// accommodating Rspack's requirement that differs from webpack's usage
|
|
42
|
+
mkdir(path, callback) {
|
|
43
|
+
const recursive = false;
|
|
44
|
+
// if (typeof options === "function") {
|
|
45
|
+
// callback = options;
|
|
46
|
+
// } else if (options) {
|
|
47
|
+
// if (options.recursive !== undefined) recursive = options.recursive;
|
|
48
|
+
// }
|
|
49
|
+
logs.mkdir.push(path);
|
|
50
|
+
if (recursive) {
|
|
51
|
+
callback();
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const err = new Error();
|
|
55
|
+
err.code = "EEXIST";
|
|
56
|
+
callback(err);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
writeFile(name, content, callback) {
|
|
60
|
+
logs.writeFile.push(name, content);
|
|
61
|
+
files[name] = content.toString("utf-8");
|
|
62
|
+
callback();
|
|
63
|
+
},
|
|
64
|
+
stat(path, callback) {
|
|
65
|
+
callback(new Error("ENOENT"));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
compiler.hooks.compilation.tap("CompilerTest", compilation => (compilation.bail = true));
|
|
69
|
+
await caseConfig.compiler?.(context, compiler);
|
|
70
|
+
},
|
|
71
|
+
async check(context, compiler, stats) {
|
|
72
|
+
if (caseConfig.error) {
|
|
73
|
+
const statsJson = stats?.toJson({
|
|
74
|
+
modules: true,
|
|
75
|
+
reasons: true
|
|
76
|
+
});
|
|
77
|
+
const compilation = stats?.compilation;
|
|
78
|
+
await caseConfig.check?.({
|
|
79
|
+
context,
|
|
80
|
+
compiler,
|
|
81
|
+
stats: statsJson,
|
|
82
|
+
compilation,
|
|
83
|
+
files
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else if (stats) {
|
|
87
|
+
expect(typeof stats).toBe("object");
|
|
88
|
+
const compilation = stats.compilation;
|
|
89
|
+
const statsJson = stats.toJson({
|
|
90
|
+
modules: true,
|
|
91
|
+
reasons: true
|
|
92
|
+
});
|
|
93
|
+
expect(typeof statsJson).toBe("object");
|
|
94
|
+
expect(statsJson).toHaveProperty("errors");
|
|
95
|
+
expect(Array.isArray(statsJson.errors)).toBe(true);
|
|
96
|
+
if (statsJson.errors.length > 0) {
|
|
97
|
+
expect(statsJson.errors[0]).toBeInstanceOf(Object);
|
|
98
|
+
throw statsJson.errors[0];
|
|
99
|
+
}
|
|
100
|
+
statsJson.logs = logs;
|
|
101
|
+
await caseConfig.check?.({
|
|
102
|
+
context,
|
|
103
|
+
stats: statsJson,
|
|
104
|
+
files,
|
|
105
|
+
compiler,
|
|
106
|
+
compilation
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
await caseConfig.check?.({
|
|
111
|
+
context,
|
|
112
|
+
files,
|
|
113
|
+
compiler
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
17
120
|
}
|
package/dist/case/config.js
CHANGED
|
@@ -10,11 +10,11 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
10
10
|
describe: false,
|
|
11
11
|
testConfig: testConfig => {
|
|
12
12
|
const oldModuleScope = testConfig.moduleScope;
|
|
13
|
-
testConfig.moduleScope = (ms, stats) => {
|
|
13
|
+
testConfig.moduleScope = (ms, stats, compilerOptions) => {
|
|
14
14
|
let res = ms;
|
|
15
15
|
// TODO: modify runner module scope based on stats here
|
|
16
16
|
if (typeof oldModuleScope === "function") {
|
|
17
|
-
res = oldModuleScope(ms, stats);
|
|
17
|
+
res = oldModuleScope(ms, stats, compilerOptions);
|
|
18
18
|
}
|
|
19
19
|
return res;
|
|
20
20
|
};
|
package/dist/case/normal.d.ts
CHANGED
package/dist/case/normal.js
CHANGED
|
@@ -4,26 +4,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createNormalCase = createNormalCase;
|
|
7
|
+
exports.createHotNormalCase = createHotNormalCase;
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const core_1 = require("@rspack/core");
|
|
8
10
|
const normal_1 = require("../processor/normal");
|
|
9
11
|
const runner_1 = require("../runner");
|
|
10
12
|
const creator_1 = require("../test/creator");
|
|
11
13
|
const type_1 = require("../type");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})
|
|
14
|
+
const NORMAL_CASES_ROOT = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/normalCases");
|
|
15
|
+
const createCaseOptions = (hot) => {
|
|
16
|
+
return {
|
|
17
|
+
clean: true,
|
|
18
|
+
describe: false,
|
|
19
|
+
steps: ({ name }) => [
|
|
20
|
+
new normal_1.NormalProcessor({
|
|
21
|
+
name,
|
|
22
|
+
root: NORMAL_CASES_ROOT,
|
|
23
|
+
compilerOptions: {
|
|
24
|
+
plugins: hot ? [new core_1.HotModuleReplacementPlugin()] : []
|
|
25
|
+
},
|
|
26
|
+
runable: true,
|
|
27
|
+
compilerType: type_1.ECompilerType.Rspack
|
|
28
|
+
})
|
|
29
|
+
],
|
|
30
|
+
runner: runner_1.NormalRunnerFactory,
|
|
31
|
+
concurrent: true
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const creator = new creator_1.BasicCaseCreator(createCaseOptions(false));
|
|
27
35
|
function createNormalCase(name, src, dist) {
|
|
28
36
|
creator.create(name, src, dist);
|
|
29
37
|
}
|
|
38
|
+
const hotCreator = new creator_1.BasicCaseCreator(createCaseOptions(true));
|
|
39
|
+
function createHotNormalCase(name, src, dist) {
|
|
40
|
+
hotCreator.create(name, src, dist);
|
|
41
|
+
}
|
package/dist/case/serial.js
CHANGED
|
@@ -10,11 +10,11 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
10
10
|
describe: false,
|
|
11
11
|
testConfig: testConfig => {
|
|
12
12
|
const oldModuleScope = testConfig.moduleScope;
|
|
13
|
-
testConfig.moduleScope = (ms, stats) => {
|
|
13
|
+
testConfig.moduleScope = (ms, stats, compilerOptions) => {
|
|
14
14
|
let res = ms;
|
|
15
15
|
// TODO: modify runner module scope based on stats here
|
|
16
16
|
if (typeof oldModuleScope === "function") {
|
|
17
|
-
res = oldModuleScope(ms, stats);
|
|
17
|
+
res = oldModuleScope(ms, stats, compilerOptions);
|
|
18
18
|
}
|
|
19
19
|
return res;
|
|
20
20
|
};
|
package/dist/compiler.d.ts
CHANGED
|
@@ -6,20 +6,21 @@ export declare enum ECompilerEvent {
|
|
|
6
6
|
Create = "create",
|
|
7
7
|
Close = "close"
|
|
8
8
|
}
|
|
9
|
-
export declare const COMPILER_FACTORIES: TCompilerFactories
|
|
9
|
+
export declare const COMPILER_FACTORIES: TCompilerFactories<ECompilerType>;
|
|
10
10
|
export declare class TestCompilerManager<T extends ECompilerType> implements ITestCompilerManager<T> {
|
|
11
11
|
protected type: T;
|
|
12
|
-
protected factories: TCompilerFactories
|
|
12
|
+
protected factories: TCompilerFactories<T>;
|
|
13
13
|
protected compilerOptions: TCompilerOptions<T>;
|
|
14
14
|
protected compilerInstance: TCompiler<T> | null;
|
|
15
15
|
protected compilerStats: TCompilerStats<T> | null;
|
|
16
16
|
protected emitter: EventEmitter;
|
|
17
|
-
constructor(type: T, factories?: TCompilerFactories);
|
|
17
|
+
constructor(type: T, factories?: TCompilerFactories<T>);
|
|
18
18
|
getOptions(): TCompilerOptions<T>;
|
|
19
19
|
setOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
|
|
20
20
|
mergeOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
|
|
21
21
|
getCompiler(): TCompiler<T> | null;
|
|
22
22
|
createCompiler(): TCompiler<T>;
|
|
23
|
+
createCompilerWithCallback(callback: (error: Error | null, stats: TCompilerStats<T> | null) => void): TCompiler<T>;
|
|
23
24
|
build(): Promise<TCompilerStats<T>>;
|
|
24
25
|
watch(timeout?: number): void;
|
|
25
26
|
getStats(): TCompilerStats<T> | null;
|
package/dist/compiler.js
CHANGED
|
@@ -15,8 +15,8 @@ var ECompilerEvent;
|
|
|
15
15
|
ECompilerEvent["Close"] = "close";
|
|
16
16
|
})(ECompilerEvent || (exports.ECompilerEvent = ECompilerEvent = {}));
|
|
17
17
|
exports.COMPILER_FACTORIES = {
|
|
18
|
-
[type_1.ECompilerType.Rspack]: ((options) => require("@rspack/core")(options)),
|
|
19
|
-
[type_1.ECompilerType.Webpack]: ((options) => require("webpack")(options))
|
|
18
|
+
[type_1.ECompilerType.Rspack]: ((options, callback) => require("@rspack/core")(options, callback)),
|
|
19
|
+
[type_1.ECompilerType.Webpack]: ((options, callback) => require("webpack")(options, callback))
|
|
20
20
|
};
|
|
21
21
|
class TestCompilerManager {
|
|
22
22
|
constructor(type, factories = exports.COMPILER_FACTORIES) {
|
|
@@ -48,6 +48,11 @@ class TestCompilerManager {
|
|
|
48
48
|
this.emitter.emit(ECompilerEvent.Create, this.compilerInstance);
|
|
49
49
|
return this.compilerInstance;
|
|
50
50
|
}
|
|
51
|
+
createCompilerWithCallback(callback) {
|
|
52
|
+
this.compilerInstance = this.factories[this.type](this.compilerOptions, callback);
|
|
53
|
+
this.emitter.emit(ECompilerEvent.Create, this.compilerInstance);
|
|
54
|
+
return this.compilerInstance;
|
|
55
|
+
}
|
|
51
56
|
build() {
|
|
52
57
|
if (!this.compilerInstance)
|
|
53
58
|
throw new Error("Compiler should be created before build");
|
|
@@ -16,7 +16,7 @@ const placeholderSerializer = (0, path_serializer_1.createSnapshotSerializer)({
|
|
|
16
16
|
: node_path_1.default.resolve(__dirname, "../../../../../"),
|
|
17
17
|
replace: [
|
|
18
18
|
{
|
|
19
|
-
match: node_path_1.default.resolve(__dirname, "
|
|
19
|
+
match: node_path_1.default.resolve(__dirname, "../../../../../tests/rspack-test"),
|
|
20
20
|
mark: "test_tools_root"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
@@ -223,12 +223,15 @@ class FakeSheet {
|
|
|
223
223
|
currentRule[property] = value;
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
|
-
|
|
227
|
-
? new URL(this._element.href)
|
|
226
|
+
let filepath = /file:\/\//.test(this._element.href)
|
|
227
|
+
? new URL(this._element.href).pathname
|
|
228
228
|
: path.resolve(this._basePath, this._element.href
|
|
229
229
|
.replace(/^https:\/\/test\.cases\/path\//, "")
|
|
230
230
|
.replace(/^https:\/\/example\.com\/public\/path\//, "")
|
|
231
231
|
.replace(/^https:\/\/example\.com\//, ""));
|
|
232
|
+
if (require("os").platform() === "win32" && filepath.startsWith("/")) {
|
|
233
|
+
filepath = filepath.slice(1);
|
|
234
|
+
}
|
|
232
235
|
let css = fs.readFileSync(filepath.replace(/\?hmr=\d*/, ""), "utf-8");
|
|
233
236
|
css = css.replace(/@import url\("([^"]+)"\);/g, (match, url) => {
|
|
234
237
|
if (!/^https:\/\/test\.cases\/path\//.test(url)) {
|
|
@@ -239,8 +242,7 @@ class FakeSheet {
|
|
|
239
242
|
}
|
|
240
243
|
return fs.readFileSync(path.resolve(this._basePath, url.replace(/^https:\/\/test\.cases\/path\//, "")), "utf-8");
|
|
241
244
|
})
|
|
242
|
-
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
243
|
-
.replace("//", "");
|
|
245
|
+
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
244
246
|
walkCssTokens(css, {
|
|
245
247
|
isSelector() {
|
|
246
248
|
return selector === undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare function _exports(env: any, { outputDirectory }: {
|
|
2
2
|
outputDirectory: any;
|
|
3
3
|
}): {
|
|
4
|
-
new (
|
|
4
|
+
new (resource: any, options?: {}): {
|
|
5
5
|
url: any;
|
|
6
6
|
worker: import("worker_threads").Worker;
|
|
7
7
|
_onmessage: ((data: any) => void) | undefined;
|
|
@@ -1,28 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// @ts-nocheck
|
|
3
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
const path = require("path");
|
|
4
4
|
module.exports = (env, { outputDirectory }) => class Worker {
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
constructor(resource, options = {}) {
|
|
6
|
+
const isFileURL = /^file:/i.test(resource);
|
|
7
|
+
const isBlobURL = /^blob:/i.test(resource);
|
|
8
|
+
if (!isFileURL && !isBlobURL) {
|
|
9
|
+
env.expect(resource.origin).toBe("https://test.cases");
|
|
10
|
+
env.expect(resource.pathname.startsWith("/path/")).toBe(true);
|
|
11
|
+
}
|
|
12
|
+
this.url = resource;
|
|
13
|
+
const file = isFileURL
|
|
14
|
+
? resource
|
|
15
|
+
: path.resolve(outputDirectory, isBlobURL
|
|
16
|
+
? options.originalURL.pathname.slice(6)
|
|
17
|
+
: resource.pathname.slice(6));
|
|
11
18
|
const workerBootstrap = `
|
|
12
19
|
const { parentPort } = require("worker_threads");
|
|
13
|
-
const { URL } = require("url");
|
|
20
|
+
const { URL, fileURLToPath } = require("url");
|
|
14
21
|
const path = require("path");
|
|
15
22
|
const fs = require("fs");
|
|
16
23
|
global.self = global;
|
|
17
24
|
self.URL = URL;
|
|
18
|
-
self.location = new URL(${JSON.stringify(
|
|
25
|
+
self.location = new URL(${JSON.stringify(isBlobURL
|
|
26
|
+
? resource.toString().replace("nodedata:", "https://test.cases/path/")
|
|
27
|
+
: resource.toString())});
|
|
19
28
|
const urlToPath = url => {
|
|
20
|
-
|
|
29
|
+
if (/^file:/i.test(url)) return fileURLToPath(url);
|
|
30
|
+
if (url.startsWith("https://test.cases/path/")) url = url.slice(24);
|
|
21
31
|
return path.resolve(${JSON.stringify(outputDirectory)}, \`./\${url}\`);
|
|
22
32
|
};
|
|
23
33
|
self.importScripts = url => {
|
|
24
34
|
${options.type === "module"
|
|
25
|
-
?
|
|
35
|
+
? 'throw new Error("importScripts is not supported in module workers")'
|
|
26
36
|
: "require(urlToPath(url))"};
|
|
27
37
|
};
|
|
28
38
|
self.fetch = async url => {
|
|
@@ -33,8 +43,10 @@ self.fetch = async url => {
|
|
|
33
43
|
)
|
|
34
44
|
);
|
|
35
45
|
return {
|
|
46
|
+
headers: { get(name) { } },
|
|
36
47
|
status: 200,
|
|
37
48
|
ok: true,
|
|
49
|
+
arrayBuffer() { return buffer; },
|
|
38
50
|
json: async () => JSON.parse(buffer.toString("utf-8"))
|
|
39
51
|
};
|
|
40
52
|
} catch(err) {
|
|
@@ -47,25 +59,37 @@ self.fetch = async url => {
|
|
|
47
59
|
throw err;
|
|
48
60
|
}
|
|
49
61
|
};
|
|
50
|
-
|
|
51
|
-
if(self.onmessage) self.onmessage({
|
|
52
|
-
data
|
|
53
|
-
});
|
|
54
|
-
});
|
|
62
|
+
|
|
55
63
|
self.postMessage = data => {
|
|
56
64
|
parentPort.postMessage(data);
|
|
57
65
|
};
|
|
58
|
-
|
|
66
|
+
if (${options.type === "module"}) {
|
|
67
|
+
import(${JSON.stringify(file)}).then(() => {
|
|
68
|
+
parentPort.on("message", data => {
|
|
69
|
+
if(self.onmessage) self.onmessage({
|
|
70
|
+
data
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
parentPort.on("message", data => {
|
|
76
|
+
if(self.onmessage) self.onmessage({
|
|
77
|
+
data
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
require(${JSON.stringify(file)});
|
|
81
|
+
}
|
|
59
82
|
`;
|
|
60
|
-
this.worker = new (require("
|
|
83
|
+
this.worker = new (require("worker_threads").Worker)(workerBootstrap, {
|
|
61
84
|
eval: true
|
|
62
85
|
});
|
|
63
86
|
this._onmessage = undefined;
|
|
64
87
|
}
|
|
88
|
+
// eslint-disable-next-line accessor-pairs
|
|
65
89
|
set onmessage(value) {
|
|
66
90
|
if (this._onmessage)
|
|
67
91
|
this.worker.off("message", this._onmessage);
|
|
68
|
-
this.worker.on("message", (this._onmessage = data => {
|
|
92
|
+
this.worker.on("message", (this._onmessage = (data) => {
|
|
69
93
|
value({
|
|
70
94
|
data
|
|
71
95
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function start(handler: any): () => any[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/*
|
|
3
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
4
|
+
Author Tobias Koppers @sokra
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
const util = require("util");
|
|
8
|
+
let interception = undefined;
|
|
9
|
+
const originalDeprecate = util.deprecate;
|
|
10
|
+
util.deprecate = (fn, message, code) => {
|
|
11
|
+
const original = originalDeprecate(fn, message, code);
|
|
12
|
+
return function (...args) {
|
|
13
|
+
if (interception) {
|
|
14
|
+
interception.set(`${code}: ${message}`, {
|
|
15
|
+
code,
|
|
16
|
+
message,
|
|
17
|
+
stack: new Error(message).stack
|
|
18
|
+
});
|
|
19
|
+
return fn.apply(this, args);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return original.apply(this, args);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.start = handler => {
|
|
27
|
+
interception = new Map();
|
|
28
|
+
return () => {
|
|
29
|
+
const map = interception;
|
|
30
|
+
interception = undefined;
|
|
31
|
+
return Array.from(map || [])
|
|
32
|
+
.sort(([a], [b]) => {
|
|
33
|
+
if (a < b)
|
|
34
|
+
return -1;
|
|
35
|
+
if (a > b)
|
|
36
|
+
return 1;
|
|
37
|
+
return 0;
|
|
38
|
+
})
|
|
39
|
+
.map(([key, data]) => data);
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} source value
|
|
3
|
+
* @param {string} str string for searching
|
|
4
|
+
*/
|
|
5
|
+
export function expectSourceToContain(source: string, str: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} source value
|
|
8
|
+
* @param {RegExp} regexStr regexp
|
|
9
|
+
*/
|
|
10
|
+
export function expectSourceToMatch(source: string, regexStr: RegExp): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
"use strict";
|
|
3
|
+
const regexEscape = require("./regexEscape");
|
|
4
|
+
// These expect* methods are necessary because 'source' contains the code for this test file, which will always contain the string
|
|
5
|
+
// being tested for, so we have to use the "DO NOT MATCH BELOW..." technique to exclude the actual testing code from the test.
|
|
6
|
+
// Place your jest 'expect' calls below a line containing the DO NOT MATCH BELOW... string constructed below. See other tests for examples.
|
|
7
|
+
// Break up the match string so we don't match it in these expect* functions either.
|
|
8
|
+
const doNotMatch = ["DO", "NOT", "MATCH", "BELOW", "THIS", "LINE"].join(" ");
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} source value
|
|
11
|
+
* @param {string} str string for searching
|
|
12
|
+
*/
|
|
13
|
+
function expectSourceToContain(source, str) {
|
|
14
|
+
expect(source).toMatch(new RegExp(`${regexEscape(str)}.*${doNotMatch}`, "s"));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} source value
|
|
18
|
+
* @param {RegExp} regexStr regexp
|
|
19
|
+
*/
|
|
20
|
+
function expectSourceToMatch(source, regexStr) {
|
|
21
|
+
expect(source).toMatch(new RegExp(`${regexStr}.*${doNotMatch}`, "s"));
|
|
22
|
+
}
|
|
23
|
+
module.exports = { expectSourceToContain, expectSourceToMatch };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
"use strict";
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
/**
|
|
6
|
+
* @param {{output: {path: string}}} options options
|
|
7
|
+
* @param {RegExp} regexp regexp
|
|
8
|
+
* @param {string=} subpath path in output directory
|
|
9
|
+
* @returns {string[]} files
|
|
10
|
+
*/
|
|
11
|
+
module.exports = function findOutputFiles(options, regexp, subpath) {
|
|
12
|
+
const files = fs.readdirSync(subpath ? path.join(options.output.path, subpath) : options.output.path);
|
|
13
|
+
return files.filter(file => regexp.test(file));
|
|
14
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
module.exports = function supportDefaultAssignment() {
|
|
4
|
+
try {
|
|
5
|
+
// eslint-disable-next-line no-unused-vars
|
|
6
|
+
var E = eval("class E { toString() { return 'default' } }");
|
|
7
|
+
var f1 = eval("(function f1({a, b = E}) {return new b().toString();})");
|
|
8
|
+
return f1({ a: "test" }) === "default";
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|