Skip to content

Commit

Permalink
Merge branch 'master' into update-http-errors-to-v1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
3imed-jaberi committed Apr 2, 2022
2 parents a87d564 + f3c67d9 commit a33ddec
Show file tree
Hide file tree
Showing 158 changed files with 16,072 additions and 5,475 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends: koa
extends: standard
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 5
versioning-strategy: increase-if-necessary
27 changes: 27 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Node.js CI

on:
push:
branch: master
pull_request:
branch: master

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint
- run: npm test -- --coverage --maxWorkers 2
- run: npx codecov
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

34 changes: 34 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@

3.0.0 /
==================

## Breaking Changes

- Supports node@12+ only.
- Removes generator deprecation messages.
Generators are no longer supported.
Koa no longer asserts if generators are used.
- Set `content-length: 0` if body is explicitly set to `null` @ognjenjevremovic #1528

## Fixes

- fix: Do not response Content-Length if Transfer-Encoding is defined #1562 @charlyzeng
- fix: Set body to `null` if `ctx.type = json` and `ctx.body = null` #1059 @likegun

2.13.1 / 2021-01-04
==================

**fixes**
* [[`b5472f4`](http://github.com/koajs/koa/commit/b5472f4cbb87349becae36b4a9ad5f76a825abb8)] - fix: make ESM transpiled CommonJS play nice for TS folks, fix #1513 (#1518) (miwnwski <<m@iwnw.ski>>)
* [[`68d97d6`](http://github.com/koajs/koa/commit/68d97d69e4536065504bf9ef1e348a66b3f35709)] - fix: fixed order of vulnerability disclosure addresses (niftylettuce <<niftylettuce@gmail.com>>)

**others**
* [[`b4398f5`](http://github.com/koajs/koa/commit/b4398f5d68f9546167419f394a686afdcb5e10e2)] - correct verb tense in doc (#1512) (Matan Shavit <<71092861+matanshavit@users.noreply.github.com>>)
* [[`39e1a5a`](http://github.com/koajs/koa/commit/39e1a5a380aa2bbc4e2d164e8e4bf37cfd512516)] - fixed multiple grammatical errors in docs. (#1497) (Hridayesh Sharma <<vyasriday7@gmail.com>>)
* [[`aeb5d19`](http://github.com/koajs/koa/commit/aeb5d1984dcc5f8e3386f8f9724807ae6f3aa1c4)] - docs: added niftylettuce@gmail.com to vulnerability disclosure (niftylettuce <<niftylettuce@gmail.com>>)
* [[`6e1093b`](http://github.com/koajs/koa/commit/6e1093be27b41135c8e67fce108743d54e9cab67)] - docs: remove babel from readme (#1494) (miwnwski <<m@iwnw.ski>>)
* [[`38cb591`](http://github.com/koajs/koa/commit/38cb591254ff5f65a04e8fb57be293afe697c46e)] - docs: update specific for auto response status (AlbertAZ1992 <<ziyuximing@163.com>>)
* [[`2224cd9`](http://github.com/koajs/koa/commit/2224cd9b6a648e7ac2eb27eac332e7d6de7db26c)] - docs: remove babel ref. (#1488) (Imed Jaberi <<imed_jebari@hotmail.fr>>)
* [[`d51f983`](http://github.com/koajs/koa/commit/d51f98328c3b84493cc6bda0732aabb69e20e3a1)] - docs: fix assert example for response (#1489) (Imed Jaberi <<imed_jebari@hotmail.fr>>)
* [[`f8b49b8`](http://github.com/koajs/koa/commit/f8b49b859363ad6c3d9ea5c11ee62341407ceafd)] - chore: fix grammatical and spelling errors in comments and tests (#1490) (Matt Kubej <<mkubej@gmail.com>>)
* [[`d1c9263`](http://github.com/koajs/koa/commit/d1c92638c95d799df2fdff5576b96fc43a62813f)] - deps: update depd >> v2.0.0 (#1482) (imed jaberi <<imed_jebari@hotmail.fr>>)

2.13.0 / 2020-06-21
==================

Expand Down
39 changes: 2 additions & 37 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,40 +160,6 @@ Learn more about the application object in the [Application API Reference](docs/
- [FAQ](docs/faq.md)
- [API documentation](docs/api/index.md)

## Babel setup

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):

```bash
$ npm install @babel/register @babel/preset-env @babel/cli --save-dev
```

In development, you'll want to use [`@babel/register`](https://babeljs.io/docs/en/next/babel-register):

```bash
node --require @babel/register <your-entry-file>
```

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:

```bash
babel src --out-dir dist --copy-files
```

And have your `.babelrc` setup:

```json
{
"presets": [
["@babel/preset-env", {
"targets": {
"node": true
}
}]
]
}
```

## Troubleshooting

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

## Reporting vulnerabilities

To report a security vulnerability, please do not open an issue, as this notifies attackers
of the vulnerability. Instead, please email [dead_horse](mailto:heyiyu.deadhorse@gmail.com) and [jonathanong](mailto:me@jongleberry.com) to
disclose.
To report a security vulnerability, please do not open an issue, as this notifies attackers of the vulnerability. Instead, please email [dead_horse](mailto:heyiyu.deadhorse@gmail.com), [jonathanong](mailto:me@jongleberry.com), and [niftylettuce](mailto:niftylettuce@gmail.com) to disclose.

## Authors

See [AUTHORS](AUTHORS).

## Community

- [KoaJS Slack Grou](https://join.slack.com/t/koa-js/shared_invite/zt-5pjgthmb-1JeKDbByqqcARtlPbtf~vQ)
- [Badgeboard](https://koajs.github.io/badgeboard) and list of official modules
- [Examples](https://github.com/koajs/examples)
- [Middleware](https://github.com/koajs/koa/wiki) list
Expand Down
2 changes: 1 addition & 1 deletion test/.eslintrc.yml → __tests__/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
mocha: true
jest: true

rules:
space-before-blocks: [2, {functions: never, keywords: always}]
Expand Down
34 changes: 34 additions & 0 deletions __tests__/application/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

'use strict'

const request = require('supertest')
const assert = require('assert')
const Koa = require('../..')

describe('app.context', () => {
const app1 = new Koa()
app1.context.msg = 'hello'
const app2 = new Koa()

it('should merge properties', () => {
app1.use((ctx, next) => {
assert.strictEqual(ctx.msg, 'hello')
ctx.status = 204
})

return request(app1.listen())
.get('/')
.expect(204)
})

it('should not affect the original prototype', () => {
app2.use((ctx, next) => {
assert.strictEqual(ctx.msg, undefined)
ctx.status = 204
})

return request(app2.listen())
.get('/')
.expect(204)
})
})
88 changes: 88 additions & 0 deletions __tests__/application/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

'use strict'

const request = require('supertest')
const assert = require('assert')
const Koa = require('../..')

describe('app', () => {
it('should handle socket errors', done => {
const app = new Koa()

app.use((ctx, next) => {
// triggers ctx.socket.writable == false
ctx.socket.emit('error', new Error('boom'))
})

app.on('error', err => {
assert.strictEqual(err.message, 'boom')
done()
})

request(app.callback())
.get('/')
.end(() => {})
})

it('should not .writeHead when !socket.writable', done => {
const app = new Koa()

app.use((ctx, next) => {
// set .writable to false
ctx.socket.writable = false
ctx.status = 204
// throw if .writeHead or .end is called
ctx.res.writeHead =
ctx.res.end = () => {
throw new Error('response sent')
}
})

// hackish, but the response should occur in a single tick
setImmediate(done)

request(app.callback())
.get('/')
.end(() => {})
})

it('should set development env when NODE_ENV missing', () => {
const NODE_ENV = process.env.NODE_ENV
process.env.NODE_ENV = ''
const app = new Koa()
process.env.NODE_ENV = NODE_ENV
assert.strictEqual(app.env, 'development')
})

it('should set env from the constructor', () => {
const env = 'custom'
const app = new Koa({ env })
assert.strictEqual(app.env, env)
})

it('should set proxy flag from the constructor', () => {
const proxy = true
const app = new Koa({ proxy })
assert.strictEqual(app.proxy, proxy)
})

it('should set signed cookie keys from the constructor', () => {
const keys = ['customkey']
const app = new Koa({ keys })
assert.strictEqual(app.keys, keys)
})

it('should set subdomainOffset from the constructor', () => {
const subdomainOffset = 3
const app = new Koa({ subdomainOffset })
assert.strictEqual(app.subdomainOffset, subdomainOffset)
})

it('should have a static property exporting `HttpError` from http-errors library', () => {
const CreateError = require('http-errors')

assert.notEqual(Koa.HttpError, undefined)
assert.deepStrictEqual(Koa.HttpError, CreateError.HttpError)
assert.throws(() => { throw new CreateError(500, 'test error') }, Koa.HttpError)
})
})
21 changes: 21 additions & 0 deletions __tests__/application/inspect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

'use strict'

const assert = require('assert')
const util = require('util')
const Koa = require('../..')
const app = new Koa()

describe('app.inspect()', () => {
it('should work', () => {
const str = util.inspect(app)
assert.strictEqual("{ subdomainOffset: 2, proxy: false, env: 'test' }", str)
})

it('should return a json representation', () => {
assert.deepStrictEqual(
{ subdomainOffset: 2, proxy: false, env: 'test' },
app.inspect()
)
})
})
63 changes: 63 additions & 0 deletions __tests__/application/onerror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

'use strict'

const assert = require('assert')
const Koa = require('../..')

describe('app.onerror(err)', () => {
it('should throw an error if a non-error is given', () => {
const app = new Koa()

assert.throws(() => {
app.onerror('foo')
}, TypeError, 'non-error thrown: foo')
})

it('should accept errors coming from other scopes', () => {
const ExternError = require('vm').runInNewContext('Error')

const app = new Koa()
const error = Object.assign(new ExternError('boom'), {
status: 418,
expose: true
})

assert.doesNotThrow(() => app.onerror(error))
})

it('should do nothing if status is 404', () => {
const app = new Koa()
const err = new Error()

err.status = 404

const spy = jest.spyOn(console, 'error')
app.onerror(err)
expect(spy).not.toHaveBeenCalled()
spy.mockRestore()
})

it('should do nothing if .silent', () => {
const app = new Koa()
app.silent = true
const err = new Error()

const spy = jest.spyOn(console, 'error')
app.onerror(err)
expect(spy).not.toHaveBeenCalled()
spy.mockRestore()
})

it('should log the error to stderr', () => {
const app = new Koa()
app.env = 'dev'

const err = new Error()
err.stack = 'Foo'

const spy = jest.spyOn(console, 'error')
app.onerror(err)
expect(spy).toHaveBeenCalled()
spy.mockRestore()
})
})

0 comments on commit a33ddec

Please sign in to comment.