Skip to content

Commit dc8464b

Browse files
refactor: getLocalIdent option tests (#807)
1 parent 4bdf08b commit dc8464b

File tree

4 files changed

+116
-18
lines changed

4 files changed

+116
-18
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`getLocalIdent option should work (\`modules: false\`): errors 1`] = `Array []`;
4+
5+
exports[`getLocalIdent option should work (\`modules: false\`): locals 1`] = `
6+
Object {
7+
"def": "foo",
8+
"ghi": "foo",
9+
"jkl": "foo",
10+
}
11+
`;
12+
13+
exports[`getLocalIdent option should work (\`modules: false\`): module (evaluated) 1`] = `
14+
Array [
15+
Array [
16+
1,
17+
".abc .foo {
18+
color: red;
19+
}
20+
21+
.foo .foo {
22+
color: blue;
23+
}
24+
",
25+
"",
26+
],
27+
]
28+
`;
29+
30+
exports[`getLocalIdent option should work (\`modules: false\`): warnings 1`] = `Array []`;
31+
32+
exports[`getLocalIdent option should work (\`modules: true\`): errors 1`] = `Array []`;
33+
34+
exports[`getLocalIdent option should work (\`modules: true\`): locals 1`] = `
35+
Object {
36+
"abc": "foo",
37+
"def": "foo",
38+
"ghi": "foo",
39+
"jkl": "foo",
40+
}
41+
`;
42+
43+
exports[`getLocalIdent option should work (\`modules: true\`): module (evaluated) 1`] = `
44+
Array [
45+
Array [
46+
1,
47+
".foo .foo {
48+
color: red;
49+
}
50+
51+
.foo .foo {
52+
color: blue;
53+
}
54+
",
55+
"",
56+
],
57+
]
58+
`;
59+
60+
exports[`getLocalIdent option should work (\`modules: true\`): warnings 1`] = `Array []`;

test/customGetLocalIdent.test.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.abc :local(.def) {
2+
color: red;
3+
}
4+
5+
:local .ghi .jkl {
6+
color: blue;
7+
}

test/getLocalIdent-option.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const { webpack, evaluated } = require('./helpers');
2+
3+
describe('getLocalIdent option', () => {
4+
it('should work (`modules: true`)', async () => {
5+
const config = {
6+
loader: {
7+
options: {
8+
modules: true,
9+
getLocalIdent() {
10+
return 'foo';
11+
},
12+
},
13+
},
14+
};
15+
const testId = './modules/getLocalIdent.css';
16+
const stats = await webpack(testId, config);
17+
const { modules } = stats.toJson();
18+
const module = modules.find((m) => m.id === testId);
19+
const evaluatedModule = evaluated(module.source);
20+
21+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
22+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
23+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
24+
expect(stats.compilation.errors).toMatchSnapshot('errors');
25+
});
26+
27+
it('should work (`modules: false`)', async () => {
28+
const config = {
29+
loader: {
30+
options: {
31+
modules: false,
32+
getLocalIdent() {
33+
return 'foo';
34+
},
35+
},
36+
},
37+
};
38+
const testId = './modules/getLocalIdent.css';
39+
const stats = await webpack(testId, config);
40+
const { modules } = stats.toJson();
41+
const module = modules.find((m) => m.id === testId);
42+
const evaluatedModule = evaluated(module.source);
43+
44+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
45+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
46+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
47+
expect(stats.compilation.errors).toMatchSnapshot('errors');
48+
});
49+
});

0 commit comments

Comments
 (0)