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
|
/**
* @jest-environment node
*/
import {
compile,
execute,
getCompiler,
getErrors,
getModuleSource,
getWarnings,
readAsset,
} from "./helpers";
describe('"minimize" option', () => {
it("should be turned off by default", async () => {
const compiler = getCompiler("simple.js");
const stats = await compile(compiler);
expect(getModuleSource("./simple.html", stats)).toMatchSnapshot("module");
expect(
execute(readAsset("main.bundle.js", compiler, stats))
).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it('should be turned off in "development" mode', async () => {
const compiler = getCompiler("simple.js", {}, { mode: "development" });
const stats = await compile(compiler);
expect(getModuleSource("./simple.html", stats)).toMatchSnapshot("module");
expect(
execute(readAsset("main.bundle.js", compiler, stats))
).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it('should be turned on in "production" mode', async () => {
const compiler = getCompiler("simple.js", {}, { mode: "production" });
const stats = await compile(compiler);
expect(getModuleSource("./simple.html", stats)).toMatchSnapshot("module");
expect(
execute(readAsset("main.bundle.js", compiler, stats))
).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it('should not work with a value equal to "false"', async () => {
const compiler = getCompiler("simple.js", { minimize: false });
const stats = await compile(compiler);
expect(getModuleSource("./simple.html", stats)).toMatchSnapshot("module");
expect(
execute(readAsset("main.bundle.js", compiler, stats))
).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it('should work with a value equal to "true"', async () => {
const compiler = getCompiler("simple.js", { minimize: true });
const stats = await compile(compiler);
expect(getModuleSource("./simple.html", stats)).toMatchSnapshot("module");
expect(
execute(readAsset("main.bundle.js", compiler, stats))
).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it("should support options for minimizer", async () => {
const compiler = getCompiler("simple.js", {
minimize: {
collapseWhitespace: true,
conservativeCollapse: true,
removeAttributeQuotes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
removeComments: false,
},
});
const stats = await compile(compiler);
expect(getModuleSource("./simple.html", stats)).toMatchSnapshot("module");
expect(
execute(readAsset("main.bundle.js", compiler, stats))
).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it("should emit an error on broken HTML syntax", async () => {
const compiler = getCompiler("broken-html-syntax.js", { minimize: true });
const stats = await compile(compiler);
expect(getModuleSource("./broken-html-syntax.html", stats)).toMatchSnapshot(
"module"
);
expect(
execute(readAsset("main.bundle.js", compiler, stats))
).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it("should work with XHTML", async () => {
const compiler = getCompiler("XHTML.js", { minimize: true });
const stats = await compile(compiler);
expect(getModuleSource("./XHTML.html", stats)).toMatchSnapshot("module");
expect(
execute(readAsset("main.bundle.js", compiler, stats))
).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});
|