Skip to content

Commit 4804a2d

Browse files
test: more
1 parent 28ab0aa commit 4804a2d

13 files changed

+1211
-56
lines changed

src/plugins/postcss-import-parser.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ function parseNode(atRule, key) {
5050
throw error;
5151
}
5252

53-
const { nodes: paramsNodes } = valueParser(atRule[key]);
53+
const rawParams =
54+
atRule.raws &&
55+
atRule.raws[key] &&
56+
typeof atRule.raws[key].raw !== "undefined"
57+
? atRule.raws[key].raw
58+
: atRule[key];
59+
const { nodes: paramsNodes } = valueParser(rawParams);
5460

5561
// No nodes - `@import ;`
5662
// Invalid type - `@import foo-bar;`

test/__snapshots__/import-option.test.js.snap

+1,148-50
Large diffs are not rendered by default.

test/__snapshots__/sourceMap-option.test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ exports[`"sourceMap" option true should generate source maps when css was extrac
313313
exports[`"sourceMap" option true should generate source maps when css was extracted and do not change "[contenthash]" on different platform: source map 1`] = `
314314
Object {
315315
"file": "main.xxxxxxxxxxxxxxxxxxxx.css",
316-
"mappings": "AAAA;EACE,WAAW;AACb;;;;;ACAA;EACE,UAAU;AACZ",
316+
"mappings": ";;;AAAA;EACE,WAAW;AACb;;;;;ACAA;EACE,UAAU;AACZ",
317317
"names": Array [],
318318
"sourceRoot": "",
319319
"sources": Array [
@@ -362,7 +362,7 @@ exports[`"sourceMap" option true should generate source maps when css was extrac
362362
exports[`"sourceMap" option true should generate source maps when css was extracted: source map 1`] = `
363363
Object {
364364
"file": "main.css",
365-
"mappings": "AAAA;EACE,WAAW;AACb;;;;;ACAA;EACE,UAAU;AACZ",
365+
"mappings": ";;;AAAA;EACE,WAAW;AACb;;;;;ACAA;EACE,UAAU;AACZ",
366366
"names": Array [],
367367
"sourceRoot": "",
368368
"sources": Array [

test/__snapshots__/validate-options.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ exports[`validate options should throw an error on the "importLoaders" option wi
6363
Details:
6464
* options.importLoaders should be a boolean.
6565
* options.importLoaders should be a string.
66-
* options.importLoaders should be a integer."
66+
* options.importLoaders should be an integer."
6767
`;
6868
6969
exports[`validate options should throw an error on the "modules" option with "{"auto":"invalid"}" value 1`] = `
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import css from './import.css';
2+
3+
__export__ = css.toString();
4+
5+
export default css;

test/fixtures/import/import-with-layer-and-supports-and-media.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import url('./test.css') layer(base);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import url('./test.css') layer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import url('./test.css') layer(base) supports(display: grid);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import url('./test.css') supports(display: grid) handheld and (max-width: 400px);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import url('./test.css') supports(display: grid);

test/fixtures/import/import.css

+28-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@import url( test.css);
88
@import url( test.css );
99
@import url(
10-
test.css
10+
test.css
1111
);
1212
@import url();
1313
@import url('');
@@ -53,7 +53,7 @@
5353
}
5454

5555
.foo {
56-
@import 'path.css';
56+
@import 'path.css';
5757
}
5858

5959
@import url('./relative.css');
@@ -158,3 +158,29 @@ st.css');
158158
/* Prefer relative */
159159
@import url(package/first.css);
160160
@import url(package/second.css);
161+
162+
@import url("./test.css") supports(display: flex);
163+
@import url("./test.css") supports(display: flex) screen and (min-width: 400px);
164+
@import url("./test.css") layer;
165+
@import url("./test.css") layer(default);
166+
@import url("./test.css") layer(default) supports(display: flex) screen and (min-width: 400px);
167+
@import url("http://example.com/style.css") supports(display: flex) screen and (min-width: 400px);
168+
@import url("./test.css")layer(default)supports(display: flex)screen and (min-width:400px);
169+
@import url("./test.css")screen and (min-width: 400px);
170+
@import url("./test.css") layer( default ) supports( display : flex ) screen and ( min-width : 400px );
171+
@import url("./test.css") LAYER(DEFAULT) SUPPORTS(DISPLAY: FLEX) SCREEN AND (MIN-WIDTH: 400PX);
172+
@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 */);
173+
@import url(test.css) /* Comment */;
174+
@import /* Comment */ url(test.css) /* Comment */;
175+
@import url(test.css) /* Comment */ print and (orientation:landscape);
176+
@import /* Comment */ url(test.css) /* Comment */ print and (orientation:landscape);
177+
178+
@import url("./import-with-supports.css") supports(display: flex);
179+
@import url("./import-with-supports-and-media.css") supports(display: flex) screen and (min-width: 400px);
180+
@import url("./import-with-layer.css") layer(default);
181+
@import url("./import-with-layer-unnamed.css") layer(default);
182+
@import url("./import-with-layer-and-supports.css") layer(default) supports(display: flex);
183+
@import url("./import-with-layer-and-supports-and-media.css") layer(default) supports(display: flex) screen and (min-width: 400px);
184+
185+
/* TODO fix comments */
186+
/* TODO check source maps generation */

test/import-option.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ describe('"import" option', () => {
2727
expect(getErrors(stats)).toMatchSnapshot("errors");
2828
});
2929

30+
it("should work when not specified and print correct output", async () => {
31+
const compiler = getCompiler("./import/import-stringified.js");
32+
const stats = await compile(compiler);
33+
34+
expect(getModuleSource("./import/import.css", stats)).toMatchSnapshot(
35+
"module"
36+
);
37+
expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot(
38+
"result"
39+
);
40+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
41+
expect(getErrors(stats)).toMatchSnapshot("errors");
42+
});
43+
3044
it('should work with a value equal to "true"', async () => {
3145
const compiler = getCompiler("./import/import.js", { import: true });
3246
const stats = await compile(compiler);

0 commit comments

Comments
 (0)