Skip to content

Commit

Permalink
test: get free port to avoid net collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Dec 15, 2024
1 parent df6096a commit 30b3327
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"esbuild-plugin-transform-hook": "^0.1.1",
"esbuild-plugin-utils": "^0.1.0",
"fs-extra": "^11.2.0",
"get-port": "^7.1.0",
"globby": "^14.0.2",
"jsr": "^0.13.2",
"madge": "^8.0.0",
Expand Down
11 changes: 7 additions & 4 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import assert from 'node:assert'
import { test, describe, before, after } from 'node:test'
import { fileURLToPath } from 'node:url'
import getPort from 'get-port'
import '../build/globals.js'
import { isMain, normalizeExt } from '../build/cli.js'

Expand Down Expand Up @@ -124,17 +125,19 @@ describe('cli', () => {
})

test('scripts from https', async () => {
const server = $`cat ${path.resolve('test/fixtures/echo.http')} | nc -l 8080`
const port = await getPort()
const server = $`cat ${path.resolve('test/fixtures/echo.http')} | nc -l ${port}`
const out =
await $`sleep 10 && node build/cli.js --verbose http://127.0.0.1:8080/echo.mjs`
await $`sleep 10 && node build/cli.js --verbose http://127.0.0.1:${port}/echo.mjs`
assert.match(out.stderr, /test/)
await server.kill()
})

test('scripts from https not ok', async () => {
const server = $`echo $'HTTP/1.1 500\n\n' | nc -l 8081`
const port = await getPort()
const server = $`echo $'HTTP/1.1 500\n\n' | nc -l ${port}`
const out =
await $`sleep 10 && node build/cli.js http://127.0.0.1:8081`.nothrow()
await $`sleep 10 && node build/cli.js http://127.0.0.1:${port}`.nothrow()
assert.match(out.stderr, /Error: Can't get/)
await server.kill()
})
Expand Down

0 comments on commit 30b3327

Please sign in to comment.