Skip to content

Commit

Permalink
refactor: modules option tests (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Nov 27, 2018
1 parent b0db66f commit 53a7fe5
Show file tree
Hide file tree
Showing 54 changed files with 1,735 additions and 515 deletions.
1,581 changes: 1,581 additions & 0 deletions test/__snapshots__/modules-option.test.js.snap

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:local(.c1/*.c2*/.c3) { background: red; }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/

.bg {
background-image: url(bg.jpg);
background-image: url(./img.png);
}

/*
* a ' below
*/
*/
11 changes: 11 additions & 0 deletions test/fixtures/modules/tests-cases/composes-1/file.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:local(.c2) {
color: red;
}

:local(.c4) {
color: blue;
}

.test{
c: d
}
3 changes: 3 additions & 0 deletions test/fixtures/modules/tests-cases/composes-1/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.c1) { composes: c2 from "./file.css"; b: 1; }
:local(.c3) { composes: c1; b: 3; }
:local(.c5) { composes: c2 c4 from "./file.css"; b: 5; }
11 changes: 11 additions & 0 deletions test/fixtures/modules/tests-cases/composes-2/file.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:local(.c-2) {
color: red;
}

:local(.c4) {
color: blue;
}

.test{
c: d
}
3 changes: 3 additions & 0 deletions test/fixtures/modules/tests-cases/composes-2/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.c1) { composes: c-2 from "./file.css"; b: 1; }
:local(.c3) { composes: c1; b: 3; }
:local(.c5) { composes: c-2 c4 from "./file.css"; b: 5; }
3 changes: 3 additions & 0 deletions test/fixtures/modules/tests-cases/composes-multiple/file1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.def1) {
color: red;
}
3 changes: 3 additions & 0 deletions test/fixtures/modules/tests-cases/composes-multiple/file2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.def2) {
color: blue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:local(.abc) {
composes: def1 from "./file1.css";
composes: def2 from "./file2.css";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.def) {
color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.abc) {
composes: def from "./file.css";
}
2 changes: 2 additions & 0 deletions test/fixtures/modules/tests-cases/composes/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:local(.c1) { a: 1; }
:local(.c2) { composes: c1; b: 1; }
File renamed without changes.
4 changes: 4 additions & 0 deletions test/fixtures/modules/tests-cases/local-2/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:local(.className) { background: red; }
:local(#someId) { background: green; }
:local(.className .subClass) { color: green; }
:local(#someId .subClass) { color: blue; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:local(.abc) {
color: red;
}
:local(.def) {
composes: abc;
background: green;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.c1[data-attr=".c2)]'"]:not(.c3):not(.c4)) {
background: red;
}
7 changes: 7 additions & 0 deletions test/fixtures/modules/tests-cases/local/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.abc :local(.def) {
color: red;
}

:local .ghi .jkl {
color: blue;
}
2 changes: 2 additions & 0 deletions test/fixtures/modules/tests-cases/mode-switching/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.c1 :local .c2 .c3 :global .c4 :local .c5, .c6 :local .c7 { background: red; }
.c8 { background: red; }
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/modules/tests-cases/urls/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions test/fixtures/modules/tests-cases/urls/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.a {
background: url(./img.png);
background: url("./img.png");
background: url("./img img.png");
background: url('./img img.png');
background: url('./img.png');
background: url("./img.png#?iefix");
background: url("#hash");
background: url("#");
background: url(data:image/png;base64,AAA);
background: url(http://example.com/image.jpg);
background: url(//example.com/image.png);
background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) url(./img.png) xyz;
}
2 changes: 2 additions & 0 deletions test/fixtures/modules/tests-cases/values-1/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@value def: red;
@value ghi: 1px solid black;
2 changes: 2 additions & 0 deletions test/fixtures/modules/tests-cases/values-2/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@value def: red;
.ghi { color: def; }
1 change: 1 addition & 0 deletions test/fixtures/modules/tests-cases/values-3/file.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@value def: red;
2 changes: 2 additions & 0 deletions test/fixtures/modules/tests-cases/values-3/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@value def from './file.css';
.ghi { color: def; }
1 change: 1 addition & 0 deletions test/fixtures/modules/tests-cases/values-4/file1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@value def: red;
1 change: 1 addition & 0 deletions test/fixtures/modules/tests-cases/values-4/file2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@value def: green;
3 changes: 3 additions & 0 deletions test/fixtures/modules/tests-cases/values-4/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@value def as aaa from './file1.css';
@value def as bbb from './file2.css';
.ghi { background: aaa, bbb, def; }
1 change: 1 addition & 0 deletions test/fixtures/modules/tests-cases/values-5/file1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@value color: red;
3 changes: 3 additions & 0 deletions test/fixtures/modules/tests-cases/values-5/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@value color from './file1.css';
@value shadow: 0 0 color,0 0 color;
.ghi { box-shadow: shadow; }
1 change: 1 addition & 0 deletions test/fixtures/modules/tests-cases/values-6/file1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@value color: red;
3 changes: 3 additions & 0 deletions test/fixtures/modules/tests-cases/values-6/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@value color from './file1.css';
@value shadow: 0 0 color ,0 0 color;
.ghi { box-shadow: shadow; }
1 change: 1 addition & 0 deletions test/fixtures/modules/tests-cases/values-7/file1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@value color: red;
3 changes: 3 additions & 0 deletions test/fixtures/modules/tests-cases/values-7/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@value color from './file1.css';
@value shadow: 0 0 color, 0 0 color;
.ghi { box-shadow: shadow; }
File renamed without changes.
11 changes: 11 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ function evaluated(output, modules, moduleId = 1) {
'import/node_modules',
'url',
'url/node_modules',
'modules/tests-cases/urls',
'modules/tests-cases/comments',
'modules/tests-cases/values-3',
'modules/tests-cases/values-4',
'modules/tests-cases/values-5',
'modules/tests-cases/values-6',
'modules/tests-cases/values-7',
'modules/tests-cases/composes-1',
'modules/tests-cases/composes-2',
'modules/tests-cases/composes-multiple',
'modules/tests-cases/composes-with-importing',
].map((importedPath) =>
path.resolve(__dirname, `./fixtures/${importedPath}`, module)
);
Expand Down
153 changes: 0 additions & 153 deletions test/local.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,159 +34,6 @@ describe('local', () => {
subClass: '_1s1VsToXFz17cPAltMg7jz',
}
);
testLocal(
'mode switching',
'.c1 :local .c2 .c3 :global .c4 :local .c5, .c6 :local .c7 { background: red; }\n.c8 { background: red; }',
[
[
1,
'.c1 ._c2 ._c3 .c4 ._c5, .c6 ._c7 { background: red; }\n.c8 { background: red; }',
'',
],
],
{
c2: '_c2',
c3: '_c3',
c5: '_c5',
c7: '_c7',
},
'?localIdentName=_[local]'
);
testLocal(
'comment in local',
':local(.c1/*.c2*/.c3) { background: red; }',
[[1, '._c1/*.c2*/._c3 { background: red; }', '']],
{
c1: '_c1',
c3: '_c3',
},
'?localIdentName=_[local]'
);
testLocal(
'comment in local',
':local(.c1/*.c2*/.c3) { background: red; }',
[[1, '._c1/*.c2*/._c3 { background: red; }', '']],
{
c1: '_c1',
c3: '_c3',
},
'?localIdentName=_[local]'
);
testLocal(
'strings in local',
':local(.c1[data-attr=".c2)]\'"]:not(.c3):not(.c4)) { background: red; }',
[
[
1,
'._c1[data-attr=".c2)]\'"]:not(._c3):not(._c4) { background: red; }',
'',
],
],
{
c1: '_c1',
c3: '_c3',
c4: '_c4',
},
'?localIdentName=_[local]'
);

testLocal(
'composes class simple',
':local(.c1) { a: 1; }\n:local(.c2) { composes: c1; b: 1; }',
[[1, '._c1 { a: 1; }\n._c2 { b: 1; }', '']],
{
c1: '_c1',
c2: '_c2 _c1',
},
'?localIdentName=_[local]'
);
testLocal(
'composes class from module',
[
':local(.c1) { composes: c2 from "./module"; b: 1; }',
':local(.c3) { composes: c1; b: 3; }',
':local(.c5) { composes: c2 c4 from "./module"; b: 5; }',
].join('\n'),
[
[2, '.test{c: d}', ''],
[
1,
['._c1 { b: 1; }', '._c3 { b: 3; }', '._c5 { b: 5; }'].join('\n'),
'',
],
],
{
c1: '_c1 imported-c2',
c3: '_c3 _c1 imported-c2',
c5: '_c5 imported-c2 imported-c4',
},
'?localIdentName=_[local]',
{
'./module': (() => {
const r = [[2, '.test{c: d}', '']];
r.locals = {
c2: 'imported-c2',
c4: 'imported-c4',
};
return r;
})(),
}
);
testLocal(
'composes class with hyphen from module',
[
':local(.c1) { composes: c-2 from "./module"; b: 1; }',
':local(.c3) { composes: c1; b: 3; }',
':local(.c5) { composes: c-2 c4 from "./module"; b: 5; }',
].join('\n'),
[
[2, '.test{c: d}', ''],
[
1,
['._c1 { b: 1; }', '._c3 { b: 3; }', '._c5 { b: 5; }'].join('\n'),
'',
],
],
{
c1: '_c1 imported-c-2',
c3: '_c3 _c1 imported-c-2',
c5: '_c5 imported-c-2 imported-c4',
},
'?localIdentName=_[local]',
{
'./module': (() => {
const r = [[2, '.test{c: d}', '']];
r.locals = {
'c-2': 'imported-c-2',
c4: 'imported-c4',
};
return r;
})(),
}
);
testLocal(
'composes class from module with import',
[
'@import url("module");',
':local(.c1) { composes: c2 c3 from "./module"; composes: c4 from "./module"; b: 1; }',
].join('\n'),
[[2, '.test{c: d}', ''], [1, '._c1 { b: 1; }', '']],
{
c1: '_c1 imported-c2 imported-c3 imported-c4',
},
'?localIdentName=_[local]',
{
'./module': (() => {
const r = [[2, '.test{c: d}', '']];
r.locals = {
c2: 'imported-c2',
c3: 'imported-c3',
c4: 'imported-c4',
};
return r;
})(),
}
);
testLocal(
'module mode',
".className { background: url(./file.png); }\n#someId { background: url('module/file.jpg'); }\n" +
Expand Down
62 changes: 0 additions & 62 deletions test/locals.test.js

This file was deleted.

Loading

0 comments on commit 53a7fe5

Please sign in to comment.