|
1 | | -import assert from 'node:assert' |
2 | | -import test from 'node:test' |
3 | | -import { spawn } from 'node:child_process' |
4 | | -import { fetch } from 'ofetch' |
5 | | -import process from 'node:process' |
| 1 | +import assert from "node:assert"; |
| 2 | +import test from "node:test"; |
| 3 | +import { spawn } from "node:child_process"; |
| 4 | +import { fetch } from "ofetch"; |
| 5 | +import process from "node:process"; |
6 | 6 |
|
7 | | -const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) |
| 7 | +const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); |
8 | 8 |
|
9 | | -test('node integration test', async () => { |
10 | | - const child = spawn('npx', ['--no-install', 'tsx', './index.ts'], { |
| 9 | +test("node integration test", async () => { |
| 10 | + const child = spawn("pnpx", ["tsx", "./index.ts"], { |
11 | 11 | cwd: process.cwd(), |
12 | | - stdio: 'inherit', |
13 | | - }) |
14 | | - await sleep(2000) |
| 12 | + stdio: "inherit", |
| 13 | + }); |
| 14 | + await sleep(3000); |
15 | 15 |
|
16 | | - const req = new Request('http://localhost:8123') |
17 | | - req.headers.set('accept-language', 'en-US,en;q=0.9,ja;q=0.8') |
18 | | - const res = await fetch(req) |
19 | | - await sleep(1000) |
| 16 | + const req = new Request("http://localhost:8123"); |
| 17 | + req.headers.set("accept-language", "en-US,en;q=0.9,ja;q=0.8"); |
| 18 | + const res = await fetch(req); |
| 19 | + await sleep(1000); |
20 | 20 |
|
21 | | - console.log(child.pid) |
| 21 | + console.log(child.pid); |
22 | 22 |
|
23 | 23 | const cleanup = () => { |
24 | | - process.kill(child.pid) |
25 | | - } |
| 24 | + process.kill(child.pid); |
| 25 | + }; |
26 | 26 |
|
27 | | - process.on('SIGINT', cleanup) |
28 | | - process.on('SIGTERM', cleanup) |
29 | | - process.on('SIGQUIT', cleanup) |
| 27 | + process.on("SIGINT", cleanup); |
| 28 | + process.on("SIGTERM", cleanup); |
| 29 | + process.on("SIGQUIT", cleanup); |
30 | 30 |
|
31 | | - assert.deepEqual('detect accpect-language: en-US,en,ja', await res.text()) |
32 | | -}) |
| 31 | + assert.deepEqual("detect accpect-language: en-US,en,ja", await res.text()); |
| 32 | +}); |
0 commit comments