Skip to content

Test more #1375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/plugins/postcss-import-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ function parseNode(atRule, key) {
throw error;
}

const { nodes: paramsNodes } = valueParser(atRule[key]);
const rawParams =
atRule.raws &&
atRule.raws[key] &&
typeof atRule.raws[key].raw !== "undefined"
? atRule.raws[key].raw
: atRule[key];
const { nodes: paramsNodes } = valueParser(rawParams);

// No nodes - `@import ;`
// Invalid type - `@import foo-bar;`
Expand Down
1,198 changes: 1,148 additions & 50 deletions test/__snapshots__/import-option.test.js.snap

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/__snapshots__/sourceMap-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ exports[`"sourceMap" option true should generate source maps when css was extrac
exports[`"sourceMap" option true should generate source maps when css was extracted and do not change "[contenthash]" on different platform: source map 1`] = `
Object {
"file": "main.xxxxxxxxxxxxxxxxxxxx.css",
"mappings": "AAAA;EACE,WAAW;AACb;;;;;ACAA;EACE,UAAU;AACZ",
"mappings": ";;;AAAA;EACE,WAAW;AACb;;;;;ACAA;EACE,UAAU;AACZ",
"names": Array [],
"sourceRoot": "",
"sources": Array [
Expand Down Expand Up @@ -362,7 +362,7 @@ exports[`"sourceMap" option true should generate source maps when css was extrac
exports[`"sourceMap" option true should generate source maps when css was extracted: source map 1`] = `
Object {
"file": "main.css",
"mappings": "AAAA;EACE,WAAW;AACb;;;;;ACAA;EACE,UAAU;AACZ",
"mappings": ";;;AAAA;EACE,WAAW;AACb;;;;;ACAA;EACE,UAAU;AACZ",
"names": Array [],
"sourceRoot": "",
"sources": Array [
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/validate-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ exports[`validate options should throw an error on the "importLoaders" option wi
Details:
* options.importLoaders should be a boolean.
* options.importLoaders should be a string.
* options.importLoaders should be a integer."
* options.importLoaders should be an integer."
`;

exports[`validate options should throw an error on the "modules" option with "{"auto":"invalid"}" value 1`] = `
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/import/import-stringified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import css from './import.css';

__export__ = css.toString();

export default css;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/import/import-with-layer-and-supports.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url('./test.css') layer(base);
1 change: 1 addition & 0 deletions test/fixtures/import/import-with-layer-unnamed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url('./test.css') layer;
1 change: 1 addition & 0 deletions test/fixtures/import/import-with-layer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url('./test.css') layer(base) supports(display: grid);
1 change: 1 addition & 0 deletions test/fixtures/import/import-with-supports-and-media.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url('./test.css') supports(display: grid) handheld and (max-width: 400px);
1 change: 1 addition & 0 deletions test/fixtures/import/import-with-supports.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url('./test.css') supports(display: grid);
30 changes: 28 additions & 2 deletions test/fixtures/import/import.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@import url( test.css);
@import url( test.css );
@import url(
test.css
test.css
);
@import url();
@import url('');
Expand Down Expand Up @@ -53,7 +53,7 @@
}

.foo {
@import 'path.css';
@import 'path.css';
}

@import url('./relative.css');
Expand Down Expand Up @@ -158,3 +158,29 @@ st.css');
/* Prefer relative */
@import url(package/first.css);
@import url(package/second.css);

@import url("./test.css") supports(display: flex);
@import url("./test.css") supports(display: flex) screen and (min-width: 400px);
@import url("./test.css") layer;
@import url("./test.css") layer(default);
@import url("./test.css") layer(default) supports(display: flex) screen and (min-width: 400px);
@import url("http://example.com/style.css") supports(display: flex) screen and (min-width: 400px);
@import url("./test.css")layer(default)supports(display: flex)screen and (min-width:400px);
@import url("./test.css")screen and (min-width: 400px);
@import url("./test.css") layer( default ) supports( display : flex ) screen and ( min-width : 400px );
@import url("./test.css") LAYER(DEFAULT) SUPPORTS(DISPLAY: FLEX) SCREEN AND (MIN-WIDTH: 400PX);
@import url("./test.css") /* Comment */ layer(/* Comment */default/* Comment */) /* Comment */ supports(/* Comment */display/* Comment */:/* Comment */ flex/* Comment */)/* Comment */ screen/* Comment */ and/* Comment */ (/* Comment */min-width/* Comment */: /* Comment */400px/* Comment */);
@import url(test.css) /* Comment */;
@import /* Comment */ url(test.css) /* Comment */;
@import url(test.css) /* Comment */ print and (orientation:landscape);
@import /* Comment */ url(test.css) /* Comment */ print and (orientation:landscape);

@import url("./import-with-supports.css") supports(display: flex);
@import url("./import-with-supports-and-media.css") supports(display: flex) screen and (min-width: 400px);
@import url("./import-with-layer.css") layer(default);
@import url("./import-with-layer-unnamed.css") layer(default);
@import url("./import-with-layer-and-supports.css") layer(default) supports(display: flex);
@import url("./import-with-layer-and-supports-and-media.css") layer(default) supports(display: flex) screen and (min-width: 400px);

/* TODO fix comments */
/* TODO check source maps generation */
14 changes: 14 additions & 0 deletions test/import-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ describe('"import" option', () => {
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should work when not specified and print correct output", async () => {
const compiler = getCompiler("./import/import-stringified.js");
const stats = await compile(compiler);

expect(getModuleSource("./import/import.css", stats)).toMatchSnapshot(
"module"
);
expect(getExecutedCode("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("./import/import.js", { import: true });
const stats = await compile(compiler);
Expand Down