Skip to content

Commit

Permalink
test: remove jest and use egg-bin(mocha) (#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed Jul 30, 2019
1 parent 219bf22 commit 2c86b10
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 47 deletions.
20 changes: 5 additions & 15 deletions package.json
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -53,24 +55,12 @@
"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": {
"node": "^4.8.4 || ^6.10.1 || ^7.10.1 || >= 8.1.4"
},
"files": [
"lib"
],
"jest": {
"testMatch": [
"**/test/!(helpers)/*.js"
],
"coverageReporters": [
"text-summary",
"lcov"
],
"bail": true,
"testEnvironment": "node"
}
]
}
35 changes: 19 additions & 16 deletions test/application/onerror.js
Expand Up @@ -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();
Expand All @@ -27,19 +22,21 @@ 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', () => {
const app = new Koa();
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', () => {
Expand All @@ -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', () => {
Expand All @@ -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');
});
});
8 changes: 0 additions & 8 deletions test/application/respond.js
Expand Up @@ -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();
Expand Down
8 changes: 0 additions & 8 deletions test/context/onerror.js
Expand Up @@ -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();

Expand Down

0 comments on commit 2c86b10

Please sign in to comment.