Skip to content

Commit 13398a6

Browse files
committed
feat: bootstrap test with jest
1 parent 3a1a18c commit 13398a6

File tree

7 files changed

+8324
-4152
lines changed

7 files changed

+8324
-4152
lines changed

.babelrc

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
{
2+
"env": {
3+
"test": {
4+
"presets": [
5+
[
6+
"@babel/preset-env",
7+
{
8+
"targets": {
9+
"node": "current"
10+
}
11+
}
12+
]
13+
]
14+
}
15+
},
216
"presets": [
317
[
418
"@babel/preset-env",

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module.exports = {
1616
'plugin:prettier/recommended',
1717
'plugin:import/errors',
1818
'plugin:import/warnings',
19+
'plugin:jest/recommended',
20+
'plugin:jest/style',
1921
],
2022
rules: {
2123
'prettier/prettier': 'error',

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ build: ## Webpack build the project
1414
mkdir -p dist
1515
npm run build
1616

17+
test: ## Run whole tests
18+
npm run test
19+
20+
test-watch: ## Watch whole test suites
21+
npm run test:watch
22+
1723
lint: ## lint the code and check coding conventions
1824
echo "Running linter..."
1925
npm run lint

jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
roots: ['<rootDir>/src'],
3+
resetMocks: true,
4+
resetModules: true,
5+
};

package-lock.json

+8,280-4,152
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"scripts": {
1414
"start": "webpack-dev-server --config webpack.demo.js --colors --devtool cheap-module-inline-source-map --hot --inline --host=0.0.0.0",
1515
"build": "webpack",
16+
"test": "NODE_ENV=test jest",
17+
"test:watch": "NODE_ENV=test jest --watch",
1618
"lint": "eslint .",
1719
"format": "prettier --write --check \"**/*.+(js|json|md)\""
1820
},
@@ -40,14 +42,17 @@
4042
"@commitlint/cli": "^8.3.5",
4143
"@commitlint/config-conventional": "^8.3.4",
4244
"babel-eslint": "^10.0.3",
45+
"babel-jest": "^25.1.0",
4346
"babel-loader": "^8.0.6",
4447
"eslint": "^6.8.0",
4548
"eslint-config-prettier": "^6.9.0",
4649
"eslint-plugin-babel": "^5.3.0",
4750
"eslint-plugin-import": "^2.20.0",
51+
"eslint-plugin-jest": "^23.6.0",
4852
"eslint-plugin-prettier": "^3.1.2",
4953
"html-webpack-plugin": "^3.2.0",
5054
"husky": "^4.2.1",
55+
"jest": "^25.1.0",
5156
"lint-staged": "^10.0.3",
5257
"prettier": "^1.19.1",
5358
"webpack": "^4.41.5",

src/utils/wait.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import wait from './wait';
2+
3+
jest.useFakeTimers();
4+
5+
describe('wait', () => {
6+
it('should call setTimeout and wait x ms', () => {
7+
wait(1000);
8+
9+
expect(setTimeout).toHaveBeenCalledTimes(1);
10+
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 1000);
11+
});
12+
});

0 commit comments

Comments
 (0)