1- import { existsSync } from "node:fs" ;
2- import { readdir } from "node:fs/promises" ;
31import { mainTestFn , test } from "@compas/cli" ;
4- import { pathJoin } from "@compas/stdlib" ;
5- import { testCompasCli , testDirectory } from "./utils.js" ;
2+ import { isNil } from "@compas/stdlib" ;
3+ import { TestCompas , testDirectory } from "./utils.js" ;
64
75mainTestFn ( import . meta) ;
86
@@ -14,60 +12,69 @@ test("compas/cli", (t) => {
1412 t . test ( "does not create a debug file without --debug" , async ( t ) => {
1513 const cwd = workingDirectory ( "no-debug" ) ;
1614
17- await testCompasCli ( {
18- args : [ "foo" ] ,
19- inputs : [ ] ,
20- waitForExit : true ,
21- cwd,
22- } ) ;
15+ const cli = new TestCompas (
16+ {
17+ cwd,
18+ } ,
19+ {
20+ args : [ "foo" ] ,
21+ } ,
22+ ) . launch ( ) ;
23+
24+ await cli . waitForExit ( ) ;
25+ await cli . recalculateOutputState ( ) ;
2326
24- t . equal ( existsSync ( pathJoin ( cwd , ".cache/compas" ) ) , false ) ;
27+ t . ok ( isNil ( cli . debugFilePath ) ) ;
2528 } ) ;
2629
2730 t . test ( "creates a debug file with --debug" , async ( t ) => {
2831 const cwd = workingDirectory ( "with-debug" ) ;
2932
30- await testCompasCli ( {
31- args : [ "foo" , "--debug" ] ,
32- inputs : [ ] ,
33- waitForExit : true ,
34- cwd,
35- } ) ;
33+ const cli = new TestCompas (
34+ {
35+ cwd,
36+ } ,
37+ {
38+ args : [ "foo" , "--debug" ] ,
39+ } ,
40+ ) . launch ( ) ;
3641
37- t . equal ( existsSync ( pathJoin ( cwd , ".cache/compas" ) ) , true ) ;
38- t . equal (
39- ( await readdir ( pathJoin ( cwd , ".cache/compas" ) , { } ) ) . some (
40- ( it ) => it . startsWith ( "debug-" ) && it . endsWith ( ".txt" ) ,
41- ) ,
42- true ,
43- ) ;
42+ await cli . waitForExit ( ) ;
43+ await cli . recalculateOutputState ( ) ;
44+
45+ t . ok ( cli . debugFilePath ) ;
4446 } ) ;
4547
4648 t . test ( "package.json is not available" , async ( t ) => {
4749 const cwd = workingDirectory ( "no-package-json" ) ;
4850
49- const { stdout } = await testCompasCli ( {
50- args : [ ] ,
51- inputs : [ ] ,
52- waitForExit : true ,
51+ const cli = new TestCompas ( {
5352 cwd,
54- } ) ;
53+ } ) . launch ( ) ;
54+
55+ await cli . waitForExit ( ) ;
5556
5657 t . ok (
57- stdout . includes ( "Please run 'npx compas@latest init' to install Compas." ) ,
58+ cli . stdout . includes (
59+ "Please run 'npx compas@latest init' to install Compas." ,
60+ ) ,
5861 ) ;
5962 } ) ;
6063
6164 t . test ( "unsupported command" , async ( t ) => {
6265 const cwd = workingDirectory ( "unknown-command" ) ;
6366
64- const { stdout } = await testCompasCli ( {
65- args : [ "foo" ] ,
66- inputs : [ ] ,
67- waitForExit : true ,
68- cwd,
69- } ) ;
67+ const cli = new TestCompas (
68+ {
69+ cwd,
70+ } ,
71+ {
72+ args : [ "foo" ] ,
73+ } ,
74+ ) . launch ( ) ;
75+
76+ await cli . waitForExit ( ) ;
7077
71- t . ok ( stdout . includes ( ` Unsupported command. Available commands:` ) ) ;
78+ t . ok ( cli . stdout . includes ( " Unsupported command. Available commands:" ) ) ;
7279 } ) ;
7380} ) ;
0 commit comments