|
| 1 | +import { describe, it, expect } from 'vitest' |
| 2 | +import StyleDictionary from 'style-dictionary' |
| 3 | +import { makeSdTailwindConfig } from '../' |
| 4 | + |
| 5 | +const expectedOutputForAllType = `/** @type {import('tailwindcss').Config} */ |
| 6 | +module.exports = { |
| 7 | + mode: "jit", |
| 8 | + content: ["./src/**/*.{ts,tsx}"], |
| 9 | + darkMode: "class", |
| 10 | + theme: { |
| 11 | + extend: { |
| 12 | + colors: { |
| 13 | + red: { |
| 14 | + 500: "#FF0000" |
| 15 | + } |
| 16 | + } |
| 17 | + }, |
| 18 | + }, |
| 19 | +}` |
| 20 | + |
| 21 | +const expectedOutputForColors = `module.exports = { |
| 22 | + red: { |
| 23 | + 500: "#FF0000" |
| 24 | + } |
| 25 | +}` |
| 26 | + |
| 27 | +describe('Should work with StyleDictionary properly', () => { |
| 28 | + it('build all tokens', async () => { |
| 29 | + const styleDictionaryTailwind = new StyleDictionary( |
| 30 | + makeSdTailwindConfig({ type: 'all', source: ['src/tests/tokens.json'] }) |
| 31 | + ) |
| 32 | + await styleDictionaryTailwind.hasInitialized |
| 33 | + const formatted = await styleDictionaryTailwind.formatAllPlatforms() |
| 34 | + expect(formatted['tailwind'][0]['output']).toEqual(expectedOutputForAllType) |
| 35 | + }) |
| 36 | + |
| 37 | + it('build colors', async () => { |
| 38 | + const types = ['colors'] |
| 39 | + |
| 40 | + for (const type of types) { |
| 41 | + const tailwindConfig = makeSdTailwindConfig({ |
| 42 | + type, |
| 43 | + source: ['src/tests/tokens.json'] |
| 44 | + }) |
| 45 | + |
| 46 | + const styleDictionaryTailwind = new StyleDictionary(tailwindConfig) |
| 47 | + |
| 48 | + await styleDictionaryTailwind.hasInitialized |
| 49 | + const formatted = await styleDictionaryTailwind.formatAllPlatforms() |
| 50 | + |
| 51 | + expect(formatted['tailwind/colors'][0]['output']).toEqual( |
| 52 | + expectedOutputForColors |
| 53 | + ) |
| 54 | + } |
| 55 | + }) |
| 56 | +}) |
0 commit comments