Skip to content

Commit 081d94e

Browse files
committed
style: apply consistent formatting across multiple files
1 parent c70831a commit 081d94e

File tree

6 files changed

+69
-45
lines changed

6 files changed

+69
-45
lines changed

demos/basic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* global Response */
22
const http = require('../index')
33

4-
const { router } = http({})
4+
const {router} = http({})
55
router.use((req, next) => {
66
req.ctx = {
7-
engine: 'bun'
7+
engine: 'bun',
88
}
99

1010
return next()
@@ -17,7 +17,7 @@ router.post('/', async (req) => {
1717
})
1818
router.delete('/:id', async (req) => {
1919
return Response.json(req.params, {
20-
status: 200
20+
status: 200,
2121
})
2222
})
2323

demos/minimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global Response */
22
const http = require('../index')
33

4-
const { router } = http({})
4+
const {router} = http({})
55

66
router.get('/hi', async (req) => {
77
return new Response('Hello World!')

lib/next.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
module.exports = function next (middlewares, req, index, defaultRoute, errorHandler) {
1+
module.exports = function next(
2+
middlewares,
3+
req,
4+
index,
5+
defaultRoute,
6+
errorHandler,
7+
) {
28
if (index >= middlewares.length) {
39
return defaultRoute(req)
410
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"description": "0http for Bun",
55
"main": "index.js",
66
"scripts": {
7-
"lint": "bun x standard",
7+
"lint": "prettier --check **/*.js",
88
"test": "bun test",
99
"bench": "bun run bench.js",
10-
"format": "prettier --write *.js"
10+
"format": "prettier --write **/*.js"
1111
},
1212
"dependencies": {
1313
"fast-querystring": "^1.1.2",

test/config.test.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/* global describe, it, expect, beforeAll */
22

33
const http = require('../index')
4-
const { router } = http({
4+
const {router} = http({
55
port: 3000,
66
defaultRoute: (req) => {
77
const res = new Response('Not Found!', {
8-
status: 404
8+
status: 404,
99
})
1010

1111
return res
1212
},
1313
errorHandler: (err) => {
1414
const res = new Response('Error: ' + err.message, {
15-
status: 500
15+
status: 500,
1616
})
1717

1818
return res
19-
}
19+
},
2020
})
2121

2222
describe('Router Configuration', () => {
@@ -27,17 +27,21 @@ describe('Router Configuration', () => {
2727
})
2828

2929
it('should return a 500 response for a route that throws an error', async () => {
30-
const response = await router.fetch(new Request('http://localhost:3000/error', {
31-
method: 'GET'
32-
}))
30+
const response = await router.fetch(
31+
new Request('http://localhost:3000/error', {
32+
method: 'GET',
33+
}),
34+
)
3335
expect(response.status).toBe(500)
3436
expect(await response.text()).toEqual('Error: Unexpected error')
3537
})
3638

3739
it('should return a 404 response for a route that does not exist', async () => {
38-
const response = await router.fetch(new Request('http://localhost:3000/does-not-exist', {
39-
method: 'GET'
40-
}))
40+
const response = await router.fetch(
41+
new Request('http://localhost:3000/does-not-exist', {
42+
method: 'GET',
43+
}),
44+
)
4145
expect(response.status).toBe(404)
4246
expect(await response.text()).toEqual('Not Found!')
4347
})

test/smoke.test.js

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* global describe, it, expect, beforeAll */
22

33
const http = require('../index')
4-
const { router } = http({ port: 3000 })
4+
const {router} = http({port: 3000})
55

66
describe('Router', () => {
77
beforeAll(async () => {
88
router.use((req, next) => {
99
req.ctx = {
10-
engine: 'bun'
10+
engine: 'bun',
1111
}
1212

1313
return next()
@@ -41,58 +41,72 @@ describe('Router', () => {
4141
})
4242

4343
it('should return a JSON response with the request parameters for GET requests', async () => {
44-
const response = await router.fetch(new Request('http://localhost:3000/get-params/123', {
45-
method: 'GET'
46-
}))
44+
const response = await router.fetch(
45+
new Request('http://localhost:3000/get-params/123', {
46+
method: 'GET',
47+
}),
48+
)
4749
expect(response.status).toBe(200)
48-
expect(await response.json()).toEqual({ id: '123' })
50+
expect(await response.json()).toEqual({id: '123'})
4951
})
5052

5153
it('should return a JSON response with the request parameters for DELETE requests', async () => {
52-
const response = await router.fetch(new Request('http://localhost:3000/get-params/123', {
53-
method: 'DELETE'
54-
}))
54+
const response = await router.fetch(
55+
new Request('http://localhost:3000/get-params/123', {
56+
method: 'DELETE',
57+
}),
58+
)
5559
expect(response.status).toBe(200)
5660
expect(await response.json()).toEqual('OK')
5761
})
5862

5963
it('should return a JSON response with the request body for POST requests', async () => {
60-
const response = await router.fetch(new Request('http://localhost:3000/create', {
61-
method: 'POST',
62-
body: JSON.stringify({ foo: 'bar' })
63-
}))
64+
const response = await router.fetch(
65+
new Request('http://localhost:3000/create', {
66+
method: 'POST',
67+
body: JSON.stringify({foo: 'bar'}),
68+
}),
69+
)
6470
expect(response.status).toBe(200)
65-
expect(await response.json()).toEqual({ foo: 'bar' })
71+
expect(await response.json()).toEqual({foo: 'bar'})
6672
})
6773

6874
it('should return a 404 response for a non-existent route', async () => {
69-
const response = await router.fetch(new Request('http://localhost:3000/non-existent', {
70-
method: 'GET'
71-
}))
75+
const response = await router.fetch(
76+
new Request('http://localhost:3000/non-existent', {
77+
method: 'GET',
78+
}),
79+
)
7280
expect(response.status).toBe(404)
7381
})
7482

7583
it('should return a 500 response for a route that throws an error', async () => {
76-
const response = await router.fetch(new Request('http://localhost:3000/error', {
77-
method: 'GET'
78-
}))
84+
const response = await router.fetch(
85+
new Request('http://localhost:3000/error', {
86+
method: 'GET',
87+
}),
88+
)
7989
expect(response.status).toBe(500)
8090
expect(await response.text()).toEqual('Unexpected error')
8191
})
8292

8393
it('should return a 200 response for a route that returns a Response object', async () => {
84-
const response = await router.fetch(new Request('http://localhost:3000/', {
85-
method: 'GET'
86-
}))
94+
const response = await router.fetch(
95+
new Request('http://localhost:3000/', {
96+
method: 'GET',
97+
}),
98+
)
8799
expect(response.status).toBe(200)
88-
expect(await response.json()).toEqual({ engine: 'bun' })
100+
expect(await response.json()).toEqual({engine: 'bun'})
89101
})
90102

91103
it('should return a JSON response with the query string parameters', async () => {
92-
const response = await router.fetch(new Request('http://localhost:3000/qs?foo=bar', {
93-
method: 'GET'
94-
}))
104+
const response = await router.fetch(
105+
new Request('http://localhost:3000/qs?foo=bar', {
106+
method: 'GET',
107+
}),
108+
)
95109
expect(response.status).toBe(200)
96-
expect(await response.json()).toEqual({ foo: 'bar' })
110+
expect(await response.json()).toEqual({foo: 'bar'})
97111
})
98112
})

0 commit comments

Comments
 (0)