Skip to content

Commit 7ca8a6a

Browse files
committed
fix(tests): properly mock paths and dependencies in postinstall-wrapper tests
Fixed all 10 tests by: - Mocking getBashRcPath() and getZshRcPath() from constants/paths.mts - Fixing import paths for completion.mjs and errors.mjs - Using correct module paths for mocked dependencies All tests now pass locally and should pass in CI.
1 parent 60076ba commit 7ca8a6a

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

packages/cli/src/commands/wrapper/postinstall-wrapper.test.mts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,17 @@ vi.mock('./add-socket-wrapper.mts', () => ({
2121
vi.mock('./check-socket-wrapper-setup.mts', () => ({
2222
checkSocketWrapperSetup: vi.fn(),
2323
}))
24-
vi.mock('../../constants.mts', () => {
25-
const kInternalsSymbol = Symbol.for('kInternalsSymbol')
26-
return {
27-
default: {
28-
bashRcPath: '/home/user/.bashrc',
29-
zshRcPath: '/home/user/.zshrc',
30-
kInternalsSymbol,
31-
[kInternalsSymbol as any]: {
32-
getSentry: vi.fn().mockReturnValue(undefined),
33-
},
34-
},
35-
}
36-
})
37-
vi.mock('../../utils/completion.mts', () => ({
24+
vi.mock('../../constants/paths.mts', () => ({
25+
getBashRcPath: vi.fn(() => '/home/user/.bashrc'),
26+
getZshRcPath: vi.fn(() => '/home/user/.zshrc'),
27+
}))
28+
vi.mock('../../utils/cli/completion.mjs', () => ({
3829
getBashrcDetails: vi.fn(),
3930
}))
4031
vi.mock('../install/setup-tab-completion.mts', () => ({
4132
updateInstalledTabCompletionScript: vi.fn(),
4233
}))
43-
vi.mock('../../utils/errors.mts', () => ({
34+
vi.mock('../../utils/error/errors.mjs', () => ({
4435
getErrorCause: vi.fn(e => e?.message || String(e)),
4536
}))
4637

@@ -184,7 +175,7 @@ describe('postinstallWrapper', () => {
184175
})
185176

186177
it('updates tab completion when it exists', async () => {
187-
const { getBashrcDetails } = await import('../../utils/completion.mts')
178+
const { getBashrcDetails } = await import('../../utils/cli/completion.mjs')
188179
const { logger } = await import('@socketsecurity/lib/logger')
189180
const { updateInstalledTabCompletionScript } = await import(
190181
'../install/setup-tab-completion.mts'
@@ -218,7 +209,7 @@ describe('postinstallWrapper', () => {
218209
})
219210

220211
it('skips tab completion update when file does not exist', async () => {
221-
const { getBashrcDetails } = await import('../../utils/completion.mts')
212+
const { getBashrcDetails } = await import('../../utils/cli/completion.mjs')
222213
const { logger } = await import('@socketsecurity/lib/logger')
223214
const { updateInstalledTabCompletionScript } = await import(
224215
'../install/setup-tab-completion.mts'
@@ -248,7 +239,7 @@ describe('postinstallWrapper', () => {
248239
})
249240

250241
it('handles tab completion update failure gracefully', async () => {
251-
const { getBashrcDetails } = await import('../../utils/completion.mts')
242+
const { getBashrcDetails } = await import('../../utils/cli/completion.mjs')
252243
const { logger } = await import('@socketsecurity/lib/logger')
253244
const mockExistsSync = vi.mocked(existsSync) as any
254245
const mockGetDetails = vi.mocked(getBashrcDetails)
@@ -271,7 +262,7 @@ describe('postinstallWrapper', () => {
271262
})
272263

273264
it('handles getBashrcDetails returning not ok', async () => {
274-
const { getBashrcDetails } = await import('../../utils/completion.mts')
265+
const { getBashrcDetails } = await import('../../utils/cli/completion.mjs')
275266
const { logger } = await import('@socketsecurity/lib/logger')
276267
const mockExistsSync = vi.mocked(existsSync) as any
277268
const mockGetDetails = vi.mocked(getBashrcDetails)

0 commit comments

Comments
 (0)