Skip to content

Commit fec8bb5

Browse files
author
Michael Vurchio
committed
Put tests on correct file
1 parent 01edf7b commit fec8bb5

File tree

2 files changed

+55
-55
lines changed

2 files changed

+55
-55
lines changed

test/getlocalidentname.test.js

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,16 @@
11
const compiler = require('./compiler.js');
22

33
const source = '<style>.red { color: red; }</style>\n<span class="$style.red">Red</span>';
4-
const sourceShorthand = '<style>.red { color: red; }</style>\n<span class="$.red">Red</span>';
54

6-
test('Generate CSS Modules from HTML attributes, Replace CSS className', async () => {
5+
test('Customize generated classname from getLocalIdentName', async () => {
76
const output = await compiler({
87
source,
98
}, {
10-
localIdentName: '[local]-123456',
9+
localIdentName: '[local]-123456MC',
10+
getLocalIdentName: (context, { interpolatedName }) => {
11+
return interpolatedName.toLowerCase();
12+
}
1113
});
1214

13-
expect(output).toBe('<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>');
14-
});
15-
test('[Shorthand] Generate CSS Modules from HTML attributes, Replace CSS className', async () => {
16-
const output = await compiler({
17-
source: sourceShorthand,
18-
}, {
19-
localIdentName: '[local]-123456',
20-
});
21-
22-
expect(output).toBe('<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>');
23-
});
24-
25-
test('Avoid generated class to start with a non character', async () => {
26-
const output = await compiler({
27-
source,
28-
}, {
29-
localIdentName: '1[local]',
30-
});
31-
expect(output).toBe('<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>');
32-
});
33-
test('[Shorthand] Avoid generated class to start with a non character', async () => {
34-
const output = await compiler({
35-
source: sourceShorthand,
36-
}, {
37-
localIdentName: '1[local]',
38-
});
39-
expect(output).toBe('<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>');
40-
});
41-
42-
test('Avoid generated class to end with a hyphen', async () => {
43-
const output = await compiler({
44-
source,
45-
}, {
46-
localIdentName: '[local]-',
47-
});
48-
expect(output).toBe('<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>');
49-
});
50-
test('[Shorthand] Avoid generated class to end with a hyphen', async () => {
51-
const output = await compiler({
52-
source: sourceShorthand,
53-
}, {
54-
localIdentName: '[local]-',
55-
});
56-
expect(output).toBe('<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>');
57-
});
15+
expect(output).toBe('<style>:global(.red-123456mc) { color: red; }</style>\n<span class="red-123456mc">Red</span>');
16+
});

test/replace.test.js

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,57 @@
11
const compiler = require('./compiler.js');
22

33
const source = '<style>.red { color: red; }</style>\n<span class="$style.red">Red</span>';
4+
const sourceShorthand = '<style>.red { color: red; }</style>\n<span class="$.red">Red</span>';
45

5-
test('Customize generated classname from getLocalIdentName', async () => {
6+
test('Generate CSS Modules from HTML attributes, Replace CSS className', async () => {
67
const output = await compiler({
78
source,
89
}, {
9-
localIdentName: '[local]-123456MC',
10-
getLocalIdentName: (context, localIdentName) => {
11-
return localIdentName.interpolated.toLowerCase();
12-
}
10+
localIdentName: '[local]-123456',
1311
});
1412

15-
expect(output).toBe('<style>:global(.red-123456mc) { color: red; }</style>\n<span class="red-123456mc">Red</span>');
16-
});
13+
expect(output).toBe('<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>');
14+
});
15+
test('[Shorthand] Generate CSS Modules from HTML attributes, Replace CSS className', async () => {
16+
const output = await compiler({
17+
source: sourceShorthand,
18+
}, {
19+
localIdentName: '[local]-123456',
20+
});
21+
22+
expect(output).toBe('<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>');
23+
});
24+
25+
test('Avoid generated class to start with a non character', async () => {
26+
const output = await compiler({
27+
source,
28+
}, {
29+
localIdentName: '1[local]',
30+
});
31+
expect(output).toBe('<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>');
32+
});
33+
test('[Shorthand] Avoid generated class to start with a non character', async () => {
34+
const output = await compiler({
35+
source: sourceShorthand,
36+
}, {
37+
localIdentName: '1[local]',
38+
});
39+
expect(output).toBe('<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>');
40+
});
41+
42+
test('Avoid generated class to end with a hyphen', async () => {
43+
const output = await compiler({
44+
source,
45+
}, {
46+
localIdentName: '[local]-',
47+
});
48+
expect(output).toBe('<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>');
49+
});
50+
test('[Shorthand] Avoid generated class to end with a hyphen', async () => {
51+
const output = await compiler({
52+
source: sourceShorthand,
53+
}, {
54+
localIdentName: '[local]-',
55+
});
56+
expect(output).toBe('<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>');
57+
});

0 commit comments

Comments
 (0)