Skip to content

Commit c253c4f

Browse files
committed
feat: add integration test for testing package with style-dictionary
1 parent c7fc031 commit c253c4f

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/tests/integration.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
})

src/tests/tokens.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"colors": {
3+
"red": {
4+
"500": {
5+
"$value": "#FF0000"
6+
}
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)