Skip to content

Commit

Permalink
test: more
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Sep 15, 2021
1 parent 28ab0aa commit 4804a2d
Show file tree
Hide file tree
Showing 13 changed files with 1,211 additions and 56 deletions.
8 changes: 7 additions & 1 deletion src/plugins/postcss-import-parser.js
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
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
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
@@ -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
@@ -0,0 +1 @@
@import url('./test.css') layer(base);
1 change: 1 addition & 0 deletions test/fixtures/import/import-with-layer-unnamed.css
@@ -0,0 +1 @@
@import url('./test.css') layer;
1 change: 1 addition & 0 deletions test/fixtures/import/import-with-layer.css
@@ -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
@@ -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
@@ -0,0 +1 @@
@import url('./test.css') supports(display: grid);
30 changes: 28 additions & 2 deletions test/fixtures/import/import.css
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
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

0 comments on commit 4804a2d

Please sign in to comment.