Skip to content

Commit a5fb49f

Browse files
committed
addressing comments, fix sbom, revert server, cleanup refiy fs mock
1 parent e3a33ee commit a5fb49f

File tree

3 files changed

+10
-37
lines changed

3 files changed

+10
-37
lines changed

test/lib/commands/sbom.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const mockSbom = async (t, { mocks, config, ...opts } = {}) => {
7070
},
7171
command: 'sbom',
7272
mocks: {
73-
path: {
73+
'node:path': {
7474
...require('node:path'),
7575
sep: '/',
7676
},

workspaces/arborist/test/arborist/rebuild.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ const server = require('node:http').createServer(() => {
1717
throw new Error('rebuild should not hit the registry')
1818
})
1919
t.before(() => new Promise(res => {
20-
server.listen(PORT, res)
20+
server.listen(PORT, () => {
21+
t.teardown(() => server.close())
22+
res()
23+
})
2124
}))
2225

23-
t.teardown(() => server.close())
24-
2526
const registry = `http://localhost:${PORT}`
2627
const newArb = opt => new Arborist({ ...opt, registry })
2728

workspaces/arborist/test/arborist/reify.js

+5-33
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,19 @@ let failRm = false
1111
let failRename = null
1212
let failRenameOnce = null
1313
let failMkdir = null
14-
const { rename: realRename, rm: realRm, mkdir: realMkdir } = fs
15-
const fsMock = {
16-
...fs,
17-
mkdir (...args) {
18-
if (failMkdir) {
19-
process.nextTick(() => args.pop()(failMkdir))
20-
return
21-
}
22-
23-
return realMkdir(...args)
24-
},
25-
rename (...args) {
26-
if (failRename) {
27-
process.nextTick(() => args.pop()(failRename))
28-
} else if (failRenameOnce) {
29-
const er = failRenameOnce
30-
failRenameOnce = null
31-
process.nextTick(() => args.pop()(er))
32-
} else {
33-
return realRename(...args)
34-
}
35-
},
36-
rm (...args) {
37-
if (failRm) {
38-
process.nextTick(() => args.pop()(new Error('rm fail')))
39-
return
40-
}
4114

42-
realRm(...args)
43-
},
44-
}
4515
const fspMock = {
4616
...fsp,
4717
mkdir: async (...args) => {
18+
fs.appendFileSync('reggi-log.txt', 'fspNodeMock.mkdir\n')
4819
if (failMkdir) {
4920
throw failMkdir
5021
}
5122

5223
return fsp.mkdir(...args)
5324
},
5425
rename: async (...args) => {
26+
fs.appendFileSync('reggi-log.txt', 'fspNodeMock.rename\n')
5527
if (failRename) {
5628
throw failRename
5729
} else if (failRenameOnce) {
@@ -63,19 +35,19 @@ const fspMock = {
6335
}
6436
},
6537
rm: async (...args) => {
38+
fs.appendFileSync('reggi-log.txt', 'fspNodeMock.rm\n')
6639
if (failRm) {
6740
throw new Error('rm fail')
6841
}
6942

7043
return fsp.rm(...args)
7144
},
7245
}
46+
7347
// need this to be injected so that it doesn't pull from main cache
74-
const { moveFile } = t.mock('@npmcli/fs', { 'node:fs/promises': fspMock, 'fs/promises': fspMock })
48+
const { moveFile } = t.mock('@npmcli/fs', { 'fs/promises': fspMock })
7549
const mocks = {
76-
fs: fsMock,
7750
'node:fs/promises': fspMock,
78-
'fs/promises': fspMock,
7951
'@npmcli/fs': { ...npmFs, moveFile },
8052
}
8153

0 commit comments

Comments
 (0)