Skip to content

Commit 4545b59

Browse files
committed
test: switch tests to jest
1 parent 596cfd5 commit 4545b59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+9537
-10401
lines changed

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ jobs:
2323
node-version: ${{ matrix.node-version }}
2424
- run: npm ci
2525
- run: npm run lint
26-
- run: npm run test-cov
26+
- run: npm test -- --coverage --maxWorkers 2
2727
- run: npx codecov

test/.eslintrc.yml renamed to __tests__/.eslintrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
env:
2-
mocha: true
2+
jest: true
33

44
rules:
55
space-before-blocks: [2, {functions: never, keywords: always}]
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/application/onerror.js renamed to __tests__/application/onerror.js

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33

44
const assert = require('assert');
55
const Koa = require('../..');
6-
const mm = require('mm');
76

87
describe('app.onerror(err)', () => {
9-
afterEach(mm.restore);
10-
118
it('should throw an error if a non-error is given', () => {
129
const app = new Koa();
1310

@@ -34,21 +31,21 @@ describe('app.onerror(err)', () => {
3431

3532
err.status = 404;
3633

37-
let called = false;
38-
mm(console, 'error', () => { called = true; });
34+
const spy = jest.spyOn(console, 'error');
3935
app.onerror(err);
40-
assert(!called);
36+
expect(spy).not.toHaveBeenCalled();
37+
spy.mockRestore();
4138
});
4239

4340
it('should do nothing if .silent', () => {
4441
const app = new Koa();
4542
app.silent = true;
4643
const err = new Error();
4744

48-
let called = false;
49-
mm(console, 'error', () => { called = true; });
45+
const spy = jest.spyOn(console, 'error');
5046
app.onerror(err);
51-
assert(!called);
47+
expect(spy).not.toHaveBeenCalled();
48+
spy.mockRestore();
5249
});
5350

5451
it('should log the error to stderr', () => {
@@ -58,28 +55,9 @@ describe('app.onerror(err)', () => {
5855
const err = new Error();
5956
err.stack = 'Foo';
6057

61-
let msg = '';
62-
mm(console, 'error', input => {
63-
if (input) msg = input;
64-
});
65-
app.onerror(err);
66-
assert(msg === '\n Foo\n');
67-
});
68-
69-
it('should use err.toString() instead of err.stack', () => {
70-
const app = new Koa();
71-
app.env = 'dev';
72-
73-
const err = new Error('mock stack null');
74-
err.stack = null;
75-
76-
app.onerror(err);
77-
78-
let msg = '';
79-
mm(console, 'error', input => {
80-
if (input) msg = input;
81-
});
58+
const spy = jest.spyOn(console, 'error');
8259
app.onerror(err);
83-
assert(msg === '\n Error: mock stack null\n');
60+
expect(spy).toHaveBeenCalled();
61+
spy.mockRestore();
8462
});
8563
});
File renamed without changes.

test/application/respond.js renamed to __tests__/application/respond.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ describe('app.respond', () => {
189189
.head('/')
190190
.expect(200);
191191

192-
assert.strictEqual(res.header['content-length'], length);
192+
assert.strictEqual(~~res.header['content-length'], length);
193193
assert(!res.text);
194194
});
195195

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy