Skip to content

Commit ef59889

Browse files
committed
use Jest instead of Karma, update to prettier-eslint-cli
1 parent dc75de8 commit ef59889

File tree

24 files changed

+266
-361
lines changed

24 files changed

+266
-361
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
webpack/*
2-
karma.conf.js
3-
tests.webpack.js

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,10 @@ After this modification to both loaders you will be able to use scss and less fi
241241
242242
#### Unit Tests
243243
244-
The project uses [Jest](https://facebook.github.io/jest/) and [Mocha](https://mochajs.org/) to run your unit tests, it uses [Karma](http://karma-runner.github.io/0.13/index.html) as the test runner, it enables the feature that you are able to render your tests to the browser (e.g: Firefox, Chrome etc.), which means you are able to use the [Test Utilities](http://facebook.github.io/react/docs/test-utils.html) from Facebook api like `renderIntoDocument()`.
244+
The project uses [Jest](https://facebook.github.io/jest/) with [Mocha](https://mochajs.org/) to run your unit tests.
245245
246246
To run the tests in the project, just simply run `npm test` if you have `Chrome` installed, it will be automatically launched as a test service for you.
247247
248-
To keep watching your test suites that you are working on, just set `singleRun: false` in the `karma.conf.js` file. Please be sure set it to `true` if you are running `npm test` on a continuous integration server (travis-ci, etc).
249-
250248
## Deployment on Heroku
251249
252250
To get this project to work on Heroku, you need to:

api/__tests__/api-test.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ describe('mapUrl', () => {
1111

1212
it('extracts nothing if the url is empty', () => {
1313
const url = '';
14-
const splittedUrlPath = url.split('?')[0].split('/').slice(1);
14+
const splittedUrlPath = url
15+
.split('?')[0]
16+
.split('/')
17+
.slice(1);
1518
const availableActions = { a: 1, widget: { c: 1, load: () => 'baz' } };
1619

1720
expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({
@@ -22,7 +25,10 @@ describe('mapUrl', () => {
2225

2326
it('extracts nothing if nothing was found', () => {
2427
const url = '/widget/load/?foo=bar';
25-
const splittedUrlPath = url.split('?')[0].split('/').slice(1);
28+
const splittedUrlPath = url
29+
.split('?')[0]
30+
.split('/')
31+
.slice(1);
2632
const availableActions = { a: 1, info: { c: 1, load: () => 'baz' } };
2733

2834
expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({
@@ -33,7 +39,10 @@ describe('mapUrl', () => {
3339

3440
it('extracts the available actions and the params from an relative url string with GET params', () => {
3541
const url = '/widget/load/param1/xzy?foo=bar';
36-
const splittedUrlPath = url.split('?')[0].split('/').slice(1);
42+
const splittedUrlPath = url
43+
.split('?')[0]
44+
.split('/')
45+
.slice(1);
3746
const availableActions = { a: 1, widget: { c: 1, load: () => 'baz' } };
3847

3948
expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({
@@ -44,7 +53,10 @@ describe('mapUrl', () => {
4453

4554
it('extracts the available actions from an url string without GET params', () => {
4655
const url = '/widget/load/?foo=bar';
47-
const splittedUrlPath = url.split('?')[0].split('/').slice(1);
56+
const splittedUrlPath = url
57+
.split('?')[0]
58+
.split('/')
59+
.slice(1);
4860
const availableActions = { a: 1, widget: { c: 1, load: () => 'baz' } };
4961

5062
expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({
@@ -55,7 +67,10 @@ describe('mapUrl', () => {
5567

5668
it('does not find the avaialble action if deeper nesting is required', () => {
5769
const url = '/widget';
58-
const splittedUrlPath = url.split('?')[0].split('/').slice(1);
70+
const splittedUrlPath = url
71+
.split('?')[0]
72+
.split('/')
73+
.slice(1);
5974
const availableActions = { a: 1, widget: { c: 1, load: () => 'baz' } };
6075

6176
expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({

api/actions/__tests__/widget-update-test.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ describe('widget update', () => {
2424
});
2525

2626
it('does not accept green widgets', () => {
27-
sinon.stub(load, 'default').returns(
28-
new Promise(resolve => {
29-
resolve(widgets);
30-
})
31-
);
27+
sinon.stub(load, 'default').resolves(widgets);
3228
return update({ session: {}, body: { color: 'Green' } }).then(
3329
() => {},
3430
err => {
@@ -38,25 +34,17 @@ describe('widget update', () => {
3834
});
3935

4036
it('fails to load widgets', () => {
41-
sinon.stub(load, 'default').returns(
42-
new Promise((resolve, reject) => {
43-
reject('Widget fail to load.');
44-
})
45-
);
37+
sinon.stub(load, 'default').rejects(new Error('Widget fail to load.'));
4638
return update({ session: {}, body: { color: 'Blue' } }).then(
4739
() => {},
4840
err => {
49-
expect(err).to.equal('Widget fail to load.');
41+
expect(err.message).to.equal('Widget fail to load.');
5042
}
5143
);
5244
});
5345

5446
it('updates a widget', () => {
55-
sinon.stub(load, 'default').returns(
56-
new Promise(resolve => {
57-
resolve(widgets);
58-
})
59-
);
47+
sinon.stub(load, 'default').resolves(widgets);
6048
const widget = { id: 2, color: 'Blue' };
6149
return update({ session: {}, body: widget }).then(res => {
6250
expect(res).to.deep.equal(widget);

api/api.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ app
3636
.use(bodyParser.json());
3737

3838
const actionsHandler = (req, res, next) => {
39-
const splittedUrlPath = req.url.split('?')[0].split('/').slice(1);
39+
const splittedUrlPath = req.url
40+
.split('?')[0]
41+
.split('/')
42+
.slice(1);
4043
const { action, params } = mapUrl(actions, splittedUrlPath);
4144

4245
req.app = app;

api/hooks/validateHook.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { createAsyncValidator as validator } from 'utils/validation';
33

44
export default function validateHook(schema) {
55
return hook =>
6-
validator(schema, { hook })(hook.data).then(() => hook).catch(errorsValidation => {
7-
if (Object.keys(errorsValidation).length) {
8-
throw new errors.BadRequest('Validation failed', errorsValidation);
9-
}
10-
});
6+
validator(schema, { hook })(hook.data)
7+
.then(() => hook)
8+
.catch(errorsValidation => {
9+
if (Object.keys(errorsValidation).length) {
10+
throw new errors.BadRequest('Validation failed', errorsValidation);
11+
}
12+
});
1113
}

jest.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
moduleDirectories: [
3+
process.env.NODE_PATH,
4+
'node_modules'
5+
],
6+
moduleNameMapper: {
7+
'\\.(jpg|jpeg|png|gif|eot|otf|svg|ttf|woff|woff2)$': '<rootDir>/__mocks__/fileMock.js',
8+
'\\.(css|less|scss)$': 'identity-obj-proxy'
9+
},
10+
globals: {
11+
__CLIENT__: process.env.NODE_PATH === 'src',
12+
__SERVER__: process.env.NODE_PATH === 'api',
13+
__DEVELOPMENT__: true,
14+
__DEVTOOLS__: false, // <-------- DISABLE redux-devtools HERE
15+
__DLLS__: false
16+
}
17+
};

karma.conf.js

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

package.json

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,29 @@
2424
],
2525
"main": "bin/server.js",
2626
"scripts": {
27-
"precommit": "lint-staged",
28-
"precommit-prettier": "eslint --print-config .eslintrc.js | prettier-eslint --write",
2927
"start": "concurrently --kill-others \"npm run start-prod\" \"npm run start-prod-api\"",
30-
"start-prod": "better-npm-run start-prod",
31-
"start-prod-api": "better-npm-run start-prod-api",
28+
"start-prod": "bnr start-prod",
29+
"start-prod-api": "bnr start-prod-api",
3230
"dev": "concurrently --kill-others \"npm run watch-client\" \"npm run start-dev\" \"npm run start-dev-api\"",
33-
"start-dev": "better-npm-run start-dev",
34-
"start-dev-api": "better-npm-run start-dev-api",
35-
"watch-client": "better-npm-run watch-client",
36-
"build": "better-npm-run build",
31+
"start-dev": "bnr start-dev",
32+
"start-dev-api": "bnr start-dev-api",
33+
"watch-client": "bnr watch-client",
34+
"build": "bnr build",
3735
"build-dlls": "webpack --colors --display-error-details --config webpack/vendor.config.js",
3836
"postinstall": "concurrently \"npm run build\" \"npm run build-dlls\"",
39-
"prettier": "npm run precommit-prettier -- \"./+(src|api)/**/*.js\"",
37+
"precommit": "lint-staged",
38+
"prettier": "prettier-eslint --write --eslint-config-path .eslintrc './+(src|api)/**/*.js'",
4039
"lint": "eslint -c .eslintrc api src",
41-
"test": "karma start",
42-
"test-node": "jest $(find api -name '*-test.js')",
43-
"test-node-watch": "jest $(find api -name '*-test.js') --watch",
40+
"test": "bnr test",
41+
"test-node": "bnr test-node",
42+
"lighthouse-report": "lighthouse http://localhost:8080 --view",
4443
"docker-build": ". ./docker/build.sh",
4544
"docker-dev": ". ./docker/run.dev.sh",
46-
"docker-prod": ". ./docker/run.prod.sh",
47-
"lighthouse-report": "LIGHTHOUSE_CHROMIUM_PATH=$(which google-chrome) lighthouse http://localhost:8080"
45+
"docker-prod": ". ./docker/run.prod.sh"
4846
},
4947
"lint-staged": {
5048
"+(src|api)/**/*.js": [
51-
"npm run precommit-prettier",
49+
"prettier-eslint --write --eslint-config-path .eslintrc",
5250
"eslint -c .eslintrc",
5351
"git add"
5452
]
@@ -105,6 +103,18 @@
105103
"env": {
106104
"NODE_ENV": "production"
107105
}
106+
},
107+
"test": {
108+
"command": "jest src",
109+
"env": {
110+
"NODE_PATH": "src"
111+
}
112+
},
113+
"test-node": {
114+
"command": "jest api",
115+
"env": {
116+
"NODE_PATH": "api"
117+
}
108118
}
109119
},
110120
"dependencies": {
@@ -172,7 +182,7 @@
172182
},
173183
"devDependencies": {
174184
"babel-eslint": "^7.1.1",
175-
"babel-jest": "^20.0.1",
185+
"babel-jest": "^21.0.2",
176186
"babel-loader": "^7.0.0",
177187
"better-npm-run": "^0.1.0",
178188
"bootstrap-loader": "^2.1.0",
@@ -181,6 +191,7 @@
181191
"clean-webpack-plugin": "^0.1.15",
182192
"concurrently": "^3.3.0",
183193
"css-loader": "^0.28.5",
194+
"enzyme": "^2.9.1",
184195
"eslint": "^4.4.1",
185196
"eslint-config-airbnb": "^15.1.0",
186197
"eslint-loader": "^1.6.1",
@@ -193,23 +204,15 @@
193204
"happypack": "^3.0.2",
194205
"html-webpack-plugin": "^2.30.1",
195206
"husky": "^0.14.3",
196-
"jest": "^20.0.1",
197-
"jest-cli": "^20.0.1",
198-
"karma": "^1.4.1",
199-
"karma-cli": "^1.0.1",
200-
"karma-mocha": "^1.3.0",
201-
"karma-mocha-reporter": "^2.2.2",
202-
"karma-phantomjs-launcher": "^1.0.2",
203-
"karma-sourcemap-loader": "^0.3.7",
204-
"karma-webpack": "^2.0.2",
207+
"identity-obj-proxy": "^3.0.0",
208+
"jest": "^21.1.0",
209+
"jest-cli": "^21.1.0",
205210
"less": "^2.7.2",
206211
"less-loader": "^4.0.3",
207212
"lighthouse": "^2.4.0",
208213
"lint-staged": "^4.0.3",
209214
"mocha": "^3.5.0",
210215
"node-sass": "^4.5.0",
211-
"phantomjs-polyfill": "^0.0.2",
212-
"phantomjs-prebuilt": "^2.1.15",
213216
"piping": "^1.0.0-rc.4",
214217
"postcss": "^6.0.9",
215218
"postcss-browser-reporter": "^0.5.0",
@@ -218,7 +221,7 @@
218221
"postcss-loader": "^2.0.5",
219222
"postcss-reporter": "^5.0.0",
220223
"postcss-url": "^7.1.2",
221-
"prettier-eslint": "^6.4.2",
224+
"prettier-eslint-cli": "^4.3.2",
222225
"react-a11y": "^0.3.3",
223226
"react-addons-test-utils": "^15.4.2",
224227
"react-hot-loader": "^3.0.0-beta.3",

src/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ const storage = __SERVER__ ? null : require('localforage');
1414
const host = clientUrl => (__SERVER__ ? `http://${config.apiHost}:${config.apiPort}` : clientUrl);
1515

1616
const configureApp = transport =>
17-
feathers().configure(transport).configure(hooks()).configure(authentication({ storage }));
17+
feathers()
18+
.configure(transport)
19+
.configure(hooks())
20+
.configure(authentication({ storage }));
1821

1922
export const socket = io('', { path: host('/ws'), autoConnect: false });
2023

0 commit comments

Comments
 (0)