Skip to content

Commit

Permalink
test: ICSS support (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Nov 27, 2018
1 parent 0a68bb4 commit d54216b
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 0 deletions.
174 changes: 174 additions & 0 deletions test/__snapshots__/icss.test.js.snap
@@ -0,0 +1,174 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ICSS case duplicate-export: errors 1`] = `Array []`;

exports[`ICSS case duplicate-export: locals 1`] = `
Object {
"_test": "_right_value",
}
`;

exports[`ICSS case duplicate-export: module (evaluated) 1`] = `
Array [
Array [
1,
"
",
"",
],
]
`;

exports[`ICSS case duplicate-export: warnings 1`] = `Array []`;

exports[`ICSS case duplicate-export-in-multiple-export: errors 1`] = `Array []`;

exports[`ICSS case duplicate-export-in-multiple-export: locals 1`] = `
Object {
"_test": "_right_value",
}
`;

exports[`ICSS case duplicate-export-in-multiple-export: module (evaluated) 1`] = `
Array [
Array [
1,
"
",
"",
],
]
`;

exports[`ICSS case duplicate-export-in-multiple-export: warnings 1`] = `Array []`;

exports[`ICSS case empty-export: errors 1`] = `Array []`;

exports[`ICSS case empty-export: locals 1`] = `undefined`;

exports[`ICSS case empty-export: module (evaluated) 1`] = `
Array [
Array [
1,
"
",
"",
],
]
`;

exports[`ICSS case empty-export: warnings 1`] = `Array []`;

exports[`ICSS case empty-import: errors 1`] = `Array []`;

exports[`ICSS case empty-import: locals 1`] = `undefined`;

exports[`ICSS case empty-import: module (evaluated) 1`] = `
Array [
Array [
1,
"
",
"",
],
]
`;

exports[`ICSS case empty-import: warnings 1`] = `Array []`;

exports[`ICSS case export: errors 1`] = `Array []`;

exports[`ICSS case export: locals 1`] = `
Object {
"_test": "_test",
}
`;

exports[`ICSS case export: module (evaluated) 1`] = `
Array [
Array [
1,
"
",
"",
],
]
`;

exports[`ICSS case export: warnings 1`] = `Array []`;

exports[`ICSS case import: errors 1`] = `Array []`;

exports[`ICSS case import: locals 1`] = `
Object {
"primary-color": "red",
}
`;

exports[`ICSS case import: module (evaluated) 1`] = `
Array [
Array [
2,
"
",
"",
],
Array [
1,
".className {
color: red;
}
",
"",
],
]
`;

exports[`ICSS case import: warnings 1`] = `Array []`;

exports[`ICSS case multiple-export: errors 1`] = `Array []`;

exports[`ICSS case multiple-export: locals 1`] = `
Object {
"_foo": "_bar",
"_test": "_test",
}
`;

exports[`ICSS case multiple-export: module (evaluated) 1`] = `
Array [
Array [
1,
"
",
"",
],
]
`;

exports[`ICSS case multiple-export: warnings 1`] = `Array []`;

exports[`ICSS case multiple-keys-values-in-export: errors 1`] = `Array []`;

exports[`ICSS case multiple-keys-values-in-export: locals 1`] = `
Object {
"_test": "_test",
"_test1": "1",
"_test2": "'string'",
"_test3": "1px 2px 3px",
"_test4": "1px 2px 3px, 1px 2px 3px",
}
`;

exports[`ICSS case multiple-keys-values-in-export: module (evaluated) 1`] = `
Array [
Array [
1,
"
",
"",
],
]
`;

exports[`ICSS case multiple-keys-values-in-export: warnings 1`] = `Array []`;
@@ -0,0 +1,7 @@
:export {
_test: _test;
}

:export {
_test: _right_value;
}
4 changes: 4 additions & 0 deletions test/fixtures/icss/tests-cases/duplicate-export/source.css
@@ -0,0 +1,4 @@
:export {
_test: _test;
_test: _right_value;
}
1 change: 1 addition & 0 deletions test/fixtures/icss/tests-cases/empty-export/source.css
@@ -0,0 +1 @@
:export {}
1 change: 1 addition & 0 deletions test/fixtures/icss/tests-cases/empty-import/source.css
@@ -0,0 +1 @@
:import("./vars.css") {}
3 changes: 3 additions & 0 deletions test/fixtures/icss/tests-cases/export/source.css
@@ -0,0 +1,3 @@
:export {
_test: _test
}
11 changes: 11 additions & 0 deletions test/fixtures/icss/tests-cases/import/source.css
@@ -0,0 +1,11 @@
:import("./vars.css") {
IMPORTED_NAME: primary-color;
}

.className {
color: IMPORTED_NAME;
}

:export {
primary-color: IMPORTED_NAME
}
3 changes: 3 additions & 0 deletions test/fixtures/icss/tests-cases/import/vars.css
@@ -0,0 +1,3 @@
:export {
primary-color: red;
}
7 changes: 7 additions & 0 deletions test/fixtures/icss/tests-cases/multiple-export/source.css
@@ -0,0 +1,7 @@
:export {
_test: _test
}

:export {
_foo: _bar
}
@@ -0,0 +1,7 @@
:export {
_test: _test;
_test1: 1;
_test2: 'string';
_test3: 1px 2px 3px;
_test4: 1px 2px 3px, 1px 2px 3px;
}
1 change: 1 addition & 0 deletions test/helpers.js
Expand Up @@ -34,6 +34,7 @@ function evaluated(output, modules, moduleId = 1) {
const importedModule = modules.find((el) => {
const modulePath = el.identifier.split('!').pop();
const importedPaths = [
'icss/tests-cases/import',
'import',
'import/node_modules',
'url',
Expand Down
24 changes: 24 additions & 0 deletions test/icss.test.js
@@ -0,0 +1,24 @@
const path = require('path');
const fs = require('fs');

const { webpack, evaluated } = require('./helpers');

const testCasesPath = path.join(__dirname, 'fixtures/icss/tests-cases');
const testCases = fs.readdirSync(testCasesPath);

describe('ICSS', () => {
testCases.forEach((name) => {
it(`case ${name}`, async () => {
const testId = `./icss/tests-cases/${name}/source.css`;
const stats = await webpack(testId);
const { modules } = stats.toJson();
const module = modules.find((m) => m.id === testId);
const evaluatedModule = evaluated(module.source, modules);

expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
expect(evaluatedModule.locals).toMatchSnapshot('locals');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});
});
});

0 comments on commit d54216b

Please sign in to comment.