|
1 | 1 | import { existsSync, readFileSync } from 'node:fs' |
2 | 2 | import { join } from 'node:path' |
3 | 3 | import { afterEach, describe, expect, it } from 'vitest' |
4 | | -import { buildTokensSnapshot, runStudioGenerate, runStudioServe, viewFiles, viewerFiles } from '../src' |
| 4 | +import { |
| 5 | + buildSemanticMap, |
| 6 | + buildTokensSnapshot, |
| 7 | + runStudioGenerate, |
| 8 | + runStudioServe, |
| 9 | + viewFiles, |
| 10 | + viewerFiles, |
| 11 | +} from '../src' |
5 | 12 | import type { StudioToken } from '../src' |
6 | 13 | import { cleanupFixture, createFixture } from './helpers' |
7 | 14 |
|
@@ -119,3 +126,34 @@ describe('studio viewer', () => { |
119 | 126 | } |
120 | 127 | }) |
121 | 128 | }) |
| 129 | + |
| 130 | +describe('studio semantic tokens', () => { |
| 131 | + const spec = { tokens: { categories: {}, values: { 'colors.white': '#fff', 'colors.black': '#000' } } } as never |
| 132 | + const config = { |
| 133 | + theme: { semanticTokens: { colors: { bg: { value: { base: '{colors.white}', _dark: '{colors.black}' } } } } }, |
| 134 | + themes: { ocean: { semanticTokens: { colors: { bg: { value: { base: '#e0f2fe' } } } } } }, |
| 135 | + } |
| 136 | + |
| 137 | + it('resolves semantic conditions and named themes against token values', () => { |
| 138 | + expect(buildSemanticMap(spec, config)).toEqual({ |
| 139 | + 'colors.bg': { base: '#fff', _dark: '#000', 'ocean · base': '#e0f2fe' }, |
| 140 | + }) |
| 141 | + }) |
| 142 | + |
| 143 | + it('emits semantic tokens with conditions, base as the display value', () => { |
| 144 | + const semantic = buildSemanticMap(spec, config) |
| 145 | + const tokens = buildTokensSnapshot(spec, semantic) |
| 146 | + const bg = tokens.find((token) => token.path === 'colors.bg') |
| 147 | + expect(bg).toMatchObject({ category: 'colors', name: 'bg', value: '#fff' }) |
| 148 | + expect(bg?.conditions).toEqual({ base: '#fff', _dark: '#000', 'ocean · base': '#e0f2fe' }) |
| 149 | + }) |
| 150 | + |
| 151 | + it('keeps semantic paths out of the primitive list', () => { |
| 152 | + const specWithSemantic = { |
| 153 | + tokens: { categories: { colors: { values: ['bg'] } }, values: { 'colors.bg': 'var(--colors-white)' } }, |
| 154 | + } as never |
| 155 | + const tokens = buildTokensSnapshot(specWithSemantic, { 'colors.bg': { base: '#fff' } }) |
| 156 | + expect(tokens.filter((token) => token.path === 'colors.bg')).toHaveLength(1) |
| 157 | + expect(tokens[0].value).toBe('#fff') |
| 158 | + }) |
| 159 | +}) |
0 commit comments