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
37import constants , {
48 FLAG_CONFIG ,
@@ -10,6 +14,55 @@ import { cmdit, spawnSocketCli } from '../../../test/utils.mts'
1014describe ( '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