From b04cb0dae3e107a03f3e39b6230a50c90a4cbcda Mon Sep 17 00:00:00 2001 From: Alexey Lavinsky Date: Wed, 22 Apr 2020 13:59:53 +0300 Subject: [PATCH] test: import through plugin (#341) --- test/fixtures/less/empty.less | 0 .../less/folder/customImportPlugin.js | 13 ++++++++++++ test/index.test.js | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test/fixtures/less/empty.less create mode 100644 test/fixtures/less/folder/customImportPlugin.js diff --git a/test/fixtures/less/empty.less b/test/fixtures/less/empty.less new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/less/folder/customImportPlugin.js b/test/fixtures/less/folder/customImportPlugin.js new file mode 100644 index 00000000..40ab9ded --- /dev/null +++ b/test/fixtures/less/folder/customImportPlugin.js @@ -0,0 +1,13 @@ +class PluginPreProcessor { + process() { + return '.imported-class {color: coral;}' + } +} + +class CustomImportPlugin { + install(less, pluginManager) { + pluginManager.addPreProcessor(new PluginPreProcessor()); + } +} + +module.exports = CustomImportPlugin; diff --git a/test/index.test.js b/test/index.test.js index e6875aa7..e51a4687 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -5,6 +5,7 @@ import moduleRules from './helpers/moduleRules'; import { readCssFixture, readSourceMap } from './helpers/readFixture'; import compareErrorMessage from './helpers/compareErrorMessage'; import getErrors from './helpers/getErrors'; +import CustomImportPlugin from './fixtures/less/folder/customImportPlugin'; const nodeModulesPath = path.resolve(__dirname, 'fixtures', 'node_modules'); @@ -301,6 +302,26 @@ test('should install plugins', async () => { expect(pluginInstalled).toBe(true); }); +test('should import from plugins', async () => { + const loaderOptions = { + lessOptions: { + plugins: [new CustomImportPlugin()], + }, + }; + + let inspect; + + const rules = moduleRules.basic(loaderOptions, {}, (i) => { + inspect = i; + }); + + await compile('empty', rules).catch((e) => e); + + const [css] = inspect.arguments; + + expect(css).toEqual('.imported-class {\n color: coral;\n}\n'); +}); + test('should not alter the original options object', async () => { const options = { lessOptions: { plugins: [] } }; const copiedOptions = { ...options };