@@ -7,47 +7,6 @@ const path = require('path')
7
7
8
8
function noop ( ) { }
9
9
10
- test ( 'makeEnv' , function ( t ) {
11
- const pkg = {
12
- name : 'myPackage' ,
13
- version : '1.0.0' ,
14
- contributors :
[ { name :
'Mike Sherov' , email :
'[email protected] ' } ]
15
- }
16
- const config = {
17
- enteente : Infinity ,
18
- '_privateVar' : 1 ,
19
- '_myPackage:myPrivateVar' : 1 ,
20
- 'myPackage:bar' : 2 ,
21
- 'myPackage:foo' : 3 ,
22
-
23
-
24
- }
25
-
26
- const env = lifecycle . makeEnv ( pkg , {
27
- config,
28
- nodeOptions : '--inspect-brk --abort-on-uncaught-exception'
29
- } , null , process . env )
30
-
31
- t . equal ( 'myPackage' , env . npm_package_name , 'package data is included' )
32
- t . equal ( 'Mike Sherov' , env . npm_package_contributors_0_name , 'nested package data is included' )
33
-
34
- t . equal ( 'Infinity' , env . npm_config_enteente , 'public config is included' )
35
- t . equal ( undefined , env . npm_config_privateVar , 'private config is excluded' )
36
-
37
- t . equal ( '1' , env . npm_config_myPackage_myPrivateVar , 'private package config is included by name' )
38
- t . equal ( '2' , env . npm_config_myPackage_bar , 'public package config is included by name' )
39
-
40
- t . equal ( '5' , env . npm_config_myPackage_1_0_0_foo , 'public package@version config is included by name' )
41
-
42
- t . equal ( '1' , env . npm_package_config_myPrivateVar , 'package private config is included' )
43
- t . equal ( '2' , env . npm_package_config_bar , 'package config is included' )
44
- t . equal ( '4' , env . npm_package_config_baz , 'package@version config is included' )
45
- t . equal ( '5' , env . npm_package_config_foo , 'package@version config overrides package config' )
46
-
47
- t . equal ( '--inspect-brk --abort-on-uncaught-exception' , env . NODE_OPTIONS , 'nodeOptions sets NODE_OPTIONS' )
48
- t . end ( )
49
- } )
50
-
51
10
test ( '_incorrectWorkingDirectory: accepts wd for package that matches project\'s name' , function ( t ) {
52
11
const wd = '/opt/my-time/node_modules/time'
53
12
const pkg = { name : 'time' }
@@ -116,7 +75,7 @@ test('runs scripts from .hooks directory even if no script is present in package
116
75
. catch ( t . end )
117
76
} )
118
77
119
- test ( "reports child's output" , function ( t ) {
78
+ test ( "reports child's output" , async ( t ) => {
120
79
const fixture = path . join ( __dirname , 'fixtures' , 'count-to-10' )
121
80
122
81
const verbose = sinon . spy ( )
@@ -136,53 +95,93 @@ test("reports child's output", function (t) {
136
95
137
96
const pkg = require ( path . join ( fixture , 'package.json' ) )
138
97
139
- lifecycle ( pkg , 'postinstall' , fixture , {
98
+ await lifecycle ( pkg , 'postinstall' , fixture , {
140
99
stdio : 'pipe' ,
141
100
log,
142
101
dir,
143
102
config : { }
144
103
} )
145
- . then ( ( ) => {
146
- t . ok (
147
- verbose . calledWithMatch (
148
- 'lifecycle' ,
149
- 'undefined~postinstall:' ,
150
- 'stdout' ,
151
- 'line 1'
152
- ) ,
153
- 'stdout reported'
154
- )
155
- t . ok (
156
- verbose . calledWithMatch (
157
- 'lifecycle' ,
158
- 'undefined~postinstall:' ,
159
- 'stdout' ,
160
- 'line 2'
161
- ) ,
162
- 'stdout reported'
163
- )
164
- t . ok (
165
- verbose . calledWithMatch (
166
- 'lifecycle' ,
167
- 'undefined~postinstall:' ,
168
- 'stderr' ,
169
- 'some error'
170
- ) ,
171
- 'stderr reported'
172
- )
173
- t . ok (
174
- silly . calledWithMatch (
175
- 'lifecycle' ,
176
- 'undefined~postinstall:' ,
177
- 'Returned: code:' ,
178
- 0 ,
179
- ' signal:' ,
180
- null
181
- ) ,
182
- 'exit code reported'
183
- )
104
+ t . ok (
105
+ verbose . calledWithMatch (
106
+ 'lifecycle' ,
107
+ 'undefined~postinstall:' ,
108
+ 'stdout' ,
109
+ 'line 1'
110
+ ) ,
111
+ 'stdout reported'
112
+ )
113
+ t . ok (
114
+ verbose . calledWithMatch (
115
+ 'lifecycle' ,
116
+ 'undefined~postinstall:' ,
117
+ 'stdout' ,
118
+ 'line 2'
119
+ ) ,
120
+ 'stdout reported'
121
+ )
122
+ t . ok (
123
+ verbose . calledWithMatch (
124
+ 'lifecycle' ,
125
+ 'undefined~postinstall:' ,
126
+ 'stderr' ,
127
+ 'some error'
128
+ ) ,
129
+ 'stderr reported'
130
+ )
131
+ t . ok (
132
+ silly . calledWithMatch (
133
+ 'lifecycle' ,
134
+ 'undefined~postinstall:' ,
135
+ 'Returned: code:' ,
136
+ 0 ,
137
+ ' signal:' ,
138
+ null
139
+ ) ,
140
+ 'exit code reported'
141
+ )
184
142
185
- t . end ( )
186
- } )
187
- . catch ( t . end )
143
+ t . end ( )
144
+ } )
145
+
146
+ // WARNING! For some reason, when this test runs first,
147
+ // the "reports child's output" fails
148
+ test ( 'makeEnv' , function ( t ) {
149
+ const pkg = {
150
+ name : 'myPackage' ,
151
+ version : '1.0.0' ,
152
+ contributors :
[ { name :
'Mike Sherov' , email :
'[email protected] ' } ]
153
+ }
154
+ const config = {
155
+ enteente : Infinity ,
156
+ '_privateVar' : 1 ,
157
+ '_myPackage:myPrivateVar' : 1 ,
158
+ 'myPackage:bar' : 2 ,
159
+ 'myPackage:foo' : 3 ,
160
+
161
+
162
+ }
163
+
164
+ const env = lifecycle . makeEnv ( pkg , {
165
+ config,
166
+ nodeOptions : '--inspect-brk --abort-on-uncaught-exception'
167
+ } , null , process . env )
168
+
169
+ t . equal ( 'myPackage' , env . npm_package_name , 'package data is included' )
170
+ t . equal ( 'Mike Sherov' , env . npm_package_contributors_0_name , 'nested package data is included' )
171
+
172
+ t . equal ( 'Infinity' , env . npm_config_enteente , 'public config is included' )
173
+ t . equal ( undefined , env . npm_config_privateVar , 'private config is excluded' )
174
+
175
+ t . equal ( '1' , env . npm_config_myPackage_myPrivateVar , 'private package config is included by name' )
176
+ t . equal ( '2' , env . npm_config_myPackage_bar , 'public package config is included by name' )
177
+
178
+ t . equal ( '5' , env . npm_config_myPackage_1_0_0_foo , 'public package@version config is included by name' )
179
+
180
+ t . equal ( '1' , env . npm_package_config_myPrivateVar , 'package private config is included' )
181
+ t . equal ( '2' , env . npm_package_config_bar , 'package config is included' )
182
+ t . equal ( '4' , env . npm_package_config_baz , 'package@version config is included' )
183
+ t . equal ( '5' , env . npm_package_config_foo , 'package@version config overrides package config' )
184
+
185
+ t . equal ( '--inspect-brk --abort-on-uncaught-exception' , env . NODE_OPTIONS , 'nodeOptions sets NODE_OPTIONS' )
186
+ t . end ( )
188
187
} )
0 commit comments