Skip to content

Commit 6b9cc53

Browse files
author
imed jaberi
committed
resolve conflicts
2 parents a87d564 + f3c67d9 commit 6b9cc53

File tree

158 files changed

+16073
-5477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+16073
-5477
lines changed

.eslintrc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
extends: koa
1+
extends: standard

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 5
8+
versioning-strategy: increase-if-necessary

.github/workflows/node.js.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
branch: master
6+
pull_request:
7+
branch: master
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [12.x, 14.x, 16.x]
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v1
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
- run: npm ci
25+
- run: npm run lint
26+
- run: npm test -- --coverage --maxWorkers 2
27+
- run: npx codecov

.npmrc

-1
This file was deleted.

.travis.yml

-21
This file was deleted.

History.md

+34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
11

2+
3.0.0 /
3+
==================
4+
5+
## Breaking Changes
6+
7+
- Supports node@12+ only.
8+
- Removes generator deprecation messages.
9+
Generators are no longer supported.
10+
Koa no longer asserts if generators are used.
11+
- Set `content-length: 0` if body is explicitly set to `null` @ognjenjevremovic #1528
12+
13+
## Fixes
14+
15+
- fix: Do not response Content-Length if Transfer-Encoding is defined #1562 @charlyzeng
16+
- fix: Set body to `null` if `ctx.type = json` and `ctx.body = null` #1059 @likegun
17+
18+
2.13.1 / 2021-01-04
19+
==================
20+
21+
**fixes**
22+
* [[`b5472f4`](http://github.com/koajs/koa/commit/b5472f4cbb87349becae36b4a9ad5f76a825abb8)] - fix: make ESM transpiled CommonJS play nice for TS folks, fix #1513 (#1518) (miwnwski <<[email protected]>>)
23+
* [[`68d97d6`](http://github.com/koajs/koa/commit/68d97d69e4536065504bf9ef1e348a66b3f35709)] - fix: fixed order of vulnerability disclosure addresses (niftylettuce <<[email protected]>>)
24+
25+
**others**
26+
* [[`b4398f5`](http://github.com/koajs/koa/commit/b4398f5d68f9546167419f394a686afdcb5e10e2)] - correct verb tense in doc (#1512) (Matan Shavit <<[email protected]>>)
27+
* [[`39e1a5a`](http://github.com/koajs/koa/commit/39e1a5a380aa2bbc4e2d164e8e4bf37cfd512516)] - fixed multiple grammatical errors in docs. (#1497) (Hridayesh Sharma <<[email protected]>>)
28+
* [[`aeb5d19`](http://github.com/koajs/koa/commit/aeb5d1984dcc5f8e3386f8f9724807ae6f3aa1c4)] - docs: added [email protected] to vulnerability disclosure (niftylettuce <<[email protected]>>)
29+
* [[`6e1093b`](http://github.com/koajs/koa/commit/6e1093be27b41135c8e67fce108743d54e9cab67)] - docs: remove babel from readme (#1494) (miwnwski <<[email protected]>>)
30+
* [[`38cb591`](http://github.com/koajs/koa/commit/38cb591254ff5f65a04e8fb57be293afe697c46e)] - docs: update specific for auto response status (AlbertAZ1992 <<[email protected]>>)
31+
* [[`2224cd9`](http://github.com/koajs/koa/commit/2224cd9b6a648e7ac2eb27eac332e7d6de7db26c)] - docs: remove babel ref. (#1488) (Imed Jaberi <<[email protected]>>)
32+
* [[`d51f983`](http://github.com/koajs/koa/commit/d51f98328c3b84493cc6bda0732aabb69e20e3a1)] - docs: fix assert example for response (#1489) (Imed Jaberi <<[email protected]>>)
33+
* [[`f8b49b8`](http://github.com/koajs/koa/commit/f8b49b859363ad6c3d9ea5c11ee62341407ceafd)] - chore: fix grammatical and spelling errors in comments and tests (#1490) (Matt Kubej <<[email protected]>>)
34+
* [[`d1c9263`](http://github.com/koajs/koa/commit/d1c92638c95d799df2fdff5576b96fc43a62813f)] - deps: update depd >> v2.0.0 (#1482) (imed jaberi <<[email protected]>>)
35+
236
2.13.0 / 2020-06-21
337
==================
438

Readme.md

+2-37
Original file line numberDiff line numberDiff line change
@@ -160,40 +160,6 @@ Learn more about the application object in the [Application API Reference](docs/
160160
- [FAQ](docs/faq.md)
161161
- [API documentation](docs/api/index.md)
162162

163-
## Babel setup
164-
165-
If you're not using `node v7.6+`, we recommend setting up `babel` with [`@babel/preset-env`](https://babeljs.io/docs/en/next/babel-preset-env):
166-
167-
```bash
168-
$ npm install @babel/register @babel/preset-env @babel/cli --save-dev
169-
```
170-
171-
In development, you'll want to use [`@babel/register`](https://babeljs.io/docs/en/next/babel-register):
172-
173-
```bash
174-
node --require @babel/register <your-entry-file>
175-
```
176-
177-
In production, you'll want to build your files with [`@babel/cli`](https://babeljs.io/docs/en/babel-cli). Suppose you are compiling a folder `src` and you wanted the output to go to a new folder `dist` with non-javascript files copied:
178-
179-
```bash
180-
babel src --out-dir dist --copy-files
181-
```
182-
183-
And have your `.babelrc` setup:
184-
185-
```json
186-
{
187-
"presets": [
188-
["@babel/preset-env", {
189-
"targets": {
190-
"node": true
191-
}
192-
}]
193-
]
194-
}
195-
```
196-
197163
## Troubleshooting
198164

199165
Check the [Troubleshooting Guide](docs/troubleshooting.md) or [Debugging Koa](docs/guide.md#debugging-koa) in
@@ -207,16 +173,15 @@ $ npm test
207173

208174
## Reporting vulnerabilities
209175

210-
To report a security vulnerability, please do not open an issue, as this notifies attackers
211-
of the vulnerability. Instead, please email [dead_horse](mailto:[email protected]) and [jonathanong](mailto:[email protected]) to
212-
disclose.
176+
To report a security vulnerability, please do not open an issue, as this notifies attackers of the vulnerability. Instead, please email [dead_horse](mailto:[email protected]), [jonathanong](mailto:[email protected]), and [niftylettuce](mailto:[email protected]) to disclose.
213177

214178
## Authors
215179

216180
See [AUTHORS](AUTHORS).
217181

218182
## Community
219183

184+
- [KoaJS Slack Grou](https://join.slack.com/t/koa-js/shared_invite/zt-5pjgthmb-1JeKDbByqqcARtlPbtf~vQ)
220185
- [Badgeboard](https://koajs.github.io/badgeboard) and list of official modules
221186
- [Examples](https://github.com/koajs/examples)
222187
- [Middleware](https://github.com/koajs/koa/wiki) list

test/.eslintrc.yml renamed to __tests__/.eslintrc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
env:
2-
mocha: true
2+
jest: true
33

44
rules:
55
space-before-blocks: [2, {functions: never, keywords: always}]

__tests__/application/context.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
'use strict'
3+
4+
const request = require('supertest')
5+
const assert = require('assert')
6+
const Koa = require('../..')
7+
8+
describe('app.context', () => {
9+
const app1 = new Koa()
10+
app1.context.msg = 'hello'
11+
const app2 = new Koa()
12+
13+
it('should merge properties', () => {
14+
app1.use((ctx, next) => {
15+
assert.strictEqual(ctx.msg, 'hello')
16+
ctx.status = 204
17+
})
18+
19+
return request(app1.listen())
20+
.get('/')
21+
.expect(204)
22+
})
23+
24+
it('should not affect the original prototype', () => {
25+
app2.use((ctx, next) => {
26+
assert.strictEqual(ctx.msg, undefined)
27+
ctx.status = 204
28+
})
29+
30+
return request(app2.listen())
31+
.get('/')
32+
.expect(204)
33+
})
34+
})

__tests__/application/index.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
'use strict'
3+
4+
const request = require('supertest')
5+
const assert = require('assert')
6+
const Koa = require('../..')
7+
8+
describe('app', () => {
9+
it('should handle socket errors', done => {
10+
const app = new Koa()
11+
12+
app.use((ctx, next) => {
13+
// triggers ctx.socket.writable == false
14+
ctx.socket.emit('error', new Error('boom'))
15+
})
16+
17+
app.on('error', err => {
18+
assert.strictEqual(err.message, 'boom')
19+
done()
20+
})
21+
22+
request(app.callback())
23+
.get('/')
24+
.end(() => {})
25+
})
26+
27+
it('should not .writeHead when !socket.writable', done => {
28+
const app = new Koa()
29+
30+
app.use((ctx, next) => {
31+
// set .writable to false
32+
ctx.socket.writable = false
33+
ctx.status = 204
34+
// throw if .writeHead or .end is called
35+
ctx.res.writeHead =
36+
ctx.res.end = () => {
37+
throw new Error('response sent')
38+
}
39+
})
40+
41+
// hackish, but the response should occur in a single tick
42+
setImmediate(done)
43+
44+
request(app.callback())
45+
.get('/')
46+
.end(() => {})
47+
})
48+
49+
it('should set development env when NODE_ENV missing', () => {
50+
const NODE_ENV = process.env.NODE_ENV
51+
process.env.NODE_ENV = ''
52+
const app = new Koa()
53+
process.env.NODE_ENV = NODE_ENV
54+
assert.strictEqual(app.env, 'development')
55+
})
56+
57+
it('should set env from the constructor', () => {
58+
const env = 'custom'
59+
const app = new Koa({ env })
60+
assert.strictEqual(app.env, env)
61+
})
62+
63+
it('should set proxy flag from the constructor', () => {
64+
const proxy = true
65+
const app = new Koa({ proxy })
66+
assert.strictEqual(app.proxy, proxy)
67+
})
68+
69+
it('should set signed cookie keys from the constructor', () => {
70+
const keys = ['customkey']
71+
const app = new Koa({ keys })
72+
assert.strictEqual(app.keys, keys)
73+
})
74+
75+
it('should set subdomainOffset from the constructor', () => {
76+
const subdomainOffset = 3
77+
const app = new Koa({ subdomainOffset })
78+
assert.strictEqual(app.subdomainOffset, subdomainOffset)
79+
})
80+
81+
it('should have a static property exporting `HttpError` from http-errors library', () => {
82+
const CreateError = require('http-errors')
83+
84+
assert.notEqual(Koa.HttpError, undefined)
85+
assert.deepStrictEqual(Koa.HttpError, CreateError.HttpError)
86+
assert.throws(() => { throw new CreateError(500, 'test error') }, Koa.HttpError)
87+
})
88+
})

__tests__/application/inspect.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
'use strict'
3+
4+
const assert = require('assert')
5+
const util = require('util')
6+
const Koa = require('../..')
7+
const app = new Koa()
8+
9+
describe('app.inspect()', () => {
10+
it('should work', () => {
11+
const str = util.inspect(app)
12+
assert.strictEqual("{ subdomainOffset: 2, proxy: false, env: 'test' }", str)
13+
})
14+
15+
it('should return a json representation', () => {
16+
assert.deepStrictEqual(
17+
{ subdomainOffset: 2, proxy: false, env: 'test' },
18+
app.inspect()
19+
)
20+
})
21+
})

__tests__/application/onerror.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
'use strict'
3+
4+
const assert = require('assert')
5+
const Koa = require('../..')
6+
7+
describe('app.onerror(err)', () => {
8+
it('should throw an error if a non-error is given', () => {
9+
const app = new Koa()
10+
11+
assert.throws(() => {
12+
app.onerror('foo')
13+
}, TypeError, 'non-error thrown: foo')
14+
})
15+
16+
it('should accept errors coming from other scopes', () => {
17+
const ExternError = require('vm').runInNewContext('Error')
18+
19+
const app = new Koa()
20+
const error = Object.assign(new ExternError('boom'), {
21+
status: 418,
22+
expose: true
23+
})
24+
25+
assert.doesNotThrow(() => app.onerror(error))
26+
})
27+
28+
it('should do nothing if status is 404', () => {
29+
const app = new Koa()
30+
const err = new Error()
31+
32+
err.status = 404
33+
34+
const spy = jest.spyOn(console, 'error')
35+
app.onerror(err)
36+
expect(spy).not.toHaveBeenCalled()
37+
spy.mockRestore()
38+
})
39+
40+
it('should do nothing if .silent', () => {
41+
const app = new Koa()
42+
app.silent = true
43+
const err = new Error()
44+
45+
const spy = jest.spyOn(console, 'error')
46+
app.onerror(err)
47+
expect(spy).not.toHaveBeenCalled()
48+
spy.mockRestore()
49+
})
50+
51+
it('should log the error to stderr', () => {
52+
const app = new Koa()
53+
app.env = 'dev'
54+
55+
const err = new Error()
56+
err.stack = 'Foo'
57+
58+
const spy = jest.spyOn(console, 'error')
59+
app.onerror(err)
60+
expect(spy).toHaveBeenCalled()
61+
spy.mockRestore()
62+
})
63+
})

0 commit comments

Comments
 (0)