1- import { test as base , expect } from '@playwright/test' ;
2- import { resetZeroUiState } from './resetProjectState' ;
1+ import { test , expect } from '@playwright/test' ;
32import path from 'node:path' ;
4- import { fileURLToPath } from 'node:url' ;
5- import { spawnSync } from 'node:child_process' ;
63import { existsSync , readFileSync } from 'node:fs' ;
4+ import { fileURLToPath } from 'node:url' ;
75
8- const test = base . extend ( { } ) ;
96const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
10- console . log ( '__dirname: ' , __dirname ) ;
11- const projectDir = path . resolve ( __dirname , '../fixtures/next' ) ;
12-
13- const zeroUiBin = path . resolve ( __dirname , '../../src/cli/init.cjs' ) ; // library CLI
14-
15-
16- test . beforeAll ( ( ) => resetZeroUiState ( projectDir ) ) ;
17-
18-
19- test . describe ( 'Zero-UI Next.js CLI' , ( ) => {
20-
21- test ( 'init CLI scaffolds project' , ( ) => {
22- // run zero-ui init
23- spawnSync ( 'node' , [ zeroUiBin ] , { cwd : projectDir , stdio : 'inherit' } ) ;
24-
25- const attrsPath = path . join ( projectDir , '.zero-ui/attributes.js' ) ;
26- const tsconfPath = path . join ( projectDir , 'tsconfig.json' ) ;
27-
28- // assert attributes.js
29- expect ( existsSync ( attrsPath ) , '.zero-ui/attributes.js should exist' ) . toBeTruthy ( ) ;
30- const attrsContent = readFileSync ( attrsPath , 'utf8' ) ;
31- expect ( attrsContent ) . toContain ( 'export const bodyAttributes' ) ;
32-
33- // assert tsconfig.json
34- const tsconf = JSON . parse ( readFileSync ( tsconfPath , 'utf8' ) ) ;
35- expect ( tsconf . compilerOptions . paths [ '@zero-ui/attributes' ] ) . toEqual (
36- [ './.zero-ui/attributes.js' ]
37- ) ;
38- } ) ;
397
8+ const projectDir = path . resolve ( __dirname , '../fixtures/next' ) ;
409
41- } ) ;
10+ test ( 'Next CLI scaffolds .zero-ui + tsconfig + postcss' , async ( ) => {
11+ // CLI setup is handled by global setup, just verify the results
12+ const attrs = path . join ( projectDir , '.zero-ui/attributes.js' ) ;
13+ const tsc = path . join ( projectDir , 'tsconfig.json' ) ;
14+ const post = path . join ( projectDir , 'postcss.config.mjs' ) ;
15+
16+ await expect . poll ( ( ) => existsSync ( attrs ) ) . toBeTruthy ( ) ;
17+ await expect . poll ( ( ) => readFileSync ( attrs , 'utf8' ) )
18+ . toContain ( 'export const bodyAttributes' ) ;
19+
20+ await expect . poll ( ( ) => {
21+ if ( ! existsSync ( tsc ) ) return false ;
22+ const conf = JSON . parse ( readFileSync ( tsc , 'utf8' ) ) ;
23+ return conf . compilerOptions ?. paths ?. [ '@zero-ui/attributes' ] ?. [ 0 ] === './.zero-ui/attributes.js' ;
24+ } ) . toBeTruthy ( ) ;
25+
26+ await expect . poll ( ( ) => {
27+ if ( ! existsSync ( post ) ) return false ;
28+ return readFileSync ( post , 'utf8' ) . includes ( '@austinserb/react-zero-ui/postcss' ) ;
29+ } ) . toBeTruthy ( ) ;
30+ } ) ;
0 commit comments