Skip to content

Commit c656f96

Browse files
committed
chore: fix failing tests in windows + node 18
Some of our tests were failing in windows after testing on node 18. The reason was the inability to clean up the logs dir. This changes forces a few tests to run in order and also cleans up any use of multiple `t.testdir` calls in a single child test which can cause problems.
1 parent fc9acd7 commit c656f96

File tree

4 files changed

+249
-276
lines changed

4 files changed

+249
-276
lines changed

test/fixtures/mock-npm.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const LoadMockNpm = async (t, {
6666
globalPrefixDir = { lib: {} },
6767
config = {},
6868
mocks = {},
69+
otherDirs = {},
6970
globals = null,
7071
} = {}) => {
7172
// Mock some globals with their original values so they get torn down
@@ -107,13 +108,15 @@ const LoadMockNpm = async (t, {
107108
prefix: prefixDir,
108109
cache: cacheDir,
109110
global: globalPrefixDir,
111+
other: otherDirs,
110112
})
111113
const dirs = {
112114
testdir: dir,
113115
prefix: path.join(dir, 'prefix'),
114116
cache: path.join(dir, 'cache'),
115117
globalPrefix: path.join(dir, 'global'),
116118
home: path.join(dir, 'home'),
119+
other: path.join(dir, 'other'),
117120
}
118121

119122
// Set cache to testdir via env var so it is available when load is run

test/lib/cli.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ const { load: loadMockNpm } = require('../fixtures/mock-npm.js')
55
const cliMock = async (t, opts) => {
66
let exitHandlerArgs = null
77
let npm = null
8+
89
const exitHandlerMock = (...args) => {
910
exitHandlerArgs = args
1011
npm.unload()
1112
}
12-
exitHandlerMock.setNpm = _npm => npm = _npm
13+
exitHandlerMock.setNpm = (_npm) => npm = _npm
1314

1415
const { Npm, outputs, logMocks, logs } = await loadMockNpm(t, { ...opts, init: false })
1516
const cli = t.mock('../../lib/cli.js', {
@@ -172,37 +173,15 @@ t.test('load error calls error handler', async t => {
172173
t.strictSame(exitHandlerCalled(), [err])
173174
})
174175

175-
t.test('known broken node version', async t => {
176-
const errors = []
177-
let exitCode
178-
const { cli } = await cliMock(t, {
179-
globals: {
180-
'console.error': (msg) => errors.push(msg),
181-
'process.version': '6.0.0',
182-
'process.exit': e => exitCode = e,
183-
},
184-
})
185-
await cli(process)
186-
t.match(errors, [
187-
'ERROR: npm is known not to run on Node.js 6.0.0',
188-
'You\'ll need to upgrade to a newer Node.js version in order to use this',
189-
'version of npm. You can find the latest version at https://nodejs.org/',
190-
])
191-
t.match(exitCode, 1)
192-
})
193-
194176
t.test('unsupported node version', async t => {
195-
const errors = []
196-
const { cli } = await cliMock(t, {
177+
const { cli, logs } = await cliMock(t, {
197178
globals: {
198-
'console.error': (msg) => errors.push(msg),
199179
'process.version': '12.6.0',
200180
},
201181
})
202182
await cli(process)
203-
t.match(errors, [
204-
'npm does not support Node.js 12.6.0',
205-
'You should probably upgrade to a newer version of node as we',
206-
'can\'t make any promises that npm will work with this version.',
207-
])
183+
t.match(
184+
logs.warn[0][1],
185+
/npm v.* does not support Node\.js 12\.6\.0\./
186+
)
208187
})

0 commit comments

Comments
 (0)