Skip to content

Commit

Permalink
test: import through plugin (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed Apr 22, 2020
1 parent 221714b commit b04cb0d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Empty file added test/fixtures/less/empty.less
Empty file.
13 changes: 13 additions & 0 deletions test/fixtures/less/folder/customImportPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class PluginPreProcessor {
process() {
return '.imported-class {color: coral;}'
}
}

class CustomImportPlugin {
install(less, pluginManager) {
pluginManager.addPreProcessor(new PluginPreProcessor());
}
}

module.exports = CustomImportPlugin;
21 changes: 21 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit b04cb0d

Please sign in to comment.