Skip to content

Commit 7b5a858

Browse files
committed
Add Tests workflow and replace Jest with node:test
- Remove `jest` - Update minimum Node.js version to 20 - Update `README.md` with NPM and Tests badges, and updated test instructions
1 parent 5f8774e commit 7b5a858

19 files changed

+140
-1783
lines changed

.github/workflows/tests.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
unit:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
node: ['20', '22', '24']
11+
name: Node ${{ matrix.node }}
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
persist-credentials: false
18+
19+
- name: Setup Node.js version
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node }}
23+
24+
- name: Install dependencies
25+
run: yarn install --frozen-lockfile
26+
27+
- name: Run lint
28+
run: yarn lint
29+
30+
- name: Run tests
31+
run: yarn test:coverage

.travis.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
This module provides a set of errors based on [standard-http-error](https://www.npmjs.com/package/standard-http-error), reducing the boilerplate of adding error classes for the most common HTTP errors.
44

5+
## Status
6+
7+
[![npm version][npm-image]][npm-url]
8+
[![build status][tests-image]][tests-url]
9+
510
## Setup
611

712
Install **@uphold/http-errors** with yarn:
@@ -113,16 +118,22 @@ try {
113118
Use the `test` script to run the test suite:
114119

115120
```sh
116-
$ yarn test
121+
yarn test
117122
```
118123

119-
To test and check coverage use the `cover` script:
124+
To run the tests on watch mode, use the `test:watch` script:
120125

121126
```sh
122-
$ yarn cover
127+
yarn test:watch
123128
```
124129

125-
A full coverage report will be generated on *test/coverage* folder.
130+
To test and check coverage use the `test:coverage` script:
131+
132+
```sh
133+
yarn test:coverage
134+
```
135+
136+
A full coverage report will be generated on `/coverage` folder.
126137

127138
## Contributing
128139

@@ -137,3 +148,8 @@ $ yarn release [<version> | major | minor | patch]
137148
## License
138149

139150
MIT
151+
152+
[npm-image]: https://img.shields.io/npm/v/@uphold/http-errors.svg
153+
[npm-url]: https://www.npmjs.com/package/@uphold/http-errors
154+
[tests-image]: https://github.com/uphold/uphold-http-errors/actions/workflows/tests.yaml/badge.svg?branch=master
155+
[tests-url]: https://github.com/uphold/uphold-http-errors/actions/workflows/tests.yaml

jest.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
"types": "types/index.d.ts",
99
"scripts": {
1010
"changelog": "github-changelog-generator --future-release=v$npm_package_version > CHANGELOG.md",
11-
"cover": "yarn test -- --coverage",
1211
"lint": "eslint --cache src test",
1312
"release": "npm version $1 -m 'Release %s'",
14-
"test": "jest --config jest.json",
13+
"test": "node --test test/**/*_test.js",
14+
"test:coverage": "NODE_V8_COVERAGE=coverage node --test --experimental-test-coverage test/**/*_test.js",
15+
"test:watch": "node --test --watch test/**/*_test.js",
1516
"version": "yarn changelog && git add CHANGELOG.md"
1617
},
1718
"pre-commit": [
@@ -25,10 +26,9 @@
2526
"@uphold/github-changelog-generator": "^0.7.0",
2627
"eslint": "^5.0.1",
2728
"eslint-config-uphold": "^0.1.1",
28-
"jest": "20.0.4",
2929
"pre-commit": "1.2.2"
3030
},
3131
"engines": {
32-
"node": ">=4"
32+
"node": ">=20"
3333
}
3434
}

test/errors/assertion-failed-error_test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
*/
66

77
const { AssertionFailedError } = require('../../src');
8-
const test = require('../utils/test-http-error');
8+
const { describe, it } = require('node:test');
9+
const testHttpError = require('../utils/test-http-error');
910

1011
/**
11-
* Test "Assertion Failed" error.
12+
* Test `Assertion Failed` error.
1213
*/
1314

1415
describe('AssertionFailedError', () => {
15-
test(AssertionFailedError, 500, 'Assertion Failed', false);
16+
testHttpError(AssertionFailedError, 500, 'Assertion Failed', false);
1617

17-
it('should set given `errors`', () => {
18-
expect(new AssertionFailedError('foo').errors).toBe('foo');
18+
it('should set given `errors`', ({ assert }) => {
19+
assert.equal(new AssertionFailedError('foo').errors, 'foo');
1920
});
2021
});

test/errors/bad-request-error_test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66

77
const { BadRequestError } = require('../../src');
8-
const test = require('../utils/test-http-error');
8+
const { describe } = require('node:test');
9+
const testHttpError = require('../utils/test-http-error');
910

1011
/**
11-
* Test "Bad Request" error.
12+
* Test `Bad Request` error.
1213
*/
1314

1415
describe('BadRequestError', () => {
15-
test(BadRequestError, 400, 'Bad Request');
16+
testHttpError(BadRequestError, 400, 'Bad Request');
1617
});

test/errors/conflict-error_test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66

77
const { ConflictError } = require('../../src');
8-
const test = require('../utils/test-http-error');
8+
const { describe } = require('node:test');
9+
const testHttpError = require('../utils/test-http-error');
910

1011
/**
11-
* Test "Conflict" error.
12+
* Test `Conflict` error.
1213
*/
1314

1415
describe('ConflictError', () => {
15-
test(ConflictError, 409, 'Conflict');
16+
testHttpError(ConflictError, 409, 'Conflict');
1617
});

test/errors/forbidden-error_test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66

77
const { ForbiddenError } = require('../../src');
8-
const test = require('../utils/test-http-error');
8+
const { describe } = require('node:test');
9+
const testHttpError = require('../utils/test-http-error');
910

1011
/**
11-
* Test "Forbidden" error.
12+
* Test `Forbidden` error.
1213
*/
1314

1415
describe('ForbiddenError', () => {
15-
test(ForbiddenError, 403, 'Forbidden');
16+
testHttpError(ForbiddenError, 403, 'Forbidden');
1617
});

test/errors/gone-error_test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66

77
const { GoneError } = require('../../src');
8-
const test = require('../utils/test-http-error');
8+
const { describe } = require('node:test');
9+
const testHttpError = require('../utils/test-http-error');
910

1011
/**
11-
* Test "Gone" error.
12+
* Test `Gone` error.
1213
*/
1314

1415
describe('GoneError', () => {
15-
test(GoneError, 410, 'Gone');
16+
testHttpError(GoneError, 410, 'Gone');
1617
});

0 commit comments

Comments
 (0)