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
|
import {
compile,
getCompiler,
getErrors,
getModuleSource,
getResultFromBrowser,
getWarnings,
} from "./helpers";
describe('"workerType" option', () => {
it('should use "Worker" by default', 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 support the "Worker" string value', async () => {
const compiler = getCompiler("./basic/entry.js", { worker: "Worker" });
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 support the "Worker" object value', async () => {
const compiler = getCompiler("./basic/entry.js", {
worker: {
type: "Worker",
options: {
type: "classic",
name: "worker-name",
},
},
});
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 support the "Worker" object value for inline workers with fallback', async () => {
const compiler = getCompiler("./basic/entry.js", {
inline: "fallback",
worker: {
type: "Worker",
options: {
type: "classic",
name: "worker-name",
},
},
});
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
const moduleSource = getModuleSource("./basic/worker.js", stats);
expect(moduleSource.indexOf("inline.js") > 0).toBe(true);
expect(
moduleSource.indexOf('__webpack_public_path__ + "test.worker.js"') > 0
).toBe(true);
expect(stats.compilation.assets["test.worker.js"]).toBeDefined();
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it('should support the "Worker" object value for inline workers without fallback', async () => {
const compiler = getCompiler("./basic/entry.js", {
inline: "no-fallback",
worker: {
type: "Worker",
options: {
type: "classic",
name: "worker-name",
},
},
});
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
const moduleSource = getModuleSource("./basic/worker.js", stats);
expect(moduleSource.indexOf("inline.js") > 0).toBe(true);
expect(
moduleSource.indexOf('__webpack_public_path__ + "test.worker.js"') === -1
).toBe(true);
expect(stats.compilation.assets["test.worker.js"]).toBeUndefined();
expect(result).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});
|