|
1 | 1 | const compiler = require('./compiler.js'); |
2 | 2 |
|
3 | 3 | const style = '<style>.red { color: red; }</style>'; |
4 | | -const source = style + '\n<span class="$style.red">Red</span>'; |
5 | | -const sourceShorthand = style + '\n<span class="$.red">Red</span>'; |
| 4 | +const source = `${style}\n<span class="$style.red">Red</span>`; |
| 5 | +const sourceShorthand = `${style}\n<span class="$.red">Red</span>`; |
6 | 6 |
|
| 7 | +describe('Generate CSS Modules from HTML attributes, Replace CSS className', () => { |
| 8 | + const expectedOutput = '<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>'; |
| 9 | + test('Use default $style.', async () => { |
| 10 | + const output = await compiler({ |
| 11 | + source, |
| 12 | + }, { |
| 13 | + localIdentName: '[local]-123456', |
| 14 | + }); |
7 | 15 |
|
8 | | -test('Generate CSS Modules from HTML attributes, Replace CSS className', async () => { |
9 | | - const output = await compiler({ |
10 | | - source, |
11 | | - }, { |
12 | | - localIdentName: '[local]-123456', |
| 16 | + expect(output).toBe(expectedOutput); |
13 | 17 | }); |
| 18 | + test('Use shorthand $.', async () => { |
| 19 | + const output = await compiler({ |
| 20 | + source: sourceShorthand, |
| 21 | + }, { |
| 22 | + localIdentName: '[local]-123456', |
| 23 | + }); |
14 | 24 |
|
15 | | - expect(output).toBe('<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>'); |
16 | | -}); |
17 | | -test('[Shorthand] Generate CSS Modules from HTML attributes, Replace CSS className', async () => { |
18 | | - const output = await compiler({ |
19 | | - source: sourceShorthand, |
20 | | - }, { |
21 | | - localIdentName: '[local]-123456', |
| 25 | + expect(output).toBe(expectedOutput); |
22 | 26 | }); |
23 | | - |
24 | | - expect(output).toBe('<style>:global(.red-123456) { color: red; }</style>\n<span class="red-123456">Red</span>'); |
25 | 27 | }); |
26 | 28 |
|
27 | | -test('Avoid generated class to start with a non character', async () => { |
28 | | - const output = await compiler({ |
29 | | - source, |
30 | | - }, { |
31 | | - localIdentName: '1[local]', |
| 29 | +describe('Avoid generated class to start with a non character', () => { |
| 30 | + const expectedOutput = '<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>'; |
| 31 | + test('Use default $style.', async () => { |
| 32 | + const output = await compiler({ |
| 33 | + source, |
| 34 | + }, { |
| 35 | + localIdentName: '1[local]', |
| 36 | + }); |
| 37 | + expect(output).toBe(expectedOutput); |
32 | 38 | }); |
33 | | - expect(output).toBe('<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>'); |
34 | | -}); |
35 | | -test('[Shorthand] Avoid generated class to start with a non character', async () => { |
36 | | - const output = await compiler({ |
37 | | - source: sourceShorthand, |
38 | | - }, { |
39 | | - localIdentName: '1[local]', |
| 39 | + test('Use shorthand $.', async () => { |
| 40 | + const output = await compiler({ |
| 41 | + source: sourceShorthand, |
| 42 | + }, { |
| 43 | + localIdentName: '1[local]', |
| 44 | + }); |
| 45 | + expect(output).toBe(expectedOutput); |
40 | 46 | }); |
41 | | - expect(output).toBe('<style>:global(._1red) { color: red; }</style>\n<span class="_1red">Red</span>'); |
42 | 47 | }); |
43 | 48 |
|
44 | | -test('Avoid generated class to end with a hyphen', async () => { |
45 | | - const output = await compiler({ |
46 | | - source, |
47 | | - }, { |
48 | | - localIdentName: '[local]-', |
| 49 | +describe('Avoid generated class to end with a hyphen', () => { |
| 50 | + const expectedOutput = '<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>'; |
| 51 | + test('Use default $style.', async () => { |
| 52 | + const output = await compiler({ |
| 53 | + source, |
| 54 | + }, { |
| 55 | + localIdentName: '[local]-', |
| 56 | + }); |
| 57 | + expect(output).toBe(expectedOutput); |
49 | 58 | }); |
50 | | - expect(output).toBe('<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>'); |
51 | | -}); |
52 | | -test('[Shorthand] Avoid generated class to end with a hyphen', async () => { |
53 | | - const output = await compiler({ |
54 | | - source: sourceShorthand, |
55 | | - }, { |
56 | | - localIdentName: '[local]-', |
| 59 | + test('Use shorthand $.', async () => { |
| 60 | + const output = await compiler({ |
| 61 | + source: sourceShorthand, |
| 62 | + }, { |
| 63 | + localIdentName: '[local]-', |
| 64 | + }); |
| 65 | + expect(output).toBe(expectedOutput); |
57 | 66 | }); |
58 | | - expect(output).toBe('<style>:global(.red) { color: red; }</style>\n<span class="red">Red</span>'); |
59 | 67 | }); |
0 commit comments