Skip to content

Commit b42624a

Browse files
committed
test: fix
1 parent a78e887 commit b42624a

File tree

1 file changed

+84
-85
lines changed

1 file changed

+84
-85
lines changed

test/index.js

Lines changed: 84 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,6 @@ const path = require('path')
77

88
function noop () {}
99

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-
5110
test('_incorrectWorkingDirectory: accepts wd for package that matches project\'s name', function (t) {
5211
const wd = '/opt/my-time/node_modules/time'
5312
const pkg = { name: 'time' }
@@ -116,7 +75,7 @@ test('runs scripts from .hooks directory even if no script is present in package
11675
.catch(t.end)
11776
})
11877

119-
test("reports child's output", function (t) {
78+
test("reports child's output", async (t) => {
12079
const fixture = path.join(__dirname, 'fixtures', 'count-to-10')
12180

12281
const verbose = sinon.spy()
@@ -136,53 +95,93 @@ test("reports child's output", function (t) {
13695

13796
const pkg = require(path.join(fixture, 'package.json'))
13897

139-
lifecycle(pkg, 'postinstall', fixture, {
98+
await lifecycle(pkg, 'postinstall', fixture, {
14099
stdio: 'pipe',
141100
log,
142101
dir,
143102
config: {}
144103
})
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+
)
184142

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()
188187
})

0 commit comments

Comments
 (0)