Skip to content

Commit fa210e9

Browse files
committed
build: v1.0.30
1 parent 797cfc4 commit fa210e9

8 files changed

Lines changed: 536 additions & 245 deletions

File tree

apps/koa-esm/vite.config.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { builtinModules } from 'node:module'
2+
import { resolve } from 'node:path'
3+
import { defineConfig } from 'vite'
4+
5+
const external = new Set([
6+
...builtinModules,
7+
...builtinModules.map((module) => `node:${module}`),
8+
'axios',
9+
'got',
10+
'koa',
11+
'koa-router',
12+
'node-network-devtools'
13+
])
14+
15+
export default defineConfig({
16+
build: {
17+
emptyOutDir: true,
18+
lib: {
19+
entry: resolve(__dirname, 'src/index.js'),
20+
fileName: 'index',
21+
formats: ['es']
22+
},
23+
minify: false,
24+
outDir: 'dist',
25+
rollupOptions: {
26+
external: [...external]
27+
},
28+
sourcemap: true,
29+
target: 'node18'
30+
}
31+
})

apps/koa/vite.config.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { builtinModules } from 'node:module'
2+
import { resolve } from 'node:path'
3+
import { defineConfig } from 'vite'
4+
5+
const external = new Set([
6+
...builtinModules,
7+
...builtinModules.map((module) => `node:${module}`),
8+
'axios',
9+
'koa',
10+
'koa-router',
11+
'node-network-devtools',
12+
'ofetch',
13+
'undici',
14+
'ws'
15+
])
16+
17+
export default defineConfig({
18+
build: {
19+
emptyOutDir: true,
20+
lib: {
21+
entry: resolve(__dirname, 'src/index.ts'),
22+
fileName: 'index',
23+
formats: ['cjs']
24+
},
25+
minify: false,
26+
outDir: 'dist',
27+
rollupOptions: {
28+
external: [...external]
29+
},
30+
sourcemap: true,
31+
target: 'node18'
32+
}
33+
})

packages/network-debugger/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-network-devtools",
3-
"version": "1.0.29",
3+
"version": "1.0.30",
44
"description": "Inspecting Node.js's Network with Chrome DevTools",
55
"homepage": "https://grinzero.github.io/node-network-devtools/",
66
"main": "./dist/index.js",

packages/network-debugger/src/__tests__/property-tests.test.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Property-Based Tests', () => {
3434
test('无效 JSON 应该返回 fallback 值', () => {
3535
fc.assert(
3636
fc.property(
37-
fc.string().filter((s) => {
37+
fc.string().filter((s: string) => {
3838
try {
3939
JSON.parse(s)
4040
return false // 有效 JSON,过滤掉
@@ -81,7 +81,7 @@ describe('Property-Based Tests', () => {
8181
fc.assert(
8282
fc.property(
8383
fc.dictionary(
84-
fc.string({ minLength: 1 }).filter((s) => !s.includes('\0')),
84+
fc.string({ minLength: 1 }).filter((s: string) => !s.includes('\0')),
8585
fc.string().filter((s) => !s.includes('\0'))
8686
),
8787
(headers) => {
@@ -181,15 +181,19 @@ describe('Property-Based Tests', () => {
181181

182182
test('不同输入应该产生不同 hash(高概率)', () => {
183183
fc.assert(
184-
fc.property(fc.string({ minLength: 1 }), fc.string({ minLength: 1 }), (input1, input2) => {
185-
fc.pre(input1 !== input2) // 前置条件:输入不同
184+
fc.property(
185+
fc.string({ minLength: 1 }),
186+
fc.string({ minLength: 1 }),
187+
(input1: string, input2: string) => {
188+
fc.pre(input1 !== input2) // 前置条件:输入不同
186189

187-
const hash1 = generateHash(input1)
188-
const hash2 = generateHash(input2)
190+
const hash1 = generateHash(input1)
191+
const hash2 = generateHash(input2)
189192

190-
// 不同输入应该产生不同 hash(碰撞概率极低)
191-
expect(hash1).not.toBe(hash2)
192-
}),
193+
// 不同输入应该产生不同 hash(碰撞概率极低)
194+
expect(hash1).not.toBe(hash2)
195+
}
196+
),
193197
{ numRuns: 50 }
194198
)
195199
})
@@ -216,9 +220,9 @@ describe('Property-Based Tests', () => {
216220
test('header 查询应该大小写不敏感', () => {
217221
fc.assert(
218222
fc.property(
219-
fc.string({ minLength: 1 }).filter((s) => /^[a-zA-Z][a-zA-Z0-9-]*$/.test(s)),
223+
fc.string({ minLength: 1 }).filter((s: string) => /^[a-zA-Z][a-zA-Z0-9-]*$/.test(s)),
220224
fc.string(),
221-
(headerName, headerValue) => {
225+
(headerName: string, headerValue: string) => {
222226
const headers = { [headerName]: headerValue }
223227
const pipe = new RequestHeaderPipe(headers)
224228

@@ -240,13 +244,13 @@ describe('Property-Based Tests', () => {
240244
test('混合大小写的 header 名称应该正确处理', () => {
241245
fc.assert(
242246
fc.property(
243-
fc.string({ minLength: 1 }).filter((s) => /^[a-zA-Z][a-zA-Z0-9-]*$/.test(s)),
247+
fc.string({ minLength: 1 }).filter((s: string) => /^[a-zA-Z][a-zA-Z0-9-]*$/.test(s)),
244248
fc.string(),
245-
(headerName, headerValue) => {
249+
(headerName: string, headerValue: string) => {
246250
// 创建混合大小写的名称
247251
const mixedCase = headerName
248252
.split('')
249-
.map((c, i) => (i % 2 === 0 ? c.toUpperCase() : c.toLowerCase()))
253+
.map((c: string, i: number) => (i % 2 === 0 ? c.toUpperCase() : c.toLowerCase()))
250254
.join('')
251255

252256
const headers = { [headerName]: headerValue }
@@ -295,7 +299,7 @@ describe('Property-Based Tests', () => {
295299
describe('Property 15: requestId 唯一性', () => {
296300
test('生成的 requestId 应该唯一', () => {
297301
fc.assert(
298-
fc.property(fc.integer({ min: 10, max: 50 }), (count) => {
302+
fc.property(fc.integer({ min: 10, max: 50 }), (count: number) => {
299303
const requestIds = new Set<string>()
300304

301305
for (let i = 0; i < count; i++) {
@@ -314,11 +318,11 @@ describe('Property-Based Tests', () => {
314318
fc.assert(
315319
fc.property(
316320
fc.array(fc.nat({ max: 1000 }), { minLength: 2, maxLength: 10 }),
317-
(deltas) => {
321+
(deltas: number[]) => {
318322
let timestamp = Date.now()
319323
const timestamps: number[] = [timestamp]
320324

321-
deltas.forEach((delta) => {
325+
deltas.forEach((delta: number) => {
322326
timestamp += delta
323327
timestamps.push(timestamp)
324328
})
@@ -337,7 +341,7 @@ describe('Property-Based Tests', () => {
337341
describe('Property 18: CDP 响应格式', () => {
338342
test('响应 id 应该与请求 id 匹配', () => {
339343
fc.assert(
340-
fc.property(fc.integer({ min: 1, max: 10000 }), (requestId) => {
344+
fc.property(fc.integer({ min: 1, max: 10000 }), (requestId: number) => {
341345
const request = { id: requestId, method: 'Network.getResponseBody' }
342346
const response = { id: requestId, result: {} }
343347

@@ -353,7 +357,7 @@ describe('Property-Based Tests', () => {
353357
fc.integer({ min: 1, max: 10000 }),
354358
fc.integer({ min: -32700, max: -32600 }),
355359
fc.string(),
356-
(id, code, message) => {
360+
(id: number, code: number, message: string) => {
357361
const errorResponse = {
358362
id,
359363
error: { code, message }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "./tsconfig.json",
4+
"include": ["src/**/*.ts", "vite-env.d.ts"],
5+
"exclude": ["src/**/*.test.ts", "src/**/__tests__/**"]
6+
}

packages/network-debugger/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
"@/*": ["src/*"]
2525
}
2626
},
27-
"exclude": ["node_modules"]
27+
"exclude": ["node_modules", "__tests__/*", "*.test.ts"]
2828
}

packages/network-debugger/vite.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,9 @@ export default defineConfig(({ mode }) => ({
7676
}
7777
}
7878
},
79-
plugins: [dts()]
79+
plugins: [
80+
dts({
81+
tsconfigPath: resolve(__dirname, 'tsconfig.build.json')
82+
})
83+
]
8084
}))

0 commit comments

Comments
 (0)