Skip to content

Commit 94f4883

Browse files
feat: setup jest for testing
1 parent 3603f18 commit 94f4883

7 files changed

+94
-29
lines changed

.eslintrc.json

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
{
2-
"extends": [
3-
"@abhijithvijayan/eslint-config/typescript",
4-
"@abhijithvijayan/eslint-config/node"
5-
],
6-
"parserOptions": {
7-
"project": "./tsconfig.json",
8-
"sourceType": "module"
9-
},
10-
"rules": {
11-
"no-console": "off",
12-
"consistent-return": "off",
13-
"node/no-unsupported-features/es-syntax": ["error", {
14-
"ignores": ["modules"]
15-
}]
16-
}
2+
"extends": [
3+
"@abhijithvijayan/eslint-config/typescript",
4+
"@abhijithvijayan/eslint-config/node"
5+
],
6+
"parserOptions": {
7+
"project": "./tsconfig.eslint.json",
8+
"sourceType": "module"
9+
},
10+
"env": {
11+
"jest": true
12+
},
13+
"rules": {
14+
"no-console": "off",
15+
"node/shebang": "off",
16+
"no-param-reassign": "warn",
17+
"@typescript-eslint/no-use-before-define": "warn",
18+
"@typescript-eslint/no-explicit-any": "warn",
19+
"node/no-unsupported-features/es-syntax": ["error", {
20+
"ignores": ["modules"]
21+
}]
22+
}
1723
}

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
access=public
12
package-lock=false

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
language: node_js
22
node_js:
3+
- '14'
34
- '12'
4-
- '10'
5+
- '10'
6+
cache: yarn
7+
script:
8+
- yarn lint
9+
- yarn test

jest.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/en/configuration.html
4+
*/
5+
6+
module.exports = {
7+
// All imported modules in your tests should be mocked automatically
8+
automock: false,
9+
10+
// Automatically clear mock calls and instances between every test
11+
clearMocks: true,
12+
13+
// The directory where Jest should output its coverage files
14+
coverageDirectory: 'coverage',
15+
16+
// Indicates which provider should be used to instrument code for coverage
17+
coverageProvider: 'v8',
18+
19+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
20+
modulePathIgnorePatterns: ['lib'],
21+
22+
// A preset that is used as a base for Jest's configuration
23+
preset: 'ts-jest',
24+
25+
// The test environment that will be used for testing
26+
testEnvironment: 'node',
27+
28+
// The glob patterns Jest uses to detect test files
29+
testMatch: ['**/tests/**/*.test.[jt]s?(x)'],
30+
};

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@
1212
"engines": {
1313
"node": ">=10.0.0"
1414
},
15-
"main": "lib/index.js",
16-
"types": "lib",
15+
"main": "lib/cjs/index.js",
16+
"module": "lib/esm/index.js",
17+
"types": "lib/cjs/index.d.ts",
1718
"files": [
1819
"lib"
1920
],
2021
"scripts": {
21-
"dev": "tsc --watch",
22-
"build": "rimraf lib && tsc",
22+
"watch": "tsc --module esnext --outDir lib/esm --watch",
23+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
24+
"build:esm": "tsc --module esnext --outDir lib/esm",
25+
"build": "rimraf lib && yarn build:cjs && yarn build:esm",
2326
"pack:list": "npm pack && tar -xvzf *.tgz && rm -rf package *.tgz",
24-
"prepublishOnly": "yarn build",
27+
"prepublishOnly": "yarn test && yarn build",
28+
"test": "jest",
29+
"test:watch": "jest --watch",
2530
"lint": "eslint . --ext .ts",
2631
"lint:fix": "eslint . --ext .ts --fix"
2732
},
@@ -46,6 +51,7 @@
4651
"@abhijithvijayan/tsconfig": "^1.3.0",
4752
"@babel/eslint-parser": "^7.12.17",
4853
"@types/loader-utils": "^2.0.1",
54+
"@types/jest": "^26.0.23",
4955
"@types/node": "^14.14.31",
5056
"@typescript-eslint/eslint-plugin": "^4.15.1",
5157
"@typescript-eslint/parser": "^4.15.1",
@@ -58,8 +64,10 @@
5864
"eslint-plugin-prettier": "^3.3.1",
5965
"eslint-plugin-react": "^7.22.0",
6066
"eslint-plugin-react-hooks": "^4.2.0",
67+
"jest": "^26.6.3",
6168
"prettier": "^2.2.1",
6269
"rimraf": "^3.0.2",
70+
"ts-jest": "^26.5.6",
6371
"typescript": "^4.1.5"
6472
}
6573
}

tsconfig.eslint.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": [
4+
"tests/**/*.test.ts"
5+
],
6+
"exclude": []
7+
}

tsconfig.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
{
2-
"extends": "@abhijithvijayan/tsconfig",
3-
"compilerOptions": {
4-
"outDir": "lib",
5-
"strict": false,
6-
"noImplicitAny": false
7-
},
8-
"include": [
9-
"source"
2+
"extends": "@abhijithvijayan/tsconfig",
3+
"compilerOptions": {
4+
"outDir": "lib",
5+
"lib": [
6+
"dom",
7+
"dom.iterable",
8+
"esnext"
109
]
10+
},
11+
"include": [
12+
"source",
13+
"tests",
14+
"jest.config.js"
15+
],
16+
"exclude": [
17+
"tests/**/*.test.ts"
18+
]
1119
}

0 commit comments

Comments
 (0)