@@ -12,22 +12,17 @@ var cmdShim = require('../')
12
12
test ( 'no shebang' , function ( t ) {
13
13
var from = path . resolve ( fixtures , 'from.exe' )
14
14
var to = path . resolve ( fixtures , 'exe.shim' )
15
- cmdShim ( from , to , function ( er ) {
16
- if ( er )
17
- throw er
15
+ return cmdShim ( from , to ) . then ( ( ) => {
18
16
matchSnapshot ( t , fs . readFileSync ( to , 'utf8' ) , 'shell' )
19
17
matchSnapshot ( t , fs . readFileSync ( to + '.cmd' , 'utf8' ) , 'cmd' )
20
18
matchSnapshot ( t , fs . readFileSync ( to + '.ps1' , 'utf8' ) , 'ps1' )
21
- t . end ( )
22
19
} )
23
20
} )
24
21
25
22
test ( 'if exists (it does exist)' , function ( t ) {
26
23
var from = path . resolve ( fixtures , 'from.exe' )
27
24
var to = path . resolve ( fixtures , 'exe.shim' )
28
- cmdShim . ifExists ( from , to , function ( er ) {
29
- if ( er )
30
- throw er
25
+ return cmdShim . ifExists ( from , to ) . then ( ( ) => {
31
26
matchSnapshot ( t , fs . readFileSync ( to , 'utf8' ) , 'shell' )
32
27
matchSnapshot ( t , fs . readFileSync ( to + '.cmd' , 'utf8' ) , 'cmd' )
33
28
matchSnapshot ( t , fs . readFileSync ( to + '.ps1' , 'utf8' ) , 'ps1' )
@@ -38,9 +33,7 @@ test('if exists (it does exist)', function (t) {
38
33
test ( 'if exists (it does not exist)' , function ( t ) {
39
34
var from = path . resolve ( fixtures , 'argle bargle we like to sparkle' )
40
35
var to = path . resolve ( fixtures , 'argle-bargle-shim' )
41
- cmdShim . ifExists ( from , to , function ( er ) {
42
- if ( er )
43
- throw er
36
+ return cmdShim . ifExists ( from , to ) . then ( ( ) => {
44
37
t . throws ( ( ) => fs . statSync ( to ) )
45
38
t . throws ( ( ) => fs . statSync ( to + '.cmd' ) )
46
39
t . throws ( ( ) => fs . statSync ( to + '.ps1' ) )
@@ -51,112 +44,81 @@ test('if exists (it does not exist)', function (t) {
51
44
test ( 'fails if from doesnt exist' , t => {
52
45
var from = path . resolve ( fixtures , 'argle bargle we like to sparkle' )
53
46
var to = path . resolve ( fixtures , 'argle-bargle-shim' )
54
- cmdShim ( from , to , function ( er ) {
55
- t . match ( er , { code : 'ENOENT' } )
56
- t . end ( )
57
- } )
47
+ return t . rejects ( cmdShim ( from , to ) , { code : 'ENOENT' } )
58
48
} )
59
49
60
50
test ( 'fails if mkdir fails' , t => {
61
51
var from = path . resolve ( fixtures , 'from.env' )
62
52
var to = path . resolve ( fixtures , 'from.env/a/b/c' )
63
- cmdShim ( from , to , er => {
64
- t . match ( er , { code : / ^ ( E N O T D I R | E E X I S T ) $ / } )
65
- t . end ( )
66
- } )
53
+ return t . rejects ( cmdShim ( from , to ) , { code : / ^ ( E N O T D I R | E E X I S T ) $ / } )
67
54
} )
68
55
69
56
test ( 'fails if to is a dir' , t => {
70
57
var from = path . resolve ( fixtures , 'from.env' )
71
58
var to = path . resolve ( fixtures )
72
- cmdShim ( from , to , er => {
73
- t . match ( er , { code : 'EISDIR' } )
59
+ t . teardown ( ( ) => {
74
60
rimraf . sync ( to + '.cmd' )
75
61
rimraf . sync ( to + '.ps1' )
76
- t . end ( )
77
62
} )
63
+ return t . rejects ( cmdShim ( from , to ) , { code : 'EISDIR' } )
78
64
} )
79
65
80
66
test ( 'just proceed if reading fails' , t => {
81
67
var from = fixtures
82
68
var to = path . resolve ( fixtures , 'env.shim' )
83
- cmdShim ( from , to , er => {
84
- if ( er )
85
- throw er
86
-
69
+ return cmdShim ( from , to ) . then ( ( ) => {
87
70
matchSnapshot ( t , fs . readFileSync ( to , 'utf8' ) , 'shell' )
88
71
matchSnapshot ( t , fs . readFileSync ( to + '.cmd' , 'utf8' ) , 'cmd' )
89
72
matchSnapshot ( t , fs . readFileSync ( to + '.ps1' , 'utf8' ) , 'ps1' )
90
- t . end ( )
91
73
} )
92
74
} )
93
75
94
76
test ( 'env shebang' , function ( t ) {
95
77
var from = path . resolve ( fixtures , 'from.env' )
96
78
var to = path . resolve ( fixtures , 'env.shim' )
97
- cmdShim ( from , to , function ( er ) {
98
- if ( er )
99
- throw er
100
-
79
+ return cmdShim ( from , to ) . then ( ( ) => {
101
80
matchSnapshot ( t , fs . readFileSync ( to , 'utf8' ) , 'shell' )
102
81
matchSnapshot ( t , fs . readFileSync ( to + '.cmd' , 'utf8' ) , 'cmd' )
103
82
matchSnapshot ( t , fs . readFileSync ( to + '.ps1' , 'utf8' ) , 'ps1' )
104
- t . end ( )
105
83
} )
106
84
} )
107
85
108
86
test ( 'env shebang with args' , function ( t ) {
109
87
var from = path . resolve ( fixtures , 'from.env.args' )
110
88
var to = path . resolve ( fixtures , 'env.args.shim' )
111
- cmdShim ( from , to , function ( er ) {
112
- if ( er )
113
- throw er
114
-
89
+ return cmdShim ( from , to ) . then ( ( ) => {
115
90
matchSnapshot ( t , fs . readFileSync ( to , 'utf8' ) , 'shell' )
116
91
matchSnapshot ( t , fs . readFileSync ( to + '.cmd' , 'utf8' ) , 'cmd' )
117
92
matchSnapshot ( t , fs . readFileSync ( to + '.ps1' , 'utf8' ) , 'ps1' )
118
- t . end ( )
119
93
} )
120
94
} )
121
95
122
96
test ( 'env shebang with variables' , function ( t ) {
123
97
var from = path . resolve ( fixtures , 'from.env.variables' )
124
98
var to = path . resolve ( fixtures , 'env.variables.shim' )
125
- cmdShim ( from , to , function ( er ) {
126
- if ( er )
127
- throw er
128
-
99
+ return cmdShim ( from , to ) . then ( ( ) => {
129
100
matchSnapshot ( t , fs . readFileSync ( to , 'utf8' ) , 'shell' )
130
101
matchSnapshot ( t , fs . readFileSync ( to + '.cmd' , 'utf8' ) , 'cmd' )
131
102
matchSnapshot ( t , fs . readFileSync ( to + '.ps1' , 'utf8' ) , 'ps1' )
132
- t . end ( )
133
103
} )
134
104
} )
135
105
136
106
test ( 'explicit shebang' , function ( t ) {
137
107
var from = path . resolve ( fixtures , 'from.sh' )
138
108
var to = path . resolve ( fixtures , 'sh.shim' )
139
- cmdShim ( from , to , function ( er ) {
140
- if ( er )
141
- throw er
142
-
109
+ return cmdShim ( from , to ) . then ( ( ) => {
143
110
matchSnapshot ( t , fs . readFileSync ( to , 'utf8' ) , 'shell' )
144
111
matchSnapshot ( t , fs . readFileSync ( to + '.cmd' , 'utf8' ) , 'cmd' )
145
112
matchSnapshot ( t , fs . readFileSync ( to + '.ps1' , 'utf8' ) , 'ps1' )
146
- t . end ( )
147
113
} )
148
114
} )
149
115
150
116
test ( 'explicit shebang with args' , function ( t ) {
151
117
var from = path . resolve ( fixtures , 'from.sh.args' )
152
118
var to = path . resolve ( fixtures , 'sh.args.shim' )
153
- cmdShim ( from , to , function ( er ) {
154
- if ( er )
155
- throw er
156
-
119
+ return cmdShim ( from , to ) . then ( ( ) => {
157
120
matchSnapshot ( t , fs . readFileSync ( to , 'utf8' ) , 'shell' )
158
121
matchSnapshot ( t , fs . readFileSync ( to + '.cmd' , 'utf8' ) , 'cmd' )
159
122
matchSnapshot ( t , fs . readFileSync ( to + '.ps1' , 'utf8' ) , 'ps1' )
160
- t . end ( )
161
123
} )
162
124
} )
0 commit comments