Skip to content

Commit 5baf3f0

Browse files
authored
fix(wrapper): correct disable guidance (#1607)
1 parent 9912a50 commit 5baf3f0

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

‎src/commands/wrapper/add-socket-wrapper.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function addSocketWrapper(file: string): void {
1414
`The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉`,
1515
)
1616
logger.log(
17-
` If you want to disable it at any time, run \`socket wrapper --disable\``,
17+
` If you want to disable it at any time, run \`socket wrapper off\``,
1818
)
1919
logger.log('')
2020
logger.info(

‎src/commands/wrapper/cmd-wrapper.test.mts‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { describe, expect } from 'vitest'
1+
import { promises as fs } from 'node:fs'
2+
import os from 'node:os'
3+
import path from 'node:path'
4+
5+
import { describe, expect, it } from 'vitest'
26

37
import constants, {
48
FLAG_CONFIG,
@@ -10,6 +14,55 @@ import { cmdit, spawnSocketCli } from '../../../test/utils.mts'
1014
describe('socket wrapper', async () => {
1115
const { binCliPath } = constants
1216

17+
it('prints the supported command to disable the wrapper', async () => {
18+
const temporaryHome = await fs.mkdtemp(
19+
path.join(os.tmpdir(), 'socket-wrapper-'),
20+
)
21+
const profilePath = path.join(temporaryHome, '.bashrc')
22+
const configDirectory = path.join(temporaryHome, 'config')
23+
const env = {
24+
HOME: temporaryHome,
25+
USERPROFILE: temporaryHome,
26+
XDG_CONFIG_HOME: configDirectory,
27+
}
28+
29+
try {
30+
await fs.mkdir(configDirectory)
31+
await fs.writeFile(profilePath, '')
32+
33+
const enabled = await spawnSocketCli(
34+
binCliPath,
35+
['wrapper', 'on', FLAG_CONFIG, '{}'],
36+
{ env },
37+
)
38+
expect(enabled.code).toBe(0)
39+
expect(`${enabled.stdout}\n${enabled.stderr}`).toContain(
40+
'`socket wrapper off`',
41+
)
42+
expect(`${enabled.stdout}\n${enabled.stderr}`).not.toContain(
43+
'`socket wrapper --disable`',
44+
)
45+
expect(await fs.readFile(profilePath, 'utf8')).toContain(
46+
'alias npm="socket npm"',
47+
)
48+
49+
const disabled = await spawnSocketCli(
50+
binCliPath,
51+
['wrapper', 'off', FLAG_CONFIG, '{}'],
52+
{ env },
53+
)
54+
expect(disabled.code).toBe(0)
55+
expect(await fs.readFile(profilePath, 'utf8')).not.toContain(
56+
'alias npm="socket npm"',
57+
)
58+
expect(await fs.readFile(profilePath, 'utf8')).not.toContain(
59+
'alias npx="socket npx"',
60+
)
61+
} finally {
62+
await fs.rm(temporaryHome, { force: true, recursive: true })
63+
}
64+
})
65+
1366
cmdit(
1467
['wrapper', FLAG_HELP, FLAG_CONFIG, '{}'],
1568
`should support ${FLAG_HELP}`,

0 commit comments

Comments
 (0)