@@ -16,6 +16,9 @@ import assert from 'node:assert'
16
16
import { test , describe , beforeEach } from 'node:test'
17
17
import { fileURLToPath } from 'node:url'
18
18
import '../build/globals.js'
19
+ import { isMain } from '../build/cli.js'
20
+
21
+ const __filename = fileURLToPath ( import . meta. url )
19
22
20
23
describe ( 'cli' , ( ) => {
21
24
// Helps detect unresolved ProcessPromise.
@@ -114,13 +117,15 @@ describe('cli', () => {
114
117
115
118
test ( 'scripts from https' , async ( ) => {
116
119
$ `cat ${ path . resolve ( 'test/fixtures/echo.http' ) } | nc -l 8080`
120
+ await sleep ( 50 )
117
121
let out =
118
122
await $ `node build/cli.js --verbose http://127.0.0.1:8080/echo.mjs`
119
123
assert . match ( out . stderr , / t e s t / )
120
124
} )
121
125
122
126
test ( 'scripts from https not ok' , async ( ) => {
123
127
$ `echo $'HTTP/1.1 500\n\n' | nc -l 8081`
128
+ await sleep ( 50 )
124
129
let out = await $ `node build/cli.js http://127.0.0.1:8081` . nothrow ( )
125
130
assert . match ( out . stderr , / E r r o r : C a n ' t g e t / )
126
131
} )
@@ -224,4 +229,28 @@ describe('cli', () => {
224
229
let p = await $ `node build/cli.js test/fixtures/exit-code.mjs` . nothrow ( )
225
230
assert . equal ( p . exitCode , 42 )
226
231
} )
232
+
233
+ describe ( 'internals' , ( ) => {
234
+ test ( 'isMain() checks process entry point' , ( ) => {
235
+ assert . equal ( isMain ( import . meta. url , __filename ) , true )
236
+
237
+ assert . equal (
238
+ isMain ( import . meta. url . replace ( '.js' , '.cjs' ) , __filename ) ,
239
+ true
240
+ )
241
+
242
+ try {
243
+ assert . equal (
244
+ isMain (
245
+ 'file:///root/zx/test/cli.test.js' ,
246
+ '/root/zx/test/all.test.js'
247
+ ) ,
248
+ true
249
+ )
250
+ assert . throw ( )
251
+ } catch ( e ) {
252
+ assert . equal ( e . code , 'ENOENT' )
253
+ }
254
+ } )
255
+ } )
227
256
} )
0 commit comments