1
- import { existsSync } from "node:fs" ;
2
- import { readdir } from "node:fs/promises" ;
3
1
import { 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" ;
6
4
7
5
mainTestFn ( import . meta) ;
8
6
@@ -14,60 +12,69 @@ test("compas/cli", (t) => {
14
12
t . test ( "does not create a debug file without --debug" , async ( t ) => {
15
13
const cwd = workingDirectory ( "no-debug" ) ;
16
14
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 ( ) ;
23
26
24
- t . equal ( existsSync ( pathJoin ( cwd , ".cache/compas" ) ) , false ) ;
27
+ t . ok ( isNil ( cli . debugFilePath ) ) ;
25
28
} ) ;
26
29
27
30
t . test ( "creates a debug file with --debug" , async ( t ) => {
28
31
const cwd = workingDirectory ( "with-debug" ) ;
29
32
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 ( ) ;
36
41
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 ) ;
44
46
} ) ;
45
47
46
48
t . test ( "package.json is not available" , async ( t ) => {
47
49
const cwd = workingDirectory ( "no-package-json" ) ;
48
50
49
- const { stdout } = await testCompasCli ( {
50
- args : [ ] ,
51
- inputs : [ ] ,
52
- waitForExit : true ,
51
+ const cli = new TestCompas ( {
53
52
cwd,
54
- } ) ;
53
+ } ) . launch ( ) ;
54
+
55
+ await cli . waitForExit ( ) ;
55
56
56
57
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
+ ) ,
58
61
) ;
59
62
} ) ;
60
63
61
64
t . test ( "unsupported command" , async ( t ) => {
62
65
const cwd = workingDirectory ( "unknown-command" ) ;
63
66
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 ( ) ;
70
77
71
- t . ok ( stdout . includes ( ` Unsupported command. Available commands:` ) ) ;
78
+ t . ok ( cli . stdout . includes ( " Unsupported command. Available commands:" ) ) ;
72
79
} ) ;
73
80
} ) ;
0 commit comments