|
| 1 | +import { readFileSync } from 'fs'; |
| 2 | +import { IICSSExports } from 'icss-utils'; |
| 3 | +import { join } from 'path'; |
| 4 | +import { createExports, getClasses } from '../cssSnapshots'; |
| 5 | + |
| 6 | +describe('utils / cssSnapshots', () => { |
| 7 | + let classesA: IICSSExports; |
| 8 | + let classesB: IICSSExports; |
| 9 | + |
| 10 | + beforeAll(() => { |
| 11 | + const testFileA = readFileSync( |
| 12 | + join(__dirname, 'fixtures/testA.module.css'), |
| 13 | + 'utf8', |
| 14 | + ); |
| 15 | + const testFileB = readFileSync( |
| 16 | + join(__dirname, 'fixtures/testB.module.scss'), |
| 17 | + 'utf8', |
| 18 | + ); |
| 19 | + classesA = getClasses(testFileA); |
| 20 | + classesB = getClasses(testFileB); |
| 21 | + }); |
| 22 | + |
| 23 | + describe('getClasses', () => { |
| 24 | + it('should return an object matching expected CSS classes', () => { |
| 25 | + expect(classesA).toEqual({ |
| 26 | + ClassB: 'file__ClassB---2bPVi', |
| 27 | + childA: 'file__childA---1hjQD', |
| 28 | + childB: 'file__childB---pq4Ks', |
| 29 | + 'class-c': 'file__class-c---DZ1TD', |
| 30 | + classA: 'file__classA---2xcnJ', |
| 31 | + nestedChild: 'file__nestedChild---2d15b', |
| 32 | + parent: 'file__parent---1ATMj', |
| 33 | + }); |
| 34 | + expect(classesB).toEqual({ |
| 35 | + 'local-class': 'file__local-class---3KegX', |
| 36 | + 'local-class-2': 'file__local-class-2---2h6qz', |
| 37 | + 'local-class-inside-global': 'file__local-class-inside-global---2xH_Y', |
| 38 | + 'local-class-inside-local': 'file__local-class-inside-local---QdL6b', |
| 39 | + }); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('createExports', () => { |
| 44 | + it('should create an exports file', () => { |
| 45 | + const exportsA = createExports(classesA); |
| 46 | + const exportsB = createExports(classesB); |
| 47 | + // tslint:disable max-line-length |
| 48 | + expect(exportsA).toMatchInlineSnapshot( |
| 49 | + `"export const classA: string;export const ClassB: string;export const class-c: string;export const parent: string;export const childA: string;export const childB: string;export const nestedChild: string;"`, |
| 50 | + ); |
| 51 | + expect(exportsB).toMatchInlineSnapshot( |
| 52 | + `"export const local-class-inside-global: string;export const local-class: string;export const local-class-2: string;export const local-class-inside-local: string;"`, |
| 53 | + ); |
| 54 | + // tslint:enable max-line-length |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments