-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13c7ca6
commit d394724
Showing
67 changed files
with
749 additions
and
856 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,71 @@ | ||
|
||
'use strict'; | ||
|
||
const stderr = require('test-console').stderr; | ||
const assert = require('assert'); | ||
const Koa = require('../..'); | ||
const AssertionError = require('assert').AssertionError; | ||
|
||
describe('app.onerror(err)', () => { | ||
it('should throw an error if a non-error is given', done => { | ||
const app = new Koa(); | ||
beforeEach(() => { | ||
global.console = jest.genMockFromModule('console'); | ||
}); | ||
|
||
(() => app.onerror('foo')).should.throw(AssertionError, {message: 'non-error thrown: foo'}); | ||
afterEach(() => { | ||
global.console = require('console'); | ||
}); | ||
|
||
it('should throw an error if a non-error is given', () => { | ||
const app = new Koa(); | ||
|
||
done(); | ||
assert.throws(() => { | ||
app.onerror('foo'); | ||
}, AssertionError, 'non-error thrown: foo'); | ||
}); | ||
|
||
it('should do nothing if status is 404', done => { | ||
it('should do nothing if status is 404', () => { | ||
const app = new Koa(); | ||
const err = new Error(); | ||
|
||
err.status = 404; | ||
|
||
const output = stderr.inspectSync(() => app.onerror(err)); | ||
app.onerror(err); | ||
|
||
output.should.eql([]); | ||
|
||
done(); | ||
assert.deepEqual(console.error.mock.calls, []); | ||
}); | ||
|
||
it('should do nothing if .silent', done => { | ||
it('should do nothing if .silent', () => { | ||
const app = new Koa(); | ||
app.silent = true; | ||
const err = new Error(); | ||
|
||
const output = stderr.inspectSync(() => app.onerror(err)); | ||
|
||
output.should.eql([]); | ||
app.onerror(err); | ||
|
||
done(); | ||
assert.deepEqual(console.error.mock.calls, []); | ||
}); | ||
|
||
it('should log the error to stderr', done => { | ||
it('should log the error to stderr', () => { | ||
const app = new Koa(); | ||
app.env = 'dev'; | ||
|
||
const err = new Error(); | ||
err.stack = 'Foo'; | ||
|
||
const output = stderr.inspectSync(() => app.onerror(err)); | ||
app.onerror(err); | ||
|
||
output.should.eql(['\n', ' Foo\n', '\n']); | ||
|
||
done(); | ||
const stderr = console.error.mock.calls.join('\n'); | ||
assert.deepEqual(stderr, '\n Foo\n'); | ||
}); | ||
|
||
it('should use err.toString() instad of err.stack', done => { | ||
it('should use err.toString() instad of err.stack', () => { | ||
const app = new Koa(); | ||
app.env = 'dev'; | ||
|
||
const err = new Error('mock stack null'); | ||
err.stack = null; | ||
|
||
const output = stderr.inspectSync(() => app.onerror(err)); | ||
|
||
output.should.eql(['\n', ' Error: mock stack null\n', '\n']); | ||
app.onerror(err); | ||
|
||
done(); | ||
const stderr = console.error.mock.calls.join('\n'); | ||
assert.equal(stderr, '\n Error: mock stack null\n'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.