-
-
Notifications
You must be signed in to change notification settings - Fork 609
/
Copy pathmodules-option.test.js
39 lines (35 loc) · 1.42 KB
/
modules-option.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const path = require('path');
const fs = require('fs');
const { webpack, evaluated } = require('./helpers');
const testCasesPath = path.join(__dirname, 'fixtures/modules/tests-cases');
const testCases = fs.readdirSync(testCasesPath);
describe('modules', () => {
[false, true].forEach((exportOnlyLocalsValue) => {
[false, true].forEach((modulesValue) => {
testCases.forEach((name) => {
it(`case \`${name}\`: (export \`${
exportOnlyLocalsValue ? 'only locals' : 'all'
}\`) (\`modules\` value is \`${modulesValue})\``, async () => {
const config = {
loader: {
options: {
modules: modulesValue,
exportOnlyLocals: exportOnlyLocalsValue,
localIdentName: '_[local]',
},
},
};
const testId = `./modules/tests-cases/${name}/source.css`;
const stats = await webpack(testId, config);
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');
});
});
});
});
});