Skip to content

Commit

Permalink
Add Jest configuration and tests (#5)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jamesdabbs authored Mar 30, 2021
1 parent 35a9b85 commit 9915a53
Show file tree
Hide file tree
Showing 16 changed files with 840 additions and 2,210 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test
on:
push:
branches:
- "*"
- '*'

jobs:
lint:
Expand All @@ -16,6 +16,15 @@ jobs:
- name: Formatting
run: npm run fmt:check

test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: bahmutov/npm-install@v1
- name: Test
run: npm run test

build:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run lint:staged
4 changes: 4 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'*.{js,ts}': ['eslint --cache --fix', 'prettier --write'],
'*.{yml,md,json}': 'prettier --write',
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Change Log

## [v0.0.5](https://github.com/pi-base/dev/compare/v0.0.4...v0.0.5)

- Add exported `jest` configuration
- Add a basic `jest` snapshot test
- Add CI step to testing workflow

## [v0.0.4](https://github.com/pi-base/dev/compare/v0.0.3...v0.0.4)

- Add initial `lint-staged` configuration

## [v0.0.3](https://github.com/pi-base/dev/compare/v0.0.2...v0.0.3)

- Add exported `eslint` configuration
- Initial CD implementation
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,70 @@
[![Release](https://github.com/pi-base/dev/actions/workflows/release.yml/badge.svg)](https://github.com/pi-base/dev/actions/workflows/release.yml)
[![NPM](https://img.shields.io/npm/v/@pi-base/dev?color=blue)](https://www.npmjs.com/package/@pi-base/dev)

Shared developer tools for π-Base packages.

</div>

Shared developer tools for π-Base packages.
# Usage

## Installation

```bash
$ npm install --save-dev @pi-base/dev
```

## Configuration

`@pi-base/dev` exports a number of common config files

```javascript
// .eslintrc.js
module.exports = require('@pi-base/dev').eslintConfig

// .lintstagedrc.js
module.exports = require('@pi-base/dev').lintStagedConfig

// .prettierrc.js
module.exports = require('@pi-base/dev').prettierConfig

// .tsconfig.json
{
"extends": "@pi-base/dev/tsconfig.shared.json",
"include": ["src/**/*.ts"]
}
```

It also includes a CLI wrapping several common tasks, intended for use as `npm run` scripts

```javascript
// package.json
{
"scripts": {
"fmt": "pi-base-dev fmt",
"fmt:check": "pi-base-dev fmt:check",
"lint": "pi-base-dev lint",
"lint:check": "pi-base-dev lint:check"
}
}
```

or in a `.husky/pre-commit` hook

```bash
# .husky/pre-commit
pi-base-dev lint-staged
```

# Development

## Installation

```bash
$ npm install
```

## Release

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`).

Be sure to add a [`CHANGELOG`](./CHANGELOG.md) entry when updating the version.
21 changes: 1 addition & 20 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
module.exports = {
bail: 10,
clearMocks: true,
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['/node_modules/'],
coverageProvider: 'v8',
errorOnDeprecated: true,
moduleFileExtensions: ['js', 'ts'],
notify: true,
notifyMode: 'failure-change',
resetMocks: true,
roots: ['src'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest',
},
verbose: true,
}
module.exports = require('./src/jest')
Loading

0 comments on commit 9915a53

Please sign in to comment.