1- import type { CodegenPrepareHookArgs } from '@pandacss/types' ;
21import { codegen } from '../codegen' ;
32import { createContext } from '../context' ;
43
@@ -7,43 +6,76 @@ const context = createContext({
76 bar : { 100 : 'red' , 200 : 'blue' } ,
87} ) ;
98
10- const args : CodegenPrepareHookArgs = {
11- artifacts : [
12- {
13- id : 'css-fn' ,
14- files : [
15- { file : 'css.mjs' , code : '' } ,
16- { file : 'css.d.ts' , code : '' } ,
17- ] ,
18- } ,
19- ] ,
20- changed : [ ] ,
21- } ;
22-
239describe ( 'codegen' , ( ) => {
2410 it ( 'generates ct runtime code' , ( ) => {
25- const result = codegen ( args , context ) as any [ ] ;
26- expect ( result [ 0 ] . files [ 0 ] ) . toMatchInlineSnapshot ( `
11+ const result = codegen (
2712 {
28- "code": "
29-
30- /* panda-plugin-ct codegen */
13+ artifacts : [
14+ {
15+ id : 'css-fn' ,
16+ files : [ ] ,
17+ } ,
18+ {
19+ id : 'css-index' ,
20+ files : [
21+ { file : 'index.mjs' , code : '// ...panda code' } ,
22+ { file : 'index.d.ts' , code : '// ...panda code' } ,
23+ ] ,
24+ } ,
25+ ] ,
26+ changed : [ ] ,
27+ } ,
28+ context ,
29+ ) ;
30+ expect ( result ) . toMatchInlineSnapshot ( `
31+ [
32+ {
33+ "files": [
34+ {
35+ "code": "
3136 const pluginCtMap = new Map([["foo.100","#fff"],["foo.200",{"base":"#000"}],["bar.100","red"],["bar.200","blue"]]);
3237
3338 export const ct = (path) => {
3439 if (!pluginCtMap.has(path)) return 'panda-plugin-ct_alias-not-found';
3540 return pluginCtMap.get(path);
3641 };",
37- "file": "css.mjs",
38- }
42+ "file": "ct.mjs",
43+ },
44+ {
45+ "code": "export const ct: (alias: "foo.100" | "foo.200" | "bar.100" | "bar.200") => string;",
46+ "file": "ct.d.ts",
47+ },
48+ ],
49+ "id": "css-fn",
50+ },
51+ {
52+ "files": [
53+ {
54+ "code": "// ...panda code
55+ export * from './ct.mjs';",
56+ "file": "index.mjs",
57+ },
58+ {
59+ "code": "// ...panda code
60+ export * from './ct';",
61+ "file": "index.d.ts",
62+ },
63+ ],
64+ "id": "css-index",
65+ },
66+ ]
3967 ` ) ;
68+ } ) ;
4069
41- expect ( result [ 0 ] . files [ 1 ] ) . toMatchInlineSnapshot ( `
70+ it ( 'skips if artifacts dont exist' , ( ) => {
71+ const result = codegen (
4272 {
43- "code": "
44- export const ct: (alias: "foo.100" | "foo.200" | "bar.100" | "bar.200") => string;",
45- "file": "css.d.ts",
46- }
47- ` ) ;
73+ artifacts : [ ] ,
74+ changed : [ ] ,
75+ } ,
76+ context ,
77+ ) ;
78+
79+ expect ( result ) . toEqual ( [ ] ) ;
4880 } ) ;
4981} ) ;
0 commit comments