test: remove jest and use egg-bin(mocha) (#1363)

This commit is contained in:
Yiyu He 2019-07-30 18:00:43 +08:00 committed by GitHub
parent 219bf22237
commit 2c86b10fea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 47 deletions

View file

@ -4,8 +4,8 @@
"description": "Koa web app framework",
"main": "lib/application.js",
"scripts": {
"test": "jest",
"test-cov": "jest --coverage --runInBand --forceExit",
"test": "egg-bin test test",
"test-cov": "egg-bin cov test",
"lint": "eslint benchmarks lib test",
"bench": "make -C benchmarks",
"authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS"
@ -31,6 +31,7 @@
"delegates": "^1.0.0",
"depd": "^1.1.2",
"destroy": "^1.0.4",
"egg-bin": "^4.13.0",
"error-inject": "^1.0.0",
"escape-html": "^1.0.3",
"fresh": "~0.5.2",
@ -40,6 +41,7 @@
"koa-compose": "^4.1.0",
"koa-convert": "^1.2.0",
"koa-is-json": "^1.0.0",
"mm": "^2.5.0",
"on-finished": "^2.3.0",
"only": "~0.0.2",
"parseurl": "^1.3.2",
@ -53,7 +55,6 @@
"eslint-config-standard": "^7.0.1",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^2.1.1",
"jest": "^20.0.0",
"supertest": "^3.1.0"
},
"engines": {
@ -61,16 +62,5 @@
},
"files": [
"lib"
],
"jest": {
"testMatch": [
"**/test/!(helpers)/*.js"
],
"coverageReporters": [
"text-summary",
"lcov"
],
"bail": true,
"testEnvironment": "node"
}
]
}

View file

@ -3,15 +3,10 @@
const assert = require('assert');
const Koa = require('../..');
const mm = require('mm');
describe('app.onerror(err)', () => {
beforeEach(() => {
global.console = jest.genMockFromModule('console');
});
afterEach(() => {
global.console = require('console');
});
afterEach(mm.restore);
it('should throw an error if a non-error is given', () => {
const app = new Koa();
@ -27,9 +22,10 @@ describe('app.onerror(err)', () => {
err.status = 404;
let called = false;
mm(console, 'error', () => { called = true; });
app.onerror(err);
assert.deepEqual(console.error.mock.calls, []);
assert(!called);
});
it('should do nothing if .silent', () => {
@ -37,9 +33,10 @@ describe('app.onerror(err)', () => {
app.silent = true;
const err = new Error();
let called = false;
mm(console, 'error', () => { called = true; });
app.onerror(err);
assert.deepEqual(console.error.mock.calls, []);
assert(!called);
});
it('should log the error to stderr', () => {
@ -49,10 +46,12 @@ describe('app.onerror(err)', () => {
const err = new Error();
err.stack = 'Foo';
let msg = '';
mm(console, 'error', input => {
if (input) msg = input;
});
app.onerror(err);
const stderr = console.error.mock.calls.join('\n');
assert.deepEqual(stderr, '\n Foo\n');
assert(msg === ' Foo');
});
it('should use err.toString() instad of err.stack', () => {
@ -64,7 +63,11 @@ describe('app.onerror(err)', () => {
app.onerror(err);
const stderr = console.error.mock.calls.join('\n');
assert.equal(stderr, '\n Error: mock stack null\n');
let msg = '';
mm(console, 'error', input => {
if (input) msg = input;
});
app.onerror(err);
assert(msg === ' Error: mock stack null');
});
});

View file

@ -8,14 +8,6 @@ const Koa = require('../..');
const fs = require('fs');
describe('app.respond', () => {
beforeEach(() => {
global.console = jest.genMockFromModule('console');
});
afterEach(() => {
global.console = require('console');
});
describe('when ctx.respond === false', () => {
it('should function (ctx)', () => {
const app = new Koa();

View file

@ -7,14 +7,6 @@ const Koa = require('../..');
const context = require('../helpers/context');
describe('ctx.onerror(err)', () => {
beforeEach(() => {
global.console = jest.genMockFromModule('console');
});
afterEach(() => {
global.console = require('console');
});
it('should respond', () => {
const app = new Koa();