1- import { execSync } from 'node:child_process' ;
21import fs from 'node:fs' ;
32import path from 'node:path' ;
43import { describe , expect , it } from 'vitest' ;
5- import { createProject } from './utils' ;
4+ import { createProject , runCli } from './utils' ;
65
76const model = `
87model User {
@@ -13,33 +12,33 @@ model User {
1312describe ( 'CLI generate command test' , ( ) => {
1413 it ( 'should generate a TypeScript schema' , ( ) => {
1514 const workDir = createProject ( model ) ;
16- execSync ( 'node node_modules/@zenstackhq/cli/bin/cli generate') ;
15+ runCli ( ' generate', workDir ) ;
1716 expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
1817 expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.prisma' ) ) ) . toBe ( false ) ;
1918 } ) ;
2019
2120 it ( 'should respect custom output directory' , ( ) => {
2221 const workDir = createProject ( model ) ;
23- execSync ( 'node node_modules/@zenstackhq/cli/bin/cli generate --output ./zen') ;
22+ runCli ( ' generate --output ./zen', workDir ) ;
2423 expect ( fs . existsSync ( path . join ( workDir , 'zen/schema.ts' ) ) ) . toBe ( true ) ;
2524 } ) ;
2625
2726 it ( 'should respect custom schema location' , ( ) => {
2827 const workDir = createProject ( model ) ;
2928 fs . renameSync ( path . join ( workDir , 'zenstack/schema.zmodel' ) , path . join ( workDir , 'zenstack/foo.zmodel' ) ) ;
30- execSync ( 'node node_modules/@zenstackhq/cli/bin/cli generate --schema ./zenstack/foo.zmodel') ;
29+ runCli ( ' generate --schema ./zenstack/foo.zmodel', workDir ) ;
3130 expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.ts' ) ) ) . toBe ( true ) ;
3231 } ) ;
3332
3433 it ( 'should respect save prisma schema option' , ( ) => {
3534 const workDir = createProject ( model ) ;
36- execSync ( 'node node_modules/@zenstackhq/cli/bin/cli generate --save-prisma-schema') ;
35+ runCli ( ' generate --save-prisma-schema', workDir ) ;
3736 expect ( fs . existsSync ( path . join ( workDir , 'zenstack/schema.prisma' ) ) ) . toBe ( true ) ;
3837 } ) ;
3938
4039 it ( 'should respect save prisma schema custom path option' , ( ) => {
4140 const workDir = createProject ( model ) ;
42- execSync ( 'node node_modules/@zenstackhq/cli/bin/cli generate --save-prisma-schema "../prisma/schema.prisma"') ;
41+ runCli ( ' generate --save-prisma-schema "../prisma/schema.prisma"', workDir ) ;
4342 expect ( fs . existsSync ( path . join ( workDir , 'prisma/schema.prisma' ) ) ) . toBe ( true ) ;
4443 } ) ;
4544} ) ;
0 commit comments