Skip to content

Commit

Permalink
Merge pull request #10 from lifeomic/customMatchers
Browse files Browse the repository at this point in the history
Exposing matchers at the top level
  • Loading branch information
David Tanner authored Jan 7, 2022
2 parents 770e7c1 + 008d287 commit 4e57e29
Show file tree
Hide file tree
Showing 11 changed files with 2,170 additions and 198 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"extends": [
"@lifeomic/standards/javascript"
"@lifeomic/standards"
],
"env": {
"node": true
"node": true,
"jest": true,
"jest/globals": true
}
}
39 changes: 32 additions & 7 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
name: PR Branch Build and Test
name: PR Build and Test

on: pull_request
on:
pull_request

jobs:
build:
test:
runs-on: ubuntu-latest
name: Node.JS ${{ matrix.node-version }}
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: yarn install
- name: Test
run: yarn test
preRelease:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- name: Lint
run: |
yarn
yarn lint
registry-url: https://registry.npmjs.org
- name: Install
run: yarn install --frozen-lockfile
- name: Version
env:
PRE_ID: pr-${{ github.event.number }}-${{ github.run_id }}
run: npm version prepatch --git-tag-version=false --preid="${PRE_ID}-$(date '+%s')"
- name: PrePublish
env:
NODE_AUTH_TOKEN: ${{secrets.LIFEOMIC_NPM_TOKEN}}
PR_TAG: pr-${{ github.event.number }}
run: npm publish --tag "${PR_TAG}"
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 14
- name: Lint
run: |
yarn
yarn lint
- name: Install
run: yarn install
- name: Test
run: yarn test
- name: Publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{secrets.LIFEOMIC_NPM_TOKEN}}
run: |
npx semantic-release
npx semantic-release
29 changes: 29 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Matchers } from 'expect/build/types';
import matchers from 'expect/build/matchers';

const invalidKeys = ['resolves', 'rejects', 'not'] as const;

export type InvalidKeys = typeof invalidKeys[number];
export type ValidKeys = keyof Omit<Matchers<any>, InvalidKeys>

type RootMatchers = {
[key in ValidKeys]: Matchers<any>[key];
}

const rootMatchers = {} as RootMatchers;

Object.keys(matchers)
.filter((name): name is ValidKeys => !invalidKeys.includes(name as InvalidKeys))
.forEach((name) => {
const matcher = matchers[name];
rootMatchers[name] = matcher.bind({});
});

expect.extend(rootMatchers);

declare global {
namespace jest {
interface Expect extends RootMatchers {}
interface InverseAsymmetricMatchers extends RootMatchers {}
}
}
19 changes: 19 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
preset: './jest-preset.js',
maxWorkers: 1,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
coveragePathIgnorePatterns: ['<rootDir>/test/', '/node_modules/'],
restoreMocks: true,
resetMocks: true,
testMatch: ['<rootDir>/test/**/*.test.ts'],
verbose: true,
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
};
28 changes: 20 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,40 @@
"name": "@lifeomic/jest-config",
"version": "0.0.0",
"main": "index.js",
"types": "index.d.ts",
"repository": {},
"author": "Development <development@lifeomic.com>",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"files": [
"jest-preset.js"
"jest-preset.js",
"index.*"
],
"scripts": {
"lint": "eslint . --ext .js -f codeframe"
"lint": "eslint . --ext .js -f codeframe --cache",
"postlint": "yarn tsc",
"pretest": "yarn lint",
"test": "jest",
"prepublishOnly": "yarn tsc -p tsconfig.build.json"
},
"devDependencies": {
"@lifeomic/eslint-config-standards": "^1.2.0",
"@lifeomic/eslint-config-standards": "^2.1.0",
"@lifeomic/typescript-config": "^1.0.2",
"@types/jest": "^27.4.0",
"conventional-changelog-conventionalcommits": "^4.6.0",
"eslint": "^7.32.0",
"semantic-release": "^17.4.4"
"expect": "^27.4.6",
"jest": "^27.4.7",
"jest-circus": "^27.4.6",
"semantic-release": "^17.4.4",
"ts-jest": "^27.1.2",
"typescript": "^4.5.4"
},
"peerDependencies": {
"@types/jest": ">=26",
"jest": ">=26",
"jest-circus": ">=26",
"ts-jest": ">=26"
"jest": ">=27",
"jest-circus": ">=27",
"ts-jest": ">=27"
}
}
11 changes: 11 additions & 0 deletions test/methods.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test('has exposed some desired methods', () => {
expect({
numberVal: .31,
otherNum: .3,
}).toEqual({
numberVal: expect.toBeCloseTo(0.3, 1),
otherNum: expect.not.toBeCloseTo(0.2),
});
expect(.31).toBeCloseTo(0.3, 1);
expect(.3).not.toBeCloseTo(0.2);
});
1 change: 1 addition & 0 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../index';
9 changes: 9 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false
},
"include": [
"./index.ts"
]
}
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@lifeomic/typescript-config",
"compilerOptions": {
"resolveJsonModule": true,
"module": "CommonJS",
"declaration": true,
"noEmit": true
},
"include": [
"./index.ts",
"test/**/*.ts"
]
}
Loading

0 comments on commit 4e57e29

Please sign in to comment.