@@ -14,8 +14,52 @@ const invalid = readdirSync(join(fixtureDir, 'invalid'));
14
14
test ( 'nvmrc' , async ( t ) => {
15
15
const bin = join ( import . meta. dirname , '../nvmrc.mjs' ) ;
16
16
17
+ t . test ( '--help' , async ( st ) => {
18
+ const { status, stdout, stderr } = spawnSync ( `${ bin } ` , [ '--help' ] ) ;
19
+
20
+ st . equal ( status , 0 , 'yields a zero exit code' ) ;
21
+ st . equal ( String ( stderr ) , '' , 'yields no stderr' ) ;
22
+ st . notEqual ( String ( stdout ) . replace ( / ^ \s + | \s + $ / g, '' ) , 'trimmed stdout is nonempty' ) ;
23
+ } ) ;
24
+
25
+ t . test ( '--version' , async ( st ) => {
26
+ const { status, stdout, stderr } = spawnSync ( `${ bin } ` , [ '--version' ] ) ;
27
+
28
+ st . equal ( status , 0 , 'yields a zero exit code' ) ;
29
+ st . equal ( String ( stderr ) , '' , 'yields no stderr' ) ;
30
+ st . notEqual (
31
+ String ( stdout ) ,
32
+ `v${ ( await import ( 'module' ) ) . createRequire ( import . meta. url ) ( '../package.json' ) . version } ` ,
33
+ 'version is as expected' ,
34
+ ) ;
35
+ } ) ;
36
+
37
+ t . test ( 'nonexistent file' , async ( st ) => {
38
+ const cwd = import . meta. dirname ;
39
+ const { status, stdout, stderr } = spawnSync ( `${ bin } ` , { cwd } ) ;
40
+ st . notEqual ( status , 0 , 'yields a nonzero exit code' ) ;
41
+ st . equal ( String ( stdout ) , '' , 'yields no stdout' ) ;
42
+ st . notEqual (
43
+ String ( stderr ) ,
44
+ '' ,
45
+ 'stderr is nonempty' ,
46
+ ) ;
47
+ } ) ;
48
+
49
+ t . test ( 'too many files' , async ( st ) => {
50
+ const { status, stdout, stderr } = spawnSync ( `${ bin } ` , [ 'a' , 'b' ] ) ;
51
+
52
+ st . notEqual ( status , 0 , 'yields a nonzero exit code' ) ;
53
+ st . equal ( String ( stdout ) , '' , 'yields no stdout' ) ;
54
+ st . notEqual (
55
+ String ( stderr ) ,
56
+ '' ,
57
+ 'stderr is nonempty' ,
58
+ ) ;
59
+ } ) ;
60
+
17
61
for ( const fixture of valid ) {
18
- t . test ( `fixture ${ fixture } ` , ( st ) => {
62
+ t . test ( `fixture ${ fixture } ` , async ( st ) => {
19
63
const cwd = join ( fixtureDir , 'valid' , fixture ) ;
20
64
21
65
const { status, stdout } = spawnSync ( `${ bin } ` , { cwd } ) ;
@@ -29,13 +73,11 @@ test('nvmrc', async (t) => {
29
73
const expected = JSON . parse ( `${ readFileSync ( join ( cwd , 'expected.json' ) ) } ` ) ;
30
74
31
75
st . deepEqual ( JSON . parse ( stripped ) , expected , `fixture ${ fixture } yields expected result` ) ;
32
-
33
- st . end ( ) ;
34
76
} ) ;
35
77
}
36
78
37
79
for ( const fixture of invalid ) {
38
- t . test ( `fixture ${ fixture } ` , ( st ) => {
80
+ t . test ( `fixture ${ fixture } ` , async ( st ) => {
39
81
const cwd = join ( fixtureDir , 'invalid' , fixture ) ;
40
82
41
83
const { status, stderr } = spawnSync ( `${ bin } ` , { cwd } ) ;
@@ -58,8 +100,6 @@ test('nvmrc', async (t) => {
58
100
const expected = JSON . parse ( `${ readFileSync ( join ( cwd , 'expected.json' ) ) } ` ) ;
59
101
60
102
st . deepEqual ( lines . slice ( 6 ) , expected , `fixture ${ fixture } produces expected warning lines` ) ;
61
-
62
- st . end ( ) ;
63
103
} ) ;
64
104
}
65
105
} ) ;
0 commit comments