Skip to content

Commit

Permalink
test: added
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jun 9, 2023
1 parent bb68c68 commit 71ec9be
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,6 @@ async function getPostcssOptions(
);
}

// No need them for processOptions
const { plugins: __plugins, ...optionsFromConfig } = processOptionsFromConfig;

const processOptionsFromOptions = { ...normalizedPostcssOptions };

if (processOptionsFromOptions.from) {
Expand All @@ -362,7 +359,8 @@ async function getPostcssOptions(
);
}

// No need them for processOptions
// No need `plugins` and `config` for processOptions
const { plugins: __plugins, ...optionsFromConfig } = processOptionsFromConfig;
const {
config: _config,
plugins: _plugins,
Expand Down
14 changes: 14 additions & 0 deletions test/__snapshots__/postcssOptions.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,20 @@ exports[`"postcssOptions" option should work "Function" value: errors 1`] = `[]`

exports[`"postcssOptions" option should work "Function" value: warnings 1`] = `[]`;

exports[`"postcssOptions" option should work and don't modify postcss options: css 1`] = `
"a { color: black }
.foo {
float: right;
}
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZyb20uY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLElBQUksYUFBYTs7QUFFakI7RUFDRSxZQUFZO0FBQ2QiLCJmaWxlIjoidG8uY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYSB7IGNvbG9yOiBibGFjayB9XG5cbi5mb28ge1xuICBmbG9hdDogcmlnaHQ7XG59XG4iXX0= */"
`;

exports[`"postcssOptions" option should work and don't modify postcss options: errors 1`] = `[]`;

exports[`"postcssOptions" option should work and don't modify postcss options: warnings 1`] = `[]`;

exports[`"postcssOptions" option should work and provide API for the configuration: css 1`] = `
"a {
color: black;
Expand Down
39 changes: 39 additions & 0 deletions test/postcssOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,48 @@ describe('"postcssOptions" option', () => {
},
});
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle("style.css", stats);

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

it("should work and don't modify postcss options", async () => {
const postcssOptions = {
config: path.resolve(__dirname, "./fixtures/css/plugins.config.js"),
from: "from.css",
map: {
inline: true,
},
parser: "postcss/lib/parse",
stringifier: "postcss/lib/stringify",
to: "to.css",
plugins: [require.resolve("./fixtures/plugin/new-api.plugin")],
};
const compiler = getCompiler(
"./config-scope/css/index.js",
{
postcssOptions,
},
{
devtool: "source-map",
}
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle("style.css", stats);

expect(postcssOptions).toEqual({
config: path.resolve(__dirname, "./fixtures/css/plugins.config.js"),
from: "from.css",
map: {
inline: true,
},
parser: "postcss/lib/parse",
stringifier: "postcss/lib/stringify",
to: "to.css",
plugins: [require.resolve("./fixtures/plugin/new-api.plugin")],
});
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
Expand Down

0 comments on commit 71ec9be

Please sign in to comment.