diff --git a/src/__tests__/codegen.test.ts b/src/__tests__/codegen.test.ts index e7e481e..f5d7d36 100644 --- a/src/__tests__/codegen.test.ts +++ b/src/__tests__/codegen.test.ts @@ -3,8 +3,8 @@ import { codegen } from '../codegen'; import { createContext } from '../context'; const context = createContext({ - foo: { 100: { value: { base: 'whitesmoke', lg: 'palegreen' } } }, - bar: { 100: '{colors.green.200}' }, + foo: { 100: { value: '#fff' }, 200: { value: { base: '#000' } } }, + bar: { 100: 'red', 200: 'blue' }, }); const args: CodegenPrepareHookArgs = { @@ -26,7 +26,7 @@ describe('codegen', () => { expect(result[0].files[0]).toMatchInlineSnapshot(` { "code": " - const pluginCtMap = new Map(JSON.parse('[["foo.100",{"base":"whitesmoke","lg":"palegreen"}],["bar.100","{colors.green.200}"]]')); + const pluginCtMap = new Map(JSON.parse('[["foo.100","#fff"],["foo.200",{"base":"#000"}],["bar.100","red"],["bar.200","blue"]]')); export const ct = (path) => { if (!path) return 'panda-plugin-ct-path-empty'; @@ -41,7 +41,7 @@ describe('codegen', () => { expect(result[0].files[1]).toMatchInlineSnapshot(` { "code": " - export const ct: (alias: "foo.100" | "bar.100") => string;", + export const ct: (alias: "foo.100" | "foo.200" | "bar.100" | "bar.200") => string;", "file": "css.d.ts", } `); diff --git a/src/__tests__/ct.test.ts b/src/__tests__/ct.test.ts index 85fe33f..3885e56 100644 --- a/src/__tests__/ct.test.ts +++ b/src/__tests__/ct.test.ts @@ -1,29 +1,27 @@ import { ct, ctTemplate } from '../ct'; const tokens = { - foo: { a: { b: { c: { value: { base: '10px', lg: '20px' } } } } }, - bar: { baz: { 100: { value: {} }, 200: { value: {} } } }, - baz: { 100: 'hello', 200: { value: 'goodbye' } }, + foo: { 100: { value: '#fff' }, 200: { value: { base: '#000' } } }, + bar: { 100: 'red', 200: 'blue' }, }; describe('ct', () => { it('gets a string', () => { - expect(ct(tokens, 'baz.100')).toBe('hello'); + expect(ct(tokens, 'bar.100')).toBe('red'); }); it('gets a value object', () => { - expect(ct(tokens, 'foo.a.b.c')).toMatchInlineSnapshot( + expect(ct(tokens, 'foo.200')).toMatchInlineSnapshot( ` { - "base": "10px", - "lg": "20px", + "base": "#000", } `, ); }); it('gets a value string', () => { - expect(ct(tokens, 'baz.200')).toMatchInlineSnapshot(`"goodbye"`); + expect(ct(tokens, 'foo.100')).toMatchInlineSnapshot(`"#fff"`); }); it('gets an undefined token', () => { diff --git a/src/__tests__/parser.test.ts b/src/__tests__/parser.test.ts index ba67c22..cf148d4 100644 --- a/src/__tests__/parser.test.ts +++ b/src/__tests__/parser.test.ts @@ -2,8 +2,8 @@ import { parser } from '../parser'; import { createContext } from '../context'; const context = createContext({ - foo: { 100: { value: { base: 'whitesmoke', lg: 'palegreen' } } }, - bar: { 100: '{colors.green.200}' }, + foo: { 100: { value: '#fff' }, 200: { value: { base: '#000' } } }, + bar: { 100: 'red', 200: 'blue' }, }); describe('parser', () => { @@ -12,13 +12,13 @@ describe('parser', () => { { configure: () => {}, filePath: 'test.tsx', - content: `
`, + content: ``, }, context, ); expect(res).toMatchInlineSnapshot( - `""`, + `""`, ); }); @@ -34,17 +34,4 @@ describe('parser', () => { expect(res).toBeUndefined(); }); - - it('skips without a path', () => { - const res = parser( - { - configure: () => {}, - filePath: 'test.tsx', - content: ``, - }, - context, - ); - - expect(res).toMatchInlineSnapshot(`""`); - }); });