Skip to content

Commit 44c7355

Browse files
authored
refactor: use Jest for tests and linting (#113)
1 parent 3e674c3 commit 44c7355

20 files changed

+47
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
.idea
3+
coverage/

.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
node_modules
22
.idea
3-
test
3+
__tests__
44
.npmignore
55
.travis.yml
66
.eslintrc.json
7+
docs
8+
coverage

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
language: node_js
2+
cache:
3+
directories:
4+
- "node_modules"
25
node_js:
36
- 4
47
- 6
58
- 8
69
script:
7-
- npm run test
8-
- npm run lint
10+
- npm run test -- --runInBand

CONTRIBUTING.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ After
7373
[cloning the repository](https://help.github.com/articles/cloning-a-repository/),
7474
run `npm install` to install dependencies.
7575

76-
Run `npm test` to run the test suite. Sometimes it can be helpful to run a
76+
Run `npm test` to run the test suite (powered by
77+
[Jest](https://facebook.github.io/jest/)). Sometimes it can be helpful to run a
7778
single test file and watch for changes, especially when working on a single
78-
rule. You can run `npx mocha path/to/test.js --watch` to achieve this.
79+
rule. You can run `npm test -- --watch` to achieve this.
7980

8081
Run `npm run lint` to lint the codebase. If there are any errors reported, try
8182
running `npm run lint -- --fix` first to see if ESLint can fix them for you.
83+
`npm test` will also lint the codebase thanks to
84+
[jest-runner-eslint](https://github.com/jest-community/jest-runner-eslint).
8285

8386
This codebase uses [Prettier](http://prettier.io/) for code formatting. Consider
8487
installing an [editor plugin](https://prettier.io/docs/en/editors.html) for the

__tests__/.eslintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"plugins": ["jest"],
3+
"extends": ["plugin:jest/recommended"],
4+
"env": {
5+
"jest/globals": true
6+
}
7+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

__tests__/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
test('can require index file', () => {
4+
expect(require('../index')).toBeInstanceOf(Object)
5+
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

package.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"repository": "[email protected]:xjamundx/eslint-plugin-promise.git",
1414
"scripts": {
1515
"precommit": "lint-staged",
16-
"test": "mocha test",
17-
"lint": "eslint index.js rules test --ignore-pattern '**/*.json'"
16+
"test": "jest",
17+
"lint": "eslint index.js rules __tests__ --ignore-pattern '**/*.json'"
1818
},
1919
"devDependencies": {
2020
"doctoc": "^1.3.0",
@@ -23,13 +23,15 @@
2323
"eslint-config-standard": "^11.0.0-beta.0",
2424
"eslint-plugin-eslint-plugin": "^1.4.0",
2525
"eslint-plugin-import": "^2.8.0",
26+
"eslint-plugin-jest": "^21.12.2",
2627
"eslint-plugin-node": "^6.0.0",
2728
"eslint-plugin-prettier": "^2.6.0",
2829
"eslint-plugin-promise": "./",
2930
"eslint-plugin-standard": "^3.0.1",
3031
"husky": "^0.14.3",
32+
"jest": "^22.4.2",
33+
"jest-runner-eslint": "^0.4.0",
3134
"lint-staged": "^6.1.0",
32-
"mocha": "^5.0.0",
3335
"prettier": "^1.10.2"
3436
},
3537
"engines": {
@@ -51,5 +53,22 @@
5153
"semi": false,
5254
"singleQuote": true,
5355
"proseWrap": "always"
56+
},
57+
"jest": {
58+
"projects": [
59+
{
60+
"displayName": "test",
61+
"testEnvironment": "node"
62+
},
63+
{
64+
"runner": "jest-runner-eslint",
65+
"displayName": "lint",
66+
"testMatch": [
67+
"<rootDir>/rules/**/*.js",
68+
"<rootDir>/__tests__/**/*.js",
69+
"<rootDir>/index.js"
70+
]
71+
}
72+
]
5473
}
5574
}

test/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)