@@ -17,7 +17,7 @@ describe('EditorPrompt', () => {
1717 input = new MockReadable ( ) ;
1818 output = new MockWritable ( ) ;
1919 vol . reset ( ) ;
20- vol . fromJSON ( { './cache-abc' : 'foo' } , '/tmp ' ) ;
20+ vol . fromJSON ( { './tmp/ cache-abc' : 'foo' , './newtmp/cache-123' : 'bar' } , '/' ) ;
2121 } ) ;
2222
2323 afterEach ( ( ) => {
@@ -48,4 +48,114 @@ describe('EditorPrompt', () => {
4848 expect ( instance . value ) . to . equal ( 'hello' ) ;
4949 expect ( instance . state ) . to . equal ( 'submit' ) ;
5050 } ) ;
51+
52+ describe ( 'path' , ( ) => {
53+ const UUID_RE = [ 8 , 4 , 4 , 4 , 12 ] . map ( ( len ) => `[a-z0-9]{${ len } }` ) . join ( '-' ) ;
54+ const createRegexp = ( dir : string , postfix = '' ) =>
55+ new RegExp ( [ '' , dir , `ce-${ UUID_RE } ${ postfix } ` ] . join ( '[\\\\/]' ) ) ;
56+
57+ test ( 'default' , ( ) => {
58+ const instance = new EditorPrompt ( {
59+ input,
60+ output,
61+ render : ( ) => 'foo' ,
62+ } ) ;
63+
64+ instance . prompt ( ) ;
65+
66+ expect ( instance . path ) . to . match ( createRegexp ( 'tmp' ) ) ;
67+ } ) ;
68+
69+ test ( 'custom temp dir' , ( ) => {
70+ const instance = new EditorPrompt ( {
71+ input,
72+ output,
73+ render : ( ) => 'foo' ,
74+ tmpdir : '/newtmp' ,
75+ } ) ;
76+
77+ instance . prompt ( ) ;
78+
79+ expect ( instance . path ) . to . match ( createRegexp ( 'newtmp' ) ) ;
80+ } ) ;
81+
82+ test ( 'custom temp file postfix/extension' , ( ) => {
83+ const instance = new EditorPrompt ( {
84+ input,
85+ output,
86+ render : ( ) => 'foo' ,
87+ postfix : '.txt' ,
88+ } ) ;
89+
90+ instance . prompt ( ) ;
91+
92+ expect ( instance . path ) . to . match ( createRegexp ( 'tmp' , '.txt' ) ) ;
93+ } ) ;
94+ } ) ;
95+
96+ describe ( 'executable' , ( ) => {
97+ const originalEnv = structuredClone ( process . env ) ;
98+ const originalPlatform = process . platform ;
99+
100+ afterEach ( ( ) => {
101+ process . env = originalEnv ;
102+ Object . defineProperty ( process , 'platform' , { value : originalPlatform } ) ;
103+ } ) ;
104+
105+ test . each ( [ 'linux' , 'win32' ] ) ( '%s default' , ( platform ) => {
106+ Object . defineProperty ( process , 'platform' , { value : platform } ) ;
107+
108+ const instance = new EditorPrompt ( {
109+ input,
110+ output,
111+ render : ( ) => 'foo' ,
112+ } ) ;
113+
114+ instance . prompt ( ) ;
115+
116+ expect ( instance . bin ) . to . equal ( platform === 'win32' ? 'notepad' : 'nano' ) ;
117+ expect ( instance . args . length ) . to . equal ( 1 ) ;
118+ } ) ;
119+
120+ test ( 'custom binary' , ( ) => {
121+ const instance = new EditorPrompt ( {
122+ input,
123+ output,
124+ render : ( ) => 'foo' ,
125+ bin : 'vim' ,
126+ } ) ;
127+
128+ instance . prompt ( ) ;
129+
130+ expect ( instance . bin ) . to . equal ( 'vim' ) ;
131+ } ) ;
132+
133+ test ( 'custom binary via env.EDITOR' , ( ) => {
134+ process . env . EDITOR = 'nvim' ;
135+
136+ const instance = new EditorPrompt ( {
137+ input,
138+ output,
139+ render : ( ) => 'foo' ,
140+ } ) ;
141+
142+ instance . prompt ( ) ;
143+
144+ expect ( instance . bin ) . to . equal ( 'nvim' ) ;
145+ } ) ;
146+
147+ test ( 'custom args' , ( ) => {
148+ const instance = new EditorPrompt ( {
149+ input,
150+ output,
151+ render : ( ) => 'foo' ,
152+ args : ( p ) => [ '--' , p ] ,
153+ } ) ;
154+
155+ instance . prompt ( ) ;
156+
157+ expect ( instance . args . length ) . to . equal ( 2 ) ;
158+ expect ( instance . args [ 0 ] ) . to . equal ( '--' ) ;
159+ } ) ;
160+ } ) ;
51161} ) ;
0 commit comments