diff --git a/src/commands/wrapper/add-socket-wrapper.mts b/src/commands/wrapper/add-socket-wrapper.mts index 8322c8792..e51f3f9e8 100644 --- a/src/commands/wrapper/add-socket-wrapper.mts +++ b/src/commands/wrapper/add-socket-wrapper.mts @@ -14,7 +14,7 @@ export function addSocketWrapper(file: string): void { `The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉`, ) logger.log( - ` If you want to disable it at any time, run \`socket wrapper --disable\``, + ` If you want to disable it at any time, run \`socket wrapper off\``, ) logger.log('') logger.info( diff --git a/src/commands/wrapper/cmd-wrapper.test.mts b/src/commands/wrapper/cmd-wrapper.test.mts index ade38593d..7acb234b4 100644 --- a/src/commands/wrapper/cmd-wrapper.test.mts +++ b/src/commands/wrapper/cmd-wrapper.test.mts @@ -1,4 +1,8 @@ -import { describe, expect } from 'vitest' +import { promises as fs } from 'node:fs' +import os from 'node:os' +import path from 'node:path' + +import { describe, expect, it } from 'vitest' import constants, { FLAG_CONFIG, @@ -10,6 +14,55 @@ import { cmdit, spawnSocketCli } from '../../../test/utils.mts' describe('socket wrapper', async () => { const { binCliPath } = constants + it('prints the supported command to disable the wrapper', async () => { + const temporaryHome = await fs.mkdtemp( + path.join(os.tmpdir(), 'socket-wrapper-'), + ) + const profilePath = path.join(temporaryHome, '.bashrc') + const configDirectory = path.join(temporaryHome, 'config') + const env = { + HOME: temporaryHome, + USERPROFILE: temporaryHome, + XDG_CONFIG_HOME: configDirectory, + } + + try { + await fs.mkdir(configDirectory) + await fs.writeFile(profilePath, '') + + const enabled = await spawnSocketCli( + binCliPath, + ['wrapper', 'on', FLAG_CONFIG, '{}'], + { env }, + ) + expect(enabled.code).toBe(0) + expect(`${enabled.stdout}\n${enabled.stderr}`).toContain( + '`socket wrapper off`', + ) + expect(`${enabled.stdout}\n${enabled.stderr}`).not.toContain( + '`socket wrapper --disable`', + ) + expect(await fs.readFile(profilePath, 'utf8')).toContain( + 'alias npm="socket npm"', + ) + + const disabled = await spawnSocketCli( + binCliPath, + ['wrapper', 'off', FLAG_CONFIG, '{}'], + { env }, + ) + expect(disabled.code).toBe(0) + expect(await fs.readFile(profilePath, 'utf8')).not.toContain( + 'alias npm="socket npm"', + ) + expect(await fs.readFile(profilePath, 'utf8')).not.toContain( + 'alias npx="socket npx"', + ) + } finally { + await fs.rm(temporaryHome, { force: true, recursive: true }) + } + }) + cmdit( ['wrapper', FLAG_HELP, FLAG_CONFIG, '{}'], `should support ${FLAG_HELP}`,