Skip to content

Commit

Permalink
fix: respect the compress option (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jan 15, 2021
1 parent 86a0ee0 commit e964abc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils.js
Expand Up @@ -34,7 +34,10 @@ function getStylusOptions(loaderContext, loaderOptions) {
? stylusOptions.resolveURL
: { nocheck: true };

if (!stylusOptions.compress && isProductionLikeMode(loaderContext)) {
if (
typeof stylusOptions.compress === "undefined" &&
isProductionLikeMode(loaderContext)
) {
stylusOptions.compress = true;
}

Expand Down
22 changes: 22 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -917,6 +917,28 @@ exports[`loader should work "use" option: errors 1`] = `Array []`;
exports[`loader should work "use" option: warnings 1`] = `Array []`;
exports[`loader should work and respect the "compress" option with the "false" value: css 1`] = `
"body {
font: 12px Helvetica, Arial, sans-serif;
}
a.button {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
"
`;
exports[`loader should work and respect the "compress" option with the "false" value: errors 1`] = `Array []`;
exports[`loader should work and respect the "compress" option with the "false" value: warnings 1`] = `Array []`;
exports[`loader should work and respect the "compress" option with the "true" value: css 1`] = `"body{font:12px Helvetica,Arial,sans-serif}a.button{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}"`;
exports[`loader should work and respect the "compress" option with the "true" value: errors 1`] = `Array []`;
exports[`loader should work and respect the "compress" option with the "true" value: warnings 1`] = `Array []`;
exports[`loader should work binop import: css 1`] = `
".not-real-nib {
color: #000;
Expand Down
50 changes: 50 additions & 0 deletions test/loader.test.js
Expand Up @@ -1509,6 +1509,56 @@ describe("loader", () => {
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it('should work and respect the "compress" option with the "true" value', async () => {
const testId = "./basic.styl";
const compiler = getCompiler(
testId,
{
stylusOptions: {
compress: true,
},
},
{ mode: "production" }
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromStylus = await getCodeFromStylus(testId, {
stylusOptions: {
compress: true,
},
});

expect(codeFromBundle.css).toBe(codeFromStylus.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it('should work and respect the "compress" option with the "false" value', async () => {
const testId = "./basic.styl";
const compiler = getCompiler(
testId,
{
stylusOptions: {
compress: false,
},
},
{ mode: "production" }
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromStylus = await getCodeFromStylus(testId, {
stylusOptions: {
compress: false,
},
});

expect(codeFromBundle.css).toBe(codeFromStylus.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should use .json file", async () => {
const testId = "./json/index.styl";
const compiler = getCompiler(testId, {
Expand Down

0 comments on commit e964abc

Please sign in to comment.