Skip to content

Commit 58dd0d3

Browse files
committedNov 27, 2018
test: localIdentName option
1 parent 0a68bb4 commit 58dd0d3

File tree

4 files changed

+283
-2
lines changed

4 files changed

+283
-2
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`localIdentName option should have hash: errors 1`] = `Array []`;
4+
5+
exports[`localIdentName option should have hash: locals 1`] = `
6+
Object {
7+
"_test": "localIdentName--_test--3Q--B",
8+
"test": "localIdentName--test--1Os7J",
9+
}
10+
`;
11+
12+
exports[`localIdentName option should have hash: module (evaluated) 1`] = `
13+
Array [
14+
Array [
15+
1,
16+
".localIdentName--test--1Os7J {
17+
background: red;
18+
}
19+
20+
.localIdentName--_test--3Q--B {
21+
background: blue;
22+
}
23+
",
24+
"",
25+
],
26+
]
27+
`;
28+
29+
exports[`localIdentName option should have hash: warnings 1`] = `Array []`;
30+
31+
exports[`localIdentName option should have path naming with context: errors 1`] = `Array []`;
32+
33+
exports[`localIdentName option should have path naming with context: locals 1`] = `
34+
Object {
35+
"_test": "fixtures-modules--localIdentName--_test",
36+
"test": "fixtures-modules--localIdentName--test",
37+
}
38+
`;
39+
40+
exports[`localIdentName option should have path naming with context: module (evaluated) 1`] = `
41+
Array [
42+
Array [
43+
1,
44+
".fixtures-modules--localIdentName--test {
45+
background: red;
46+
}
47+
48+
.fixtures-modules--localIdentName--_test {
49+
background: blue;
50+
}
51+
",
52+
"",
53+
],
54+
]
55+
`;
56+
57+
exports[`localIdentName option should have path naming with context: warnings 1`] = `Array []`;
58+
59+
exports[`localIdentName option should prefixes leading hyphen + digit with underscore: errors 1`] = `Array []`;
60+
61+
exports[`localIdentName option should prefixes leading hyphen + digit with underscore: locals 1`] = `
62+
Object {
63+
"_test": "_-1_test",
64+
"test": "_-1test",
65+
}
66+
`;
67+
68+
exports[`localIdentName option should prefixes leading hyphen + digit with underscore: module (evaluated) 1`] = `
69+
Array [
70+
Array [
71+
1,
72+
"._-1test {
73+
background: red;
74+
}
75+
76+
._-1_test {
77+
background: blue;
78+
}
79+
",
80+
"",
81+
],
82+
]
83+
`;
84+
85+
exports[`localIdentName option should prefixes leading hyphen + digit with underscore: warnings 1`] = `Array []`;
86+
87+
exports[`localIdentName option should prefixes two leading hyphens with underscore: errors 1`] = `Array []`;
88+
89+
exports[`localIdentName option should prefixes two leading hyphens with underscore: locals 1`] = `
90+
Object {
91+
"_test": "_--_test",
92+
"test": "_--test",
93+
}
94+
`;
95+
96+
exports[`localIdentName option should prefixes two leading hyphens with underscore: module (evaluated) 1`] = `
97+
Array [
98+
Array [
99+
1,
100+
"._--test {
101+
background: red;
102+
}
103+
104+
._--_test {
105+
background: blue;
106+
}
107+
",
108+
"",
109+
],
110+
]
111+
`;
112+
113+
exports[`localIdentName option should prefixes two leading hyphens with underscore: warnings 1`] = `Array []`;
114+
115+
exports[`localIdentName option should saves underscore prefix in exported class names: errors 1`] = `Array []`;
116+
117+
exports[`localIdentName option should saves underscore prefix in exported class names: locals 1`] = `
118+
Object {
119+
"_test": "_test",
120+
"test": "test",
121+
}
122+
`;
123+
124+
exports[`localIdentName option should saves underscore prefix in exported class names: module (evaluated) 1`] = `
125+
Array [
126+
Array [
127+
1,
128+
".test {
129+
background: red;
130+
}
131+
132+
._test {
133+
background: blue;
134+
}
135+
",
136+
"",
137+
],
138+
]
139+
`;
140+
141+
exports[`localIdentName option should saves underscore prefix in exported class names: warnings 1`] = `Array []`;
142+
143+
exports[`localIdentName option should use hash prefix: errors 1`] = `Array []`;
144+
145+
exports[`localIdentName option should use hash prefix: locals 1`] = `
146+
Object {
147+
"_test": "_test--d745495d407559ef605c9072243801fd",
148+
"test": "test--307c32aa793aaec9aecded85a9fdd448",
149+
}
150+
`;
151+
152+
exports[`localIdentName option should use hash prefix: module (evaluated) 1`] = `
153+
Array [
154+
Array [
155+
1,
156+
".test--307c32aa793aaec9aecded85a9fdd448 {
157+
background: red;
158+
}
159+
160+
._test--d745495d407559ef605c9072243801fd {
161+
background: blue;
162+
}
163+
",
164+
"",
165+
],
166+
]
167+
`;
168+
169+
exports[`localIdentName option should use hash prefix: warnings 1`] = `Array []`;
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:local(.test) {
2+
background: red;
3+
}
4+
5+
:local(._test) {
6+
background: blue;
7+
}

‎test/localIdentName-option.test.js

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
const path = require('path');
2+
3+
const { webpack, evaluated } = require('./helpers');
4+
5+
describe('localIdentName option', () => {
6+
it('should have hash', async () => {
7+
const config = {
8+
loader: {
9+
options: {
10+
localIdentName: '[name]--[local]--[hash:base64:5]',
11+
context: path.resolve(__dirname),
12+
},
13+
},
14+
};
15+
const testId = './modules/localIdentName.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, modules);
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 have path naming with context', async () => {
28+
const config = {
29+
loader: {
30+
options: {
31+
localIdentName: '[path]-[name]--[local]',
32+
context: path.resolve(__dirname),
33+
},
34+
},
35+
};
36+
const testId = './modules/localIdentName.css';
37+
const stats = await webpack(testId, config);
38+
const { modules } = stats.toJson();
39+
const module = modules.find((m) => m.id === testId);
40+
const evaluatedModule = evaluated(module.source, modules);
41+
42+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
43+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
44+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
45+
expect(stats.compilation.errors).toMatchSnapshot('errors');
46+
});
47+
48+
it('should use hash prefix', async () => {
49+
const config = {
50+
loader: {
51+
options: { localIdentName: '[local]--[hash]', hashPrefix: 'x' },
52+
},
53+
};
54+
const testId = './modules/localIdentName.css';
55+
const stats = await webpack(testId, config);
56+
const { modules } = stats.toJson();
57+
const module = modules.find((m) => m.id === testId);
58+
const evaluatedModule = evaluated(module.source, modules);
59+
60+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
61+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
62+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
63+
expect(stats.compilation.errors).toMatchSnapshot('errors');
64+
});
65+
66+
it('should prefixes leading hyphen + digit with underscore', async () => {
67+
const config = { loader: { options: { localIdentName: '-1[local]' } } };
68+
const testId = './modules/localIdentName.css';
69+
const stats = await webpack(testId, config);
70+
const { modules } = stats.toJson();
71+
const module = modules.find((m) => m.id === testId);
72+
const evaluatedModule = evaluated(module.source, modules);
73+
74+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
75+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
76+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
77+
expect(stats.compilation.errors).toMatchSnapshot('errors');
78+
});
79+
80+
it('should prefixes two leading hyphens with underscore', async () => {
81+
const config = { loader: { options: { localIdentName: '--[local]' } } };
82+
const testId = './modules/localIdentName.css';
83+
const stats = await webpack(testId, config);
84+
const { modules } = stats.toJson();
85+
const module = modules.find((m) => m.id === testId);
86+
const evaluatedModule = evaluated(module.source, modules);
87+
88+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
89+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
90+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
91+
expect(stats.compilation.errors).toMatchSnapshot('errors');
92+
});
93+
94+
it('should saves underscore prefix in exported class names', async () => {
95+
const config = { loader: { options: { localIdentName: '[local]' } } };
96+
const testId = './modules/localIdentName.css';
97+
const stats = await webpack(testId, config);
98+
const { modules } = stats.toJson();
99+
const module = modules.find((m) => m.id === testId);
100+
const evaluatedModule = evaluated(module.source, modules);
101+
102+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
103+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
104+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
105+
expect(stats.compilation.errors).toMatchSnapshot('errors');
106+
});
107+
});

‎test/modules-option.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ describe('modules option', () => {
2121
const module = modules.find((m) => m.id === testId);
2222
const evaluatedModule = evaluated(module.source, modules);
2323

24-
// console.log(module)
25-
2624
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
2725
expect(evaluatedModule.locals).toMatchSnapshot('locals');
2826
expect(stats.compilation.warnings).toMatchSnapshot('warnings');

0 commit comments

Comments
 (0)