From 1bfbf14f45265b4ccf1b58210599fe6259f090e0 Mon Sep 17 00:00:00 2001 From: Brian Link Date: Thu, 11 May 2017 16:32:06 -0700 Subject: [PATCH 1/2] Adds failing test for nested imports. --- test/fixtures/less/folder/nested.less | 3 +++ test/fixtures/less/import-nested.less | 1 + test/helpers/moduleRules.js | 20 ++++++++++++++++++++ test/helpers/nestedFileLoader.js | 5 +++++ test/index.test.js | 13 +++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 test/fixtures/less/folder/nested.less create mode 100644 test/fixtures/less/import-nested.less create mode 100644 test/helpers/nestedFileLoader.js diff --git a/test/fixtures/less/folder/nested.less b/test/fixtures/less/folder/nested.less new file mode 100644 index 00000000..5d06a490 --- /dev/null +++ b/test/fixtures/less/folder/nested.less @@ -0,0 +1,3 @@ +.nested-import-css { + background: <%= color %>; +} \ No newline at end of file diff --git a/test/fixtures/less/import-nested.less b/test/fixtures/less/import-nested.less new file mode 100644 index 00000000..da6a993c --- /dev/null +++ b/test/fixtures/less/import-nested.less @@ -0,0 +1 @@ +@import "folder/nested.less"; diff --git a/test/helpers/moduleRules.js b/test/helpers/moduleRules.js index 0572ef43..4b6fc2f1 100644 --- a/test/helpers/moduleRules.js +++ b/test/helpers/moduleRules.js @@ -1,6 +1,7 @@ const lessLoader = require.resolve('../../src'); const helperLoader = require.resolve('./helperLoader.js'); const someFileLoader = require.resolve('./someFileLoader.js'); +const nestedFileLoader = require.resolve('./nestedFileLoader.js'); function basic(lessLoaderOptions, lessLoaderContext = {}, inspectCallback = () => {}) { return [{ @@ -42,5 +43,24 @@ function nonLessImport(inspectCallback) { }]; } +function nestedImport(inspectCallback) { + return [{ + test: /\.less$/, + loaders: [{ + loader: helperLoader, + }, { + loader: 'inspect-loader', + options: { + callback: inspectCallback, + }, + }, { + loader: lessLoader, + }, { + loader: nestedFileLoader, + }], + }]; +} + exports.basic = basic; exports.nonLessImport = nonLessImport; +exports.nestedImport = nestedImport; diff --git a/test/helpers/nestedFileLoader.js b/test/helpers/nestedFileLoader.js new file mode 100644 index 00000000..4f1bc6f9 --- /dev/null +++ b/test/helpers/nestedFileLoader.js @@ -0,0 +1,5 @@ +function nestedFileLoader(source) { + return source.replace('<%= color %>', 'hotpink'); +} + +module.exports = nestedFileLoader; diff --git a/test/index.test.js b/test/index.test.js index a6c1ea41..52db1b37 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -157,6 +157,19 @@ test('should allow to import non-less files', async () => { expect(css).toMatch(/\.some-file {\s*background: hotpink;\s*}\s*/); }); +test('should run webpack loaders on nested imports', async () => { + let inspect; + const rules = moduleRules.nestedImport((i) => { + inspect = i; + }); + + await compile('import-nested', rules); + + const [css] = inspect.arguments; + + expect(css).toMatch(/\.nested-import-css {\s*background: hotpink;\s*}\s*/); +}); + test('should compile data-uri function', async () => { await compileAndCompare('data-uri'); }); From 0f51867ba1f0263690abd8ac4fd8492c9265157a Mon Sep 17 00:00:00 2001 From: Brian Link Date: Thu, 11 May 2017 16:35:26 -0700 Subject: [PATCH 2/2] Prove that the loader runs on the top import. --- test/fixtures/less/folder/nested.less | 2 +- test/fixtures/less/import-nested.less | 4 ++++ test/index.test.js | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/fixtures/less/folder/nested.less b/test/fixtures/less/folder/nested.less index 5d06a490..57aa8a2c 100644 --- a/test/fixtures/less/folder/nested.less +++ b/test/fixtures/less/folder/nested.less @@ -1,3 +1,3 @@ -.nested-import-css { +.nested-import { background: <%= color %>; } \ No newline at end of file diff --git a/test/fixtures/less/import-nested.less b/test/fixtures/less/import-nested.less index da6a993c..69170bcf 100644 --- a/test/fixtures/less/import-nested.less +++ b/test/fixtures/less/import-nested.less @@ -1 +1,5 @@ +.top-import { + background: <%= color %>; +} + @import "folder/nested.less"; diff --git a/test/index.test.js b/test/index.test.js index 52db1b37..8858c9d8 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -167,7 +167,7 @@ test('should run webpack loaders on nested imports', async () => { const [css] = inspect.arguments; - expect(css).toMatch(/\.nested-import-css {\s*background: hotpink;\s*}\s*/); + expect(css).toMatch(/\.top-import {\s*background: hotpink;\s*}\s*\.nested-import {\s*background: hotpink;\s*}\s*/); }); test('should compile data-uri function', async () => {