Skip to content

Commit 9915a53

Browse files
authored
Add Jest configuration and tests (#5)
* Update README * Update lint-staged Fixes a bug wherein prettier fails to scan package.json b/c of the hardcoded `parser`. * Add Jest configuration and a simple snapshot test * Add CI step, CHANGELOG * Restore esbuild which was accidentally removed when doing some dependency cleanup
1 parent 35a9b85 commit 9915a53

File tree

16 files changed

+840
-2210
lines changed

16 files changed

+840
-2210
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Test
22
on:
33
push:
44
branches:
5-
- "*"
5+
- '*'
66

77
jobs:
88
lint:
@@ -16,6 +16,15 @@ jobs:
1616
- name: Formatting
1717
run: npm run fmt:check
1818

19+
test:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v2
24+
- uses: bahmutov/npm-install@v1
25+
- name: Test
26+
run: npm run test
27+
1928
build:
2029
runs-on: ubuntu-latest
2130
steps:

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run lint:staged

.lintstagedrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
'*.{js,ts}': ['eslint --cache --fix', 'prettier --write'],
3+
'*.{yml,md,json}': 'prettier --write',
4+
}

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock.json

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change Log
2+
3+
## [v0.0.5](https://github.com/pi-base/dev/compare/v0.0.4...v0.0.5)
4+
5+
- Add exported `jest` configuration
6+
- Add a basic `jest` snapshot test
7+
- Add CI step to testing workflow
8+
9+
## [v0.0.4](https://github.com/pi-base/dev/compare/v0.0.3...v0.0.4)
10+
11+
- Add initial `lint-staged` configuration
12+
13+
## [v0.0.3](https://github.com/pi-base/dev/compare/v0.0.2...v0.0.3)
14+
15+
- Add exported `eslint` configuration
16+
- Initial CD implementation

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,70 @@
66
[![Release](https://github.com/pi-base/dev/actions/workflows/release.yml/badge.svg)](https://github.com/pi-base/dev/actions/workflows/release.yml)
77
[![NPM](https://img.shields.io/npm/v/@pi-base/dev?color=blue)](https://www.npmjs.com/package/@pi-base/dev)
88

9+
Shared developer tools for π-Base packages.
10+
911
</div>
1012

11-
Shared developer tools for π-Base packages.
13+
# Usage
14+
15+
## Installation
16+
17+
```bash
18+
$ npm install --save-dev @pi-base/dev
19+
```
20+
21+
## Configuration
22+
23+
`@pi-base/dev` exports a number of common config files
24+
25+
```javascript
26+
// .eslintrc.js
27+
module.exports = require('@pi-base/dev').eslintConfig
28+
29+
// .lintstagedrc.js
30+
module.exports = require('@pi-base/dev').lintStagedConfig
31+
32+
// .prettierrc.js
33+
module.exports = require('@pi-base/dev').prettierConfig
34+
35+
// .tsconfig.json
36+
{
37+
"extends": "@pi-base/dev/tsconfig.shared.json",
38+
"include": ["src/**/*.ts"]
39+
}
40+
```
41+
42+
It also includes a CLI wrapping several common tasks, intended for use as `npm run` scripts
43+
44+
```javascript
45+
// package.json
46+
{
47+
"scripts": {
48+
"fmt": "pi-base-dev fmt",
49+
"fmt:check": "pi-base-dev fmt:check",
50+
"lint": "pi-base-dev lint",
51+
"lint:check": "pi-base-dev lint:check"
52+
}
53+
}
54+
```
55+
56+
or in a `.husky/pre-commit` hook
57+
58+
```bash
59+
# .husky/pre-commit
60+
pi-base-dev lint-staged
61+
```
62+
63+
# Development
64+
65+
## Installation
66+
67+
```bash
68+
$ npm install
69+
```
70+
71+
## Release
72+
73+
Releases to [NPM](https://www.npmjs.com/package/@pi-base/dev) are automatically triggered by creating a [Github release](https://github.com/pi-base/dev/releases) named `vX.X.X` (matching the current version in `package.json`).
74+
75+
Be sure to add a [`CHANGELOG`](./CHANGELOG.md) entry when updating the version.

jest.config.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
1-
module.exports = {
2-
bail: 10,
3-
clearMocks: true,
4-
coverageDirectory: 'coverage',
5-
coveragePathIgnorePatterns: ['/node_modules/'],
6-
coverageProvider: 'v8',
7-
errorOnDeprecated: true,
8-
moduleFileExtensions: ['js', 'ts'],
9-
notify: true,
10-
notifyMode: 'failure-change',
11-
resetMocks: true,
12-
roots: ['src'],
13-
testEnvironment: 'node',
14-
testMatch: ['**/*.test.ts'],
15-
testRunner: 'jest-circus/runner',
16-
transform: {
17-
'^.+\\.ts$': 'ts-jest',
18-
},
19-
verbose: true,
20-
}
1+
module.exports = require('./src/jest')

0 commit comments

Comments
 (0)