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", "description": "Koa web app framework",
"main": "lib/application.js", "main": "lib/application.js",
"scripts": { "scripts": {
"test": "jest", "test": "egg-bin test test",
"test-cov": "jest --coverage --runInBand --forceExit", "test-cov": "egg-bin cov test",
"lint": "eslint benchmarks lib test", "lint": "eslint benchmarks lib test",
"bench": "make -C benchmarks", "bench": "make -C benchmarks",
"authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS" "authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS"
@ -31,6 +31,7 @@
"delegates": "^1.0.0", "delegates": "^1.0.0",
"depd": "^1.1.2", "depd": "^1.1.2",
"destroy": "^1.0.4", "destroy": "^1.0.4",
"egg-bin": "^4.13.0",
"error-inject": "^1.0.0", "error-inject": "^1.0.0",
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
"fresh": "~0.5.2", "fresh": "~0.5.2",
@ -40,6 +41,7 @@
"koa-compose": "^4.1.0", "koa-compose": "^4.1.0",
"koa-convert": "^1.2.0", "koa-convert": "^1.2.0",
"koa-is-json": "^1.0.0", "koa-is-json": "^1.0.0",
"mm": "^2.5.0",
"on-finished": "^2.3.0", "on-finished": "^2.3.0",
"only": "~0.0.2", "only": "~0.0.2",
"parseurl": "^1.3.2", "parseurl": "^1.3.2",
@ -53,7 +55,6 @@
"eslint-config-standard": "^7.0.1", "eslint-config-standard": "^7.0.1",
"eslint-plugin-promise": "^3.5.0", "eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^2.1.1", "eslint-plugin-standard": "^2.1.1",
"jest": "^20.0.0",
"supertest": "^3.1.0" "supertest": "^3.1.0"
}, },
"engines": { "engines": {
@ -61,16 +62,5 @@
}, },
"files": [ "files": [
"lib" "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 assert = require('assert');
const Koa = require('../..'); const Koa = require('../..');
const mm = require('mm');
describe('app.onerror(err)', () => { describe('app.onerror(err)', () => {
beforeEach(() => { afterEach(mm.restore);
global.console = jest.genMockFromModule('console');
});
afterEach(() => {
global.console = require('console');
});
it('should throw an error if a non-error is given', () => { it('should throw an error if a non-error is given', () => {
const app = new Koa(); const app = new Koa();
@ -27,9 +22,10 @@ describe('app.onerror(err)', () => {
err.status = 404; err.status = 404;
let called = false;
mm(console, 'error', () => { called = true; });
app.onerror(err); app.onerror(err);
assert(!called);
assert.deepEqual(console.error.mock.calls, []);
}); });
it('should do nothing if .silent', () => { it('should do nothing if .silent', () => {
@ -37,9 +33,10 @@ describe('app.onerror(err)', () => {
app.silent = true; app.silent = true;
const err = new Error(); const err = new Error();
let called = false;
mm(console, 'error', () => { called = true; });
app.onerror(err); app.onerror(err);
assert(!called);
assert.deepEqual(console.error.mock.calls, []);
}); });
it('should log the error to stderr', () => { it('should log the error to stderr', () => {
@ -49,10 +46,12 @@ describe('app.onerror(err)', () => {
const err = new Error(); const err = new Error();
err.stack = 'Foo'; err.stack = 'Foo';
let msg = '';
mm(console, 'error', input => {
if (input) msg = input;
});
app.onerror(err); app.onerror(err);
assert(msg === ' Foo');
const stderr = console.error.mock.calls.join('\n');
assert.deepEqual(stderr, '\n Foo\n');
}); });
it('should use err.toString() instad of err.stack', () => { it('should use err.toString() instad of err.stack', () => {
@ -64,7 +63,11 @@ describe('app.onerror(err)', () => {
app.onerror(err); app.onerror(err);
const stderr = console.error.mock.calls.join('\n'); let msg = '';
assert.equal(stderr, '\n Error: mock stack null\n'); 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'); const fs = require('fs');
describe('app.respond', () => { describe('app.respond', () => {
beforeEach(() => {
global.console = jest.genMockFromModule('console');
});
afterEach(() => {
global.console = require('console');
});
describe('when ctx.respond === false', () => { describe('when ctx.respond === false', () => {
it('should function (ctx)', () => { it('should function (ctx)', () => {
const app = new Koa(); const app = new Koa();

View file

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