From d54216b5cecfc21c9676f9df9520cde91f2d69e8 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Tue, 27 Nov 2018 22:13:02 +0300 Subject: [PATCH] test: ICSS support (#813) --- test/__snapshots__/icss.test.js.snap | 174 ++++++++++++++++++ .../source.css | 7 + .../tests-cases/duplicate-export/source.css | 4 + .../icss/tests-cases/empty-export/source.css | 1 + .../icss/tests-cases/empty-import/source.css | 1 + .../icss/tests-cases/export/source.css | 3 + .../icss/tests-cases/import/source.css | 11 ++ .../fixtures/icss/tests-cases/import/vars.css | 3 + .../tests-cases/multiple-export/source.css | 7 + .../multiple-keys-values-in-export/source.css | 7 + test/helpers.js | 1 + test/icss.test.js | 24 +++ 12 files changed, 243 insertions(+) create mode 100644 test/__snapshots__/icss.test.js.snap create mode 100644 test/fixtures/icss/tests-cases/duplicate-export-in-multiple-export/source.css create mode 100644 test/fixtures/icss/tests-cases/duplicate-export/source.css create mode 100644 test/fixtures/icss/tests-cases/empty-export/source.css create mode 100644 test/fixtures/icss/tests-cases/empty-import/source.css create mode 100644 test/fixtures/icss/tests-cases/export/source.css create mode 100644 test/fixtures/icss/tests-cases/import/source.css create mode 100644 test/fixtures/icss/tests-cases/import/vars.css create mode 100644 test/fixtures/icss/tests-cases/multiple-export/source.css create mode 100644 test/fixtures/icss/tests-cases/multiple-keys-values-in-export/source.css create mode 100644 test/icss.test.js diff --git a/test/__snapshots__/icss.test.js.snap b/test/__snapshots__/icss.test.js.snap new file mode 100644 index 00000000..045a44b5 --- /dev/null +++ b/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 []`; diff --git a/test/fixtures/icss/tests-cases/duplicate-export-in-multiple-export/source.css b/test/fixtures/icss/tests-cases/duplicate-export-in-multiple-export/source.css new file mode 100644 index 00000000..090df1bf --- /dev/null +++ b/test/fixtures/icss/tests-cases/duplicate-export-in-multiple-export/source.css @@ -0,0 +1,7 @@ +:export { + _test: _test; +} + +:export { + _test: _right_value; +} diff --git a/test/fixtures/icss/tests-cases/duplicate-export/source.css b/test/fixtures/icss/tests-cases/duplicate-export/source.css new file mode 100644 index 00000000..bda50f8a --- /dev/null +++ b/test/fixtures/icss/tests-cases/duplicate-export/source.css @@ -0,0 +1,4 @@ +:export { + _test: _test; + _test: _right_value; +} diff --git a/test/fixtures/icss/tests-cases/empty-export/source.css b/test/fixtures/icss/tests-cases/empty-export/source.css new file mode 100644 index 00000000..b76d40c8 --- /dev/null +++ b/test/fixtures/icss/tests-cases/empty-export/source.css @@ -0,0 +1 @@ +:export {} diff --git a/test/fixtures/icss/tests-cases/empty-import/source.css b/test/fixtures/icss/tests-cases/empty-import/source.css new file mode 100644 index 00000000..fa423e05 --- /dev/null +++ b/test/fixtures/icss/tests-cases/empty-import/source.css @@ -0,0 +1 @@ +:import("./vars.css") {} diff --git a/test/fixtures/icss/tests-cases/export/source.css b/test/fixtures/icss/tests-cases/export/source.css new file mode 100644 index 00000000..10b9ec77 --- /dev/null +++ b/test/fixtures/icss/tests-cases/export/source.css @@ -0,0 +1,3 @@ +:export { + _test: _test +} diff --git a/test/fixtures/icss/tests-cases/import/source.css b/test/fixtures/icss/tests-cases/import/source.css new file mode 100644 index 00000000..4d715aa2 --- /dev/null +++ b/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 +} diff --git a/test/fixtures/icss/tests-cases/import/vars.css b/test/fixtures/icss/tests-cases/import/vars.css new file mode 100644 index 00000000..d4fdfda6 --- /dev/null +++ b/test/fixtures/icss/tests-cases/import/vars.css @@ -0,0 +1,3 @@ +:export { + primary-color: red; +} diff --git a/test/fixtures/icss/tests-cases/multiple-export/source.css b/test/fixtures/icss/tests-cases/multiple-export/source.css new file mode 100644 index 00000000..45724d97 --- /dev/null +++ b/test/fixtures/icss/tests-cases/multiple-export/source.css @@ -0,0 +1,7 @@ +:export { + _test: _test +} + +:export { + _foo: _bar +} diff --git a/test/fixtures/icss/tests-cases/multiple-keys-values-in-export/source.css b/test/fixtures/icss/tests-cases/multiple-keys-values-in-export/source.css new file mode 100644 index 00000000..8449fe4e --- /dev/null +++ b/test/fixtures/icss/tests-cases/multiple-keys-values-in-export/source.css @@ -0,0 +1,7 @@ +:export { + _test: _test; + _test1: 1; + _test2: 'string'; + _test3: 1px 2px 3px; + _test4: 1px 2px 3px, 1px 2px 3px; +} diff --git a/test/helpers.js b/test/helpers.js index 03dfe658..6e769346 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -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', diff --git a/test/icss.test.js b/test/icss.test.js new file mode 100644 index 00000000..01599bad --- /dev/null +++ b/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'); + }); + }); +});