1- import * as cp from "node:child_process" ;
2- import fs from "node:fs/promises" ;
3- import os from "node:os" ;
4- import path from "node:path" ;
5- import { beforeAll , describe , expect , it } from "vitest" ;
1+ import * as cp from "node:child_process"
2+ import fs from "node:fs/promises"
3+ import os from "node:os"
4+ import path from "node:path"
5+ import { beforeAll , describe , expect , it } from "vitest"
66
77import {
88 expectPathsEqual ,
@@ -12,154 +12,152 @@ import {
1212 printEnvCommand ,
1313 shimExecFile ,
1414 writeExecutable ,
15- } from "./platform" ;
15+ } from "./platform"
1616
1717describe ( "platform utils" , ( ) => {
1818 describe ( "printCommand" , ( ) => {
1919 it ( "should generate a simple node command" , ( ) => {
20- const result = printCommand ( "hello world" ) ;
21- expect ( result ) . toBe ( "node -e \"process.stdout.write('hello world')\"" ) ;
22- } ) ;
20+ const result = printCommand ( "hello world" )
21+ expect ( result ) . toBe ( "node -e \"process.stdout.write('hello world')\"" )
22+ } )
2323
2424 it ( "should escape special characters" , ( ) => {
25- const result = printCommand ( 'path\\to\\file\'s "name"\nline2\rcarriage' ) ;
25+ const result = printCommand ( 'path\\to\\file\'s "name"\nline2\rcarriage' )
2626 expect ( result ) . toBe (
2727 'node -e "process.stdout.write(\'path\\\\to\\\\file\\\'s \\"name\\"\\nline2\\rcarriage\')"' ,
28- ) ;
29- } ) ;
30- } ) ;
28+ )
29+ } )
30+ } )
3131
3232 describe ( "exitCommand" , ( ) => {
3333 it ( "should generate node commands with various exit codes" , ( ) => {
34- expect ( exitCommand ( 0 ) ) . toBe ( 'node -e "process.exit(0)"' ) ;
35- expect ( exitCommand ( 1 ) ) . toBe ( 'node -e "process.exit(1)"' ) ;
36- expect ( exitCommand ( 42 ) ) . toBe ( 'node -e "process.exit(42)"' ) ;
37- expect ( exitCommand ( - 1 ) ) . toBe ( 'node -e "process.exit(-1)"' ) ;
38- } ) ;
39- } ) ;
34+ expect ( exitCommand ( 0 ) ) . toBe ( 'node -e "process.exit(0)"' )
35+ expect ( exitCommand ( 1 ) ) . toBe ( 'node -e "process.exit(1)"' )
36+ expect ( exitCommand ( 42 ) ) . toBe ( 'node -e "process.exit(42)"' )
37+ expect ( exitCommand ( - 1 ) ) . toBe ( 'node -e "process.exit(-1)"' )
38+ } )
39+ } )
4040
4141 describe ( "printEnvCommand" , ( ) => {
4242 it ( "should generate node commands that print env variables" , ( ) => {
4343 expect ( printEnvCommand ( "url" , "CODER_URL" ) ) . toBe (
4444 "node -e \"process.stdout.write('url=' + process.env.CODER_URL)\"" ,
45- ) ;
45+ )
4646 expect ( printEnvCommand ( "token" , "CODER_TOKEN" ) ) . toBe (
4747 "node -e \"process.stdout.write('token=' + process.env.CODER_TOKEN)\"" ,
48- ) ;
48+ )
4949 // Will fail to execute but that's fine
5050 expect ( printEnvCommand ( "" , "" ) ) . toBe (
5151 "node -e \"process.stdout.write('=' + process.env.)\"" ,
52- ) ;
53- } ) ;
54- } ) ;
52+ )
53+ } )
54+ } )
5555
5656 describe ( "expectPathsEqual" , ( ) => {
5757 it ( "should consider identical paths equal" , ( ) => {
58- expectPathsEqual ( "same/path" , "same/path" ) ;
59- } ) ;
58+ expectPathsEqual ( "same/path" , "same/path" )
59+ } )
6060
6161 it ( "should throw when paths are different" , ( ) => {
62- expect ( ( ) =>
63- expectPathsEqual ( "path/to/file1" , "path/to/file2" ) ,
64- ) . toThrow ( ) ;
65- } ) ;
62+ expect ( ( ) => expectPathsEqual ( "path/to/file1" , "path/to/file2" ) ) . toThrow ( )
63+ } )
6664
6765 it ( "should handle empty paths" , ( ) => {
68- expectPathsEqual ( "" , "" ) ;
69- } ) ;
66+ expectPathsEqual ( "" , "" )
67+ } )
7068
7169 it . runIf ( isWindows ( ) ) (
7270 "should consider paths with different separators equal on Windows" ,
7371 ( ) => {
74- expectPathsEqual ( "path/to/file" , "path\\to\\file" ) ;
75- expectPathsEqual ( "C:/path/to/file" , "C:\\path\\to\\file" ) ;
72+ expectPathsEqual ( "path/to/file" , "path\\to\\file" )
73+ expectPathsEqual ( "C:/path/to/file" , "C:\\path\\to\\file" )
7674 expectPathsEqual (
7775 "C:/path with spaces/file" ,
7876 "C:\\path with spaces\\file" ,
79- ) ;
77+ )
8078 } ,
81- ) ;
79+ )
8280
8381 it . skipIf ( isWindows ( ) ) (
8482 "should consider backslash as literal on non-Windows" ,
8583 ( ) => {
8684 expect ( ( ) =>
8785 expectPathsEqual ( "path/to/file" , "path\\to\\file" ) ,
88- ) . toThrow ( ) ;
86+ ) . toThrow ( )
8987 } ,
90- ) ;
91- } ) ;
88+ )
89+ } )
9290
9391 describe ( "writeExecutable" , ( ) => {
94- const tmp = path . join ( os . tmpdir ( ) , "vscode-coder-tests-platform" ) ;
92+ const tmp = path . join ( os . tmpdir ( ) , "vscode-coder-tests-platform" )
9593
9694 beforeAll ( async ( ) => {
97- await fs . rm ( tmp , { recursive : true , force : true } ) ;
98- await fs . mkdir ( tmp , { recursive : true } ) ;
99- } ) ;
95+ await fs . rm ( tmp , { recursive : true , force : true } )
96+ await fs . mkdir ( tmp , { recursive : true } )
97+ } )
10098
10199 it ( "writes a .js file and returns its path" , async ( ) => {
102- const result = await writeExecutable ( tmp , "test-script" , "// hello" ) ;
103- expect ( result ) . toBe ( path . join ( tmp , "test-script.js" ) ) ;
104- expect ( await fs . readFile ( result , "utf-8" ) ) . toBe ( "// hello" ) ;
105- } ) ;
100+ const result = await writeExecutable ( tmp , "test-script" , "// hello" )
101+ expect ( result ) . toBe ( path . join ( tmp , "test-script.js" ) )
102+ expect ( await fs . readFile ( result , "utf-8" ) ) . toBe ( "// hello" )
103+ } )
106104
107105 it ( "overwrites existing files" , async ( ) => {
108- await writeExecutable ( tmp , "overwrite" , "first" ) ;
109- const result = await writeExecutable ( tmp , "overwrite" , "second" ) ;
110- expect ( await fs . readFile ( result , "utf-8" ) ) . toBe ( "second" ) ;
111- } ) ;
112- } ) ;
106+ await writeExecutable ( tmp , "overwrite" , "first" )
107+ const result = await writeExecutable ( tmp , "overwrite" , "second" )
108+ expect ( await fs . readFile ( result , "utf-8" ) ) . toBe ( "second" )
109+ } )
110+ } )
113111
114112 describe ( "shimExecFile" , ( ) => {
115- const tmp = path . join ( os . tmpdir ( ) , "vscode-coder-tests-shim" ) ;
116- const mod = shimExecFile ( cp ) ;
113+ const tmp = path . join ( os . tmpdir ( ) , "vscode-coder-tests-shim" )
114+ const mod = shimExecFile ( cp )
117115
118116 beforeAll ( async ( ) => {
119- await fs . rm ( tmp , { recursive : true , force : true } ) ;
120- await fs . mkdir ( tmp , { recursive : true } ) ;
121- } ) ;
117+ await fs . rm ( tmp , { recursive : true , force : true } )
118+ await fs . mkdir ( tmp , { recursive : true } )
119+ } )
122120
123121 it ( "runs .js files through node" , async ( ) => {
124122 const script = await writeExecutable (
125123 tmp ,
126124 "echo" ,
127125 'process.stdout.write("ok");' ,
128- ) ;
126+ )
129127 const stdout = await new Promise < string > ( ( resolve , reject ) => {
130128 mod . execFile ( script , ( err , out ) =>
131129 err ? reject ( new Error ( err . message ) ) : resolve ( out ) ,
132- ) ;
133- } ) ;
134- expect ( stdout ) . toBe ( "ok" ) ;
135- } ) ;
130+ )
131+ } )
132+ expect ( stdout ) . toBe ( "ok" )
133+ } )
136134
137135 it ( "passes args through to the script" , async ( ) => {
138136 const script = await writeExecutable (
139137 tmp ,
140138 "echo-args" ,
141139 "process.stdout.write(process.argv.slice(2).join(','));" ,
142- ) ;
140+ )
143141 const stdout = await new Promise < string > ( ( resolve , reject ) => {
144142 mod . execFile ( script , [ "a" , "b" , "c" ] , ( err , out ) =>
145143 err ? reject ( new Error ( err . message ) ) : resolve ( out ) ,
146- ) ;
147- } ) ;
148- expect ( stdout ) . toBe ( "a,b,c" ) ;
149- } ) ;
144+ )
145+ } )
146+ expect ( stdout ) . toBe ( "a,b,c" )
147+ } )
150148
151149 it ( "does not rewrite non-.js files" , async ( ) => {
152150 await expect (
153151 new Promise ( ( resolve , reject ) => {
154152 mod . execFile ( "/nonexistent/binary" , ( err , out ) =>
155153 err ? reject ( new Error ( err . message ) ) : resolve ( out ) ,
156- ) ;
154+ )
157155 } ) ,
158- ) . rejects . toThrow ( "ENOENT" ) ;
159- } ) ;
156+ ) . rejects . toThrow ( "ENOENT" )
157+ } )
160158
161159 it ( "does not touch spawn" , ( ) => {
162- expect ( mod . spawn ) . toBe ( cp . spawn ) ;
163- } ) ;
164- } ) ;
165- } ) ;
160+ expect ( mod . spawn ) . toBe ( cp . spawn )
161+ } )
162+ } )
163+ } )
0 commit comments