Skip to content

Commit 8f05e4f

Browse files
committed
test: gate css minimizer tests by node version
Skip tests that exercise minimizers whose underlying tool requires a newer Node than the test row provides: - `cssnanoMinify` and the cssnano array tests need Node >=18 (cssnano@7; the workflow already swaps in older cssnano for older Node, but the snapshots are taken against cssnano@7's output). - `esbuildMinifyCss` and the merge-source-map chain that includes `esbuildMinify` need Node >=18 (esbuild@0.27). - `swcMinifyCss` needs Node >=14 (@swc/css). - `lightningCssMinify` needs Node >=12. Adds an `itIf` helper at the top of the file driven by `process.versions.node`.
1 parent 5ff6ebc commit 8f05e4f

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

test/minify-option.test.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import {
1111
readsAssets,
1212
} from "./helpers";
1313

14+
// Some bundled minimizers require a newer Node than the test matrix
15+
// covers (`@swc/css` >=14, `cssnano@7` >=18, `esbuild@0.27` >=18, etc.).
16+
// Skip the rows that exercise them on older Node so snapshot-based
17+
// assertions don't drift between versions of those tools.
18+
const NODE_MAJOR = Number(process.versions.node.split(".")[0]);
19+
const itIf = (condition) => (condition ? it : it.skip);
20+
1421
describe("minify option", () => {
1522
it("should work", async () => {
1623
const compiler = getCompiler({
@@ -1302,7 +1309,8 @@ describe("minify option", () => {
13021309
expect(getWarnings(stats)).toMatchSnapshot("warnings");
13031310
});
13041311

1305-
it("should work using when the `minify` option is `cssnanoMinify`", async () => {
1312+
// cssnano@7 requires Node >=18 — older Node rows install older cssnano via CI.
1313+
itIf(NODE_MAJOR >= 18)("should work using when the `minify` option is `cssnanoMinify`", async () => {
13061314
const compiler = getCompiler({
13071315
entry: path.resolve(__dirname, "./fixtures/css.js"),
13081316
});
@@ -1320,7 +1328,7 @@ describe("minify option", () => {
13201328
expect(getWarnings(stats)).toMatchSnapshot("warnings");
13211329
});
13221330

1323-
it("should work using when the `minify` option is `cssnanoMinify` and allows to set `cssnano` options", async () => {
1331+
itIf(NODE_MAJOR >= 18)("should work using when the `minify` option is `cssnanoMinify` and allows to set `cssnano` options", async () => {
13241332
const compiler = getCompiler({
13251333
entry: path.resolve(__dirname, "./fixtures/css.js"),
13261334
});
@@ -1413,7 +1421,8 @@ describe("minify option", () => {
14131421
expect(getWarnings(stats)).toMatchSnapshot("warnings");
14141422
});
14151423

1416-
it("should work using when the `minify` option is `esbuildMinifyCss`", async () => {
1424+
// esbuild@0.27 requires Node >=18.
1425+
itIf(NODE_MAJOR >= 18)("should work using when the `minify` option is `esbuildMinifyCss`", async () => {
14171426
const compiler = getCompiler({
14181427
entry: path.resolve(__dirname, "./fixtures/css.js"),
14191428
});
@@ -1431,7 +1440,8 @@ describe("minify option", () => {
14311440
expect(getWarnings(stats)).toMatchSnapshot("warnings");
14321441
});
14331442

1434-
it("should work using when the `minify` option is `lightningCssMinify`", async () => {
1443+
// `lightningcss` requires Node >=12.
1444+
itIf(NODE_MAJOR >= 12)("should work using when the `minify` option is `lightningCssMinify`", async () => {
14351445
const compiler = getCompiler({
14361446
entry: path.resolve(__dirname, "./fixtures/css.js"),
14371447
});
@@ -1449,7 +1459,8 @@ describe("minify option", () => {
14491459
expect(getWarnings(stats)).toMatchSnapshot("warnings");
14501460
});
14511461

1452-
it("should work using when the `minify` option is `swcMinifyCss`", async () => {
1462+
// `@swc/css` requires Node >=14.
1463+
itIf(NODE_MAJOR >= 14)("should work using when the `minify` option is `swcMinifyCss`", async () => {
14531464
const compiler = getCompiler({
14541465
entry: path.resolve(__dirname, "./fixtures/css.js"),
14551466
});
@@ -1467,7 +1478,7 @@ describe("minify option", () => {
14671478
expect(getWarnings(stats)).toMatchSnapshot("warnings");
14681479
});
14691480

1470-
it("should work when `minify` is an array of functions using `cssnanoMinify`", async () => {
1481+
itIf(NODE_MAJOR >= 18)("should work when `minify` is an array of functions using `cssnanoMinify`", async () => {
14711482
const compiler = getCompiler({
14721483
entry: path.resolve(__dirname, "./fixtures/css.js"),
14731484
});
@@ -1541,7 +1552,7 @@ describe("minify option", () => {
15411552
expect(getWarnings(stats)).toMatchSnapshot("warnings");
15421553
});
15431554

1544-
it("should work and merge source maps when `minify` is an array of CSS minimizers", async () => {
1555+
itIf(NODE_MAJOR >= 18)("should work and merge source maps when `minify` is an array of CSS minimizers", async () => {
15451556
const compiler = getCompiler({
15461557
devtool: "source-map",
15471558
entry: path.resolve(__dirname, "./fixtures/css.js"),
@@ -1584,7 +1595,7 @@ describe("minify option", () => {
15841595
expect(getWarnings(stats)).toMatchSnapshot("warnings");
15851596
});
15861597

1587-
it("should work and merge source maps when `minify` mixes `terserMinify` with `esbuildMinify`", async () => {
1598+
itIf(NODE_MAJOR >= 18)("should work and merge source maps when `minify` mixes `terserMinify` with `esbuildMinify`", async () => {
15881599
const compiler = getCompiler({
15891600
devtool: "source-map",
15901601
entry: path.resolve(__dirname, "./fixtures/minify/es6.js"),
@@ -1607,7 +1618,9 @@ describe("minify option", () => {
16071618
expect(getWarnings(stats)).toMatchSnapshot("warnings");
16081619
});
16091620

1610-
it("should work and merge source maps when `minify` mixes CSS minimizers using `cssnano`, `csso`, `cleanCss`, `lightningCss`, `swcCss`, and `esbuild`", async () => {
1621+
// The chain runs through every CSS minimizer; `esbuild` is the
1622+
// tightest constraint at Node >=18.
1623+
itIf(NODE_MAJOR >= 18)("should work and merge source maps when `minify` mixes CSS minimizers using `cssnano`, `csso`, `cleanCss`, `lightningCss`, `swcCss`, and `esbuild`", async () => {
16111624
const compiler = getCompiler({
16121625
devtool: "source-map",
16131626
entry: path.resolve(__dirname, "./fixtures/css.js"),

0 commit comments

Comments
 (0)