|
1 | | -import { setFileScope, endFileScope } from './fileScope'; |
| 1 | +import { removeAdapter, setAdapter } from './adapter'; |
| 2 | +import { endFileScope, setFileScope } from './fileScope'; |
2 | 3 | import { generateIdentifier } from './identifier'; |
3 | 4 |
|
4 | 5 | describe('identifier', () => { |
@@ -57,4 +58,43 @@ describe('identifier', () => { |
57 | 58 | ).toMatchInlineSnapshot(`"_18bazsm6"`); |
58 | 59 | }); |
59 | 60 | }); |
| 61 | + |
| 62 | + describe('with custom callback', () => { |
| 63 | + beforeAll(() => { |
| 64 | + setFileScope('path/to/file.css.ts', 'packagetest'); |
| 65 | + setAdapter({ |
| 66 | + appendCss: () => {}, |
| 67 | + registerClassName: () => {}, |
| 68 | + onEndFileScope: () => {}, |
| 69 | + registerComposition: () => {}, |
| 70 | + markCompositionUsed: () => {}, |
| 71 | + getIdentOption: |
| 72 | + () => |
| 73 | + ({ hash, debugId, filePath, packageName }) => { |
| 74 | + const filenameWithExtension = filePath?.split('/').pop(); |
| 75 | + const filenameWithoutExtension = |
| 76 | + filenameWithExtension?.split('.')?.[0]; |
| 77 | + |
| 78 | + return `abc_${debugId}_${hash}_${packageName}_${filenameWithoutExtension}`; |
| 79 | + }, |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + afterAll(() => { |
| 84 | + removeAdapter(); |
| 85 | + endFileScope(); |
| 86 | + }); |
| 87 | + |
| 88 | + it('defers to a custom callback', () => { |
| 89 | + expect(generateIdentifier(`a`)).toMatchInlineSnapshot( |
| 90 | + `"abc_a_s0xkdr0_packagetest_file"`, |
| 91 | + ); |
| 92 | + }); |
| 93 | + |
| 94 | + it('rejects invalid identifiers', () => { |
| 95 | + // getIdentOption() does not remove spaces from the debug info so the |
| 96 | + // resulting identifier should be invalid here. |
| 97 | + expect(() => generateIdentifier(`a b`)).toThrow(); |
| 98 | + }); |
| 99 | + }); |
60 | 100 | }); |
0 commit comments