Skip to content

Commit ebc3e3e

Browse files
committed
refactor test coverage
1 parent 386c90a commit ebc3e3e

15 files changed

Lines changed: 2615 additions & 195 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

bench.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
import { run, bench, group } from "mitata"
2-
import httpNext from "./index"
3-
import httpPrevious from "0http-bun"
1+
import {run, bench, group} from 'mitata'
2+
import httpNext from './index'
3+
import httpPrevious from '0http-bun'
44

55
function setupRouter(router) {
66
router.use((req, next) => {
77
return next()
88
})
99

10-
router.get("/", () => {
10+
router.get('/', () => {
1111
return new Response()
1212
})
13-
router.get("/:id", async (req) => {
13+
router.get('/:id', async (req) => {
1414
return new Response(req.params.id)
1515
})
16-
router.get("/:id/error", () => {
17-
throw new Error("Error")
16+
router.get('/:id/error', () => {
17+
throw new Error('Error')
1818
})
1919
}
2020

21-
const { router } = httpNext()
21+
const {router} = httpNext()
2222
setupRouter(router)
2323

24-
const { router: routerPrevious } = httpPrevious()
24+
const {router: routerPrevious} = httpPrevious()
2525
setupRouter(routerPrevious)
2626

27-
group("Next Router", () => {
28-
bench("Parameter URL", () => {
29-
router.fetch(new Request(new URL("http://localhost/0")))
30-
}).gc("inner")
31-
bench("Not Found URL", () => {
32-
router.fetch(new Request(new URL("http://localhost/0/404")))
33-
}).gc("inner")
34-
bench("Error URL", () => {
35-
router.fetch(new Request(new URL("http://localhost/0/error")))
36-
}).gc("inner")
27+
group('Next Router', () => {
28+
bench('Parameter URL', () => {
29+
router.fetch(new Request(new URL('http://localhost/0')))
30+
}).gc('inner')
31+
bench('Not Found URL', () => {
32+
router.fetch(new Request(new URL('http://localhost/0/404')))
33+
}).gc('inner')
34+
bench('Error URL', () => {
35+
router.fetch(new Request(new URL('http://localhost/0/error')))
36+
}).gc('inner')
3737
})
3838

39-
group("Previous Router", () => {
40-
bench("Parameter URL", () => {
41-
routerPrevious.fetch(new Request(new URL("http://localhost/0")))
42-
}).gc("inner")
43-
bench("Not Found URL", () => {
44-
routerPrevious.fetch(new Request(new URL("http://localhost/0/404")))
45-
}).gc("inner")
46-
bench("Error URL", () => {
47-
routerPrevious.fetch(new Request(new URL("http://localhost/0/error")))
48-
}).gc("inner")
39+
group('Previous Router', () => {
40+
bench('Parameter URL', () => {
41+
routerPrevious.fetch(new Request(new URL('http://localhost/0')))
42+
}).gc('inner')
43+
bench('Not Found URL', () => {
44+
routerPrevious.fetch(new Request(new URL('http://localhost/0/404')))
45+
}).gc('inner')
46+
bench('Error URL', () => {
47+
routerPrevious.fetch(new Request(new URL('http://localhost/0/error')))
48+
}).gc('inner')
4949
})
5050

51-
await run({
51+
run({
5252
colors: true,
5353
})

common.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Pattern, Methods } from 'trouter'
1+
import {Pattern, Methods} from 'trouter'
22

33
export interface IRouterConfig {
44
defaultRoute?: RequestHandler
@@ -16,7 +16,7 @@ type ZeroRequest = Request & {
1616

1717
export type RequestHandler = (
1818
req: ZeroRequest,
19-
next: StepFunction
19+
next: StepFunction,
2020
) => Response | Promise<Response>
2121

2222
export interface IRouter {

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { IRouter, IRouterConfig } from './common'
1+
import {IRouter, IRouterConfig} from './common'
22

33
export default function zero(config?: IRouterConfig): {
44
router: IRouter
55
}
66

7-
export * from './common'
7+
export * from './common'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"lint": "prettier --check **/*.js",
8-
"test": "bun test",
8+
"test": "bun --coverage test",
99
"bench": "bun run bench.js",
1010
"format": "prettier --write **/*.js"
1111
},

test/config.test.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)