1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
import {
compile,
getCompiler,
getErrors,
getModuleSource,
getResultFromBrowser,
getWarnings,
} from "./helpers";
describe("worker-loader", () => {
it("should work", async () => {
const compiler = getCompiler("./basic/entry.js");
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
expect(getModuleSource("./basic/worker.js", stats)).toMatchSnapshot(
"module"
);
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it("should work with inline syntax", async () => {
const compiler = getCompiler("./query/entry.js");
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
expect(getModuleSource("./query/my-worker-name.js", stats)).toMatchSnapshot(
"module"
);
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it("should work with WASM", async () => {
const compiler = getCompiler("./wasm/entry.js");
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
expect(getModuleSource("./wasm/worker.js", stats)).toMatchSnapshot(
"module"
);
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it("should work with async chunks", async () => {
const compiler = getCompiler("./chunks/entry.js");
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
expect(getModuleSource("./chunks/worker.js", stats)).toMatchSnapshot(
"module"
);
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it('should work with "externals"', async () => {
const compiler = getCompiler(
"./external/entry.js",
{},
{
externals: {
"my-custom-module": "navigator",
},
}
);
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
expect(getModuleSource("./external/worker.js", stats)).toMatchSnapshot(
"module"
);
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it('should work and respect the "devtool" option ("source-map" value)', async () => {
const compiler = getCompiler(
"./basic/entry.js",
{},
{ devtool: "source-map" }
);
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
expect(getModuleSource("./basic/worker.js", stats)).toMatchSnapshot(
"module"
);
expect(stats.compilation.assets["test.worker.js.map"]).toBeDefined();
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it('should work and respect the "devtool" option ("false" value)', async () => {
const compiler = getCompiler("./basic/entry.js", {}, { devtool: false });
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
expect(getModuleSource("./basic/worker.js", stats)).toMatchSnapshot(
"module"
);
expect(stats.compilation.assets["test.worker.js.map"]).toBeUndefined();
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it("should work and have the same base file name as the source files", async () => {
const compiler = getCompiler("./name/entry.js", {
filename: "[name].worker.js",
});
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
expect(getModuleSource("./name/TypeDetection.js", stats)).toMatchSnapshot(
"module"
);
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});
|