Skip to content

Commit c8a1abd

Browse files
committed
Add Husky; Add git hook rule to lint on pre-commit and test on pre-push
1 parent 370387d commit c8a1abd

36 files changed

+199
-185
lines changed

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn lint

.husky/pre-push

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn test

config/babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = function (api) {
2727
presets: [
2828
[
2929
'@babel/preset-env',
30-
{targets: {node: 'current'}}
30+
{ targets: { node: 'current' } }
3131
],
3232
'@babel/preset-react'
3333
],

config/jest/beforeTestEnvSetup.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ global.navigator.geolocation = mockGeolocation
1313
window.Intl = {
1414
DateTimeFormat: jest.fn().mockImplementation(() => ({
1515
resolvedOptions: jest.fn().mockImplementation(() => ({
16-
timeZone: "Etc/GMT"
16+
timeZone: 'Etc/GMT'
1717
}))
1818
}))
1919
}
@@ -24,6 +24,6 @@ window.matchMedia = jest.fn().mockImplementation(query => {
2424
media: query,
2525
onchange: null,
2626
addListener: jest.fn(),
27-
removeListener: jest.fn(),
28-
};
29-
});
27+
removeListener: jest.fn()
28+
}
29+
})

config/webpack.config.dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
44
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
55
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin')
66
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin')
7-
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
7+
const MomentLocalesPlugin = require('moment-locales-webpack-plugin')
88
const getClientEnvironment = require('./env')
99
const paths = require('./paths')
1010
const sharedConfig = require('./webpack.config.shared')

config/webpack.config.prod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin')
55
const { WebpackManifestPlugin } = require('webpack-manifest-plugin')
66
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin')
77
const safePostCssParser = require('postcss-safe-parser')
8-
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
8+
const MomentLocalesPlugin = require('moment-locales-webpack-plugin')
99
const TerserPlugin = require('terser-webpack-plugin')
1010
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
1111
const paths = require('./paths')

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"lint:fix": "yarn exec standard --fix",
1313
"server": "./node_modules/.bin/babel-node --config-file ./config/babel.config.js scripts/serveUniversal.js",
1414
"storybook": "start-storybook -p 6006",
15-
"storybook:build": "build-storybook"
15+
"storybook:build": "build-storybook",
16+
"prepare": "husky install"
1617
},
1718
"dependencies": {
1819
"@babel/cli": "7.2.3",
@@ -217,7 +218,8 @@
217218
"xhr": "^2.5.0"
218219
},
219220
"devDependencies": {
220-
"standard": "12.0.1"
221+
"standard": "12.0.1",
222+
"husky": "^7.0.0"
221223
},
222224
"engines": {
223225
"node": "15.5.0",

scripts/start.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ function addMiddleware (devServer, protocol) {
206206
// This prevents an issue when developing locally using SSL where the server would crash if the API server wasn't running
207207
devServer.listeningApp.on('secureConnection', (sock) => {
208208
sock.on('error', (err) => {
209-
console.error("Caught error on secure connect: ", err);
210-
});
209+
console.error('Caught error on secure connect: ', err)
210+
})
211211
})
212212
}
213213

src/components/Affiliation/Affiliation.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import Affiliation from './Affiliation'
55
describe('Affiliation', () => {
66
it('matches last snapshot', () => {
77
const props = {
8-
affiliation: {
9-
id: "1",
10-
orgName: "La Fromagerie",
11-
preposition: "at",
12-
role: "Cheesemonger",
8+
affiliation: {
9+
id: '1',
10+
orgName: 'La Fromagerie',
11+
preposition: 'at',
12+
role: 'Cheesemonger',
1313
url: null,
14-
createdAt: "2020-12-09T23:01:17.431Z",
15-
updatedAt: "2020-12-09T23:01:17.431Z",
14+
createdAt: '2020-12-09T23:01:17.431Z',
15+
updatedAt: '2020-12-09T23:01:17.431Z',
1616
isActive: true }
1717
}
1818

src/components/AttachmentManager/AttachmentManager.store.test.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('AttachmentManager store', () => {
5555
it('removes an attachment', () => {
5656
const state = {
5757
...defaultState,
58-
['post-new']: [
58+
'post-new': [
5959
{ url: 'a.pdf', attachmentType: 'file' },
6060
{ url: 'b.pdf', attachmentType: 'file' },
6161
{ url: 'c.pdf', attachmentType: 'file' },
@@ -76,13 +76,13 @@ describe('AttachmentManager store', () => {
7676
attachmentKey: 'post-new',
7777
attachmentType: 'image',
7878
position1: 1,
79-
position2: 2,
79+
position2: 2
8080
}
8181
}
8282
it('switches two attachments', () => {
8383
const state = {
8484
...defaultState,
85-
['post-new']: [
85+
'post-new': [
8686
{ url: 'a.pdf', attachmentType: 'file' },
8787
{ url: 'b.pdf', attachmentType: 'file' },
8888
{ url: 'c.pdf', attachmentType: 'file' },
@@ -96,20 +96,20 @@ describe('AttachmentManager store', () => {
9696
})
9797
})
9898
})
99-
100-
describe('getUploadAttachmentPending', () => {
99+
100+
describe('getUploadAttachmentPending', () => {
101101
const props = {
102102
type: 'user-avatar',
103103
id: '123',
104104
attachmentType: 'image'
105105
}
106106

107107
it('returns false when not pending', () => {
108-
const state = { pending: {} }
108+
const state = { pending: {} }
109109

110110
expect(getUploadAttachmentPending(state, props)).toEqual(false)
111111
})
112-
112+
113113
it("returns false when pending doesn't match settings", () => {
114114
const state = {
115115
pending: {
@@ -120,10 +120,10 @@ describe('AttachmentManager store', () => {
120120
}
121121
}
122122
}
123-
123+
124124
expect(getUploadAttachmentPending(state, props)).toEqual(false)
125125
})
126-
126+
127127
it('returns true when pending matches settings', () => {
128128
const state = {
129129
pending: {
@@ -134,7 +134,7 @@ describe('AttachmentManager store', () => {
134134
}
135135
}
136136
}
137-
137+
138138
expect(getUploadAttachmentPending(state, props)).toEqual(true)
139139
})
140140

@@ -148,7 +148,7 @@ describe('AttachmentManager store', () => {
148148
}
149149
}
150150
}
151-
151+
152152
expect(getUploadAttachmentPending(state, { type: props.type, id: props.id })).toEqual(true)
153153
})
154154
})

src/components/AttachmentManager/AttachmentManager.test.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-unused-expressions */
12
import React from 'react'
23
import { shallow } from 'enzyme'
34
import AttachmentManager, { ImageManager, ImagePreview, FileManager, FilePreview } from './AttachmentManager'
@@ -17,7 +18,7 @@ const postEditorCaseDefaultProps = {
1718
type: 'post',
1819
showLabel: true,
1920
showLoading: true,
20-
showsAddButton: true,
21+
showsAddButton: true
2122
}
2223

2324
const commentFormCaseDefaultProps = {
@@ -42,49 +43,48 @@ const attachments = [
4243

4344
describe('AttachmentManager', () => {
4445
it('renders with minProps', () => {
45-
const wrapper =
4646
expect(shallow(
4747
<AttachmentManager {...minDefaultProps} />
4848
).text()).toBe('')
49-
}),
49+
})
5050

5151
describe('as used with PostEditor (showLabel, showLoading, showAddButtons)', () => {
5252
test('when empty', () => {
5353
expect(shallow(
5454
<AttachmentManager {...postEditorCaseDefaultProps} />
55-
)).toMatchSnapshot()
55+
)).toMatchSnapshot()
5656
})
5757

5858
test('with attachments', () => {
5959
expect(shallow(
6060
<AttachmentManager attachments={attachments} {...postEditorCaseDefaultProps} />
61-
)).toMatchSnapshot()
61+
)).toMatchSnapshot()
6262
})
6363

6464
test('when loading', () => {
6565
expect(shallow(
6666
<AttachmentManager uploadAttachmentPending {...postEditorCaseDefaultProps} />
67-
)).toMatchSnapshot()
67+
)).toMatchSnapshot()
6868
})
6969

7070
test('when loading, with attachments', () => {
7171
expect(shallow(
7272
<AttachmentManager attachments={attachments} uploadAttachmentPending {...postEditorCaseDefaultProps} />
73-
)).toMatchSnapshot()
73+
)).toMatchSnapshot()
7474
})
7575
})
7676

7777
describe('as used with CommentForm (default case)', () => {
78-
test('when empty', () => {
78+
test('when empty', () => {
7979
expect(shallow(
8080
<AttachmentManager {...commentFormCaseDefaultProps} />
81-
)).toMatchSnapshot()
81+
)).toMatchSnapshot()
8282
})
8383

8484
test('with attachments', () => {
8585
expect(shallow(
8686
<AttachmentManager attachments={attachments} {...commentFormCaseDefaultProps} />
87-
)).toMatchSnapshot()
87+
)).toMatchSnapshot()
8888
})
8989

9090
test('when loading', () => {
@@ -96,7 +96,7 @@ describe('AttachmentManager', () => {
9696
test('when loading, with attachments', () => {
9797
expect(shallow(
9898
<AttachmentManager attachments={attachments} uploadAttachmentPending {...commentFormCaseDefaultProps} />
99-
)).toMatchSnapshot()
99+
)).toMatchSnapshot()
100100
})
101101
})
102102

@@ -105,21 +105,21 @@ describe('AttachmentManager', () => {
105105
test('with attachments (of both types), when loading', () => {
106106
expect(shallow(
107107
<AttachmentManager attachmentType='image' attachments={attachments} uploadAttachmentPending {...minDefaultProps} />
108-
)).toMatchSnapshot()
108+
)).toMatchSnapshot()
109109
})
110110
})
111111
describe('"file"', () => {
112112
test('with attachments (of both types), when loading', () => {
113113
expect(shallow(
114114
<AttachmentManager attachmentType='file' attachments={attachments} uploadAttachmentPending {...minDefaultProps} />
115-
)).toMatchSnapshot()
115+
)).toMatchSnapshot()
116116
})
117117
})
118118
describe('not provided', () => {
119119
test('with attachments (of both types), when loading', () => {
120120
expect(shallow(
121121
<AttachmentManager attachments={attachments} uploadAttachmentPending {...minDefaultProps} />
122-
)).toMatchSnapshot()
122+
)).toMatchSnapshot()
123123
})
124124
})
125125
})

src/components/CardImageAttachments/CardImageAttachments.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { shallow } from 'enzyme'
55
it('renders a single image', () => {
66
expect(shallow(<CardImageAttachments attachments={[
77
{ url: 'foo', type: 'image' }
8-
]} />)).toMatchSnapshot()
8+
]} />)).toMatchSnapshot()
99
})
1010

1111
it('renders multiple images', () => {

src/components/CreateGroup/CreateGroup.connector.test.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
const defaultProps = {
1010
match: {
1111
params: {
12-
context:'group',
12+
context: 'group',
1313
groupSlug: 'moderatorgroup'
1414
}
1515
},
@@ -26,7 +26,7 @@ describe('CreateGroup.connector', () => {
2626
const session = orm.session(orm.getEmptyState())
2727

2828
session.Me.create({
29-
id: '1',
29+
id: '1'
3030
})
3131

3232
state = {
@@ -49,9 +49,11 @@ describe('CreateGroup.connector', () => {
4949
})
5050

5151
it('gets the default name and slug from the querystring', () => {
52-
const props = { ...defaultProps, location: {
53-
search: '?name=weird&slug=banana'
54-
}}
52+
const props = { ...defaultProps,
53+
location: {
54+
search: '?name=weird&slug=banana'
55+
}
56+
}
5557
const actual = mapStateToProps(state, props)
5658
expect(actual.initialGroupName).toEqual('weird')
5759
expect(actual.initialGroupSlug).toEqual('banana')

src/components/CreateGroup/CreateGroup.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { shallow } from 'enzyme'
33
import React from 'react'
44

55
describe('CreateGroup', () => {
6-
76
it('matches snapshot', () => {
87
const wrapper = shallow(<CreateGroup />)
98
expect(wrapper).toMatchSnapshot()
@@ -13,5 +12,4 @@ describe('CreateGroup', () => {
1312
const wrapper = shallow(<CreateGroup initialName='Epic Name' initialSlug='bananaslug' />)
1413
expect(wrapper).toMatchSnapshot()
1514
})
16-
1715
})

0 commit comments

Comments
 (0)