Skip to content

Commit

Permalink
test: add test for css minimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Burhanuddin Udaipurwala committed Jun 3, 2023
1 parent 550df9d commit d3ad1ac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
7 changes: 3 additions & 4 deletions test/configCases/optimization/css-minimize/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as style from "./style.css";
import "./style.css";

it("should compile and load style on demand", done => {
expect(style).toEqual(nsObj({}));
it("should compile", done => {
import("./style.css").then(x => {
expect(x).toEqual(nsObj({}));
const style = getComputedStyle(document.body);
expect(style.getPropertyValue("background")).toBe(" red");
expect(style.getPropertyValue("background")).toBe("red");
done();
}, done);
});
28 changes: 26 additions & 2 deletions test/configCases/optimization/css-minimize/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
const Compilation = require("../../../../").Compilation;
const Source = require("webpack-sources").Source;

/** @type {import("../../../../").Configuration} */
module.exports = {
target: "web",
mode: "production",
experiments: {
css: true
},
optimization: {
minimize: true
}
},
plugins: [
compiler => {
const files = {};
compiler.hooks.assetEmitted.tap(
"Test",
(file, { content, source, outputPath, compilation, targetPath }) => {
expect(Buffer.isBuffer(content)).toBe(true);
expect(source).toBeInstanceOf(Source);
expect(typeof outputPath).toBe("string");
expect(typeof targetPath).toBe("string");
expect(compilation).toBeInstanceOf(Compilation);
files[file] = content.toString("utf-8");
}
);
compiler.hooks.afterEmit.tap("Test", () => {
// css should be minimized
expect(files["bundle0.css"]).toMatchInlineSnapshot(
`"body{background:red}head{--webpack-179:_258}"`
);
});
}
]
};

0 comments on commit d3ad1ac

Please sign in to comment.