Skip to content

Commit cfdfd9e

Browse files
author
Evan Sebastian
authored
Merge pull request #12 from source-academy/precommit-push-lint-tests
Add linting, tests, as pre-commit and pre-push git hooks
2 parents 6d7b3fd + 299ae56 commit cfdfd9e

File tree

4 files changed

+158
-4
lines changed

4 files changed

+158
-4
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
"start": "react-scripts-ts start",
1616
"build": "react-scripts-ts build",
1717
"test": "react-scripts-ts test --env=jsdom",
18+
"coverage": "./scripts/coverage-fix.sh do && react-scripts-ts test --env=jsdom --coverage && ./scripts/coverage-fix.sh undo",
1819
"update-ui-snapshots": "jest --updateSnapshot"
1920
},
21+
"husky": {
22+
"hooks": {
23+
"pre-commit": "yarn format && CI=true yarn test",
24+
"pre-push": "yarn format && CI=true yarn test"
25+
}
26+
},
2027
"dependencies": {
2128
"@blueprintjs/core": "^2.1.1",
2229
"normalize.css": "^8.0.0",
@@ -48,6 +55,7 @@
4855
"@types/redux-mock-store": "^0.0.13",
4956
"enzyme": "^3.3.0",
5057
"enzyme-adapter-react-16": "^1.1.1",
58+
"husky": "^1.0.0-rc.6",
5159
"prettier": "^1.12.0",
5260
"react-scripts-ts": "^2.15.1",
5361
"react-test-renderer": "^16.3.1",

scripts/coverage-fix.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#! /usr/bin/env bash
2+
3+
DIR_TO_LOOK="./src"
4+
5+
main() {
6+
# make sure we are in the git root
7+
if [[ $(git rev-parse --show-toplevel 2> /dev/null) = "$PWD" ]]; then
8+
if [ "$1" == "do" ]; then
9+
do_change
10+
elif [ "$1" == "undo" ]; then
11+
undo_change
12+
else
13+
echo "Specify 'do' or 'undo' as argument"
14+
fi
15+
else
16+
echo "Please run this command from the git root directory."
17+
false # exit 1
18+
fi
19+
}
20+
21+
do_change() {
22+
# local variables in this function:
23+
# tsd_files: string[] - filenames of *.d.ts
24+
# ts_files: string[] - filenames of tsd_files converted as *.ts
25+
# note that .coverage-fix.tmp is used to keep track of *.ts files that need
26+
# to be renamed back to *.d.ts
27+
local tsd_files=( `find "$DIR_TO_LOOK" -name "*.d.ts"` )
28+
local ts_files=( `printf '%s\n' "${tsd_files[@]}" | sed -e "s/.d.ts/.ts/g"` )
29+
printf '%s\n' "${ts_files[@]}" > .coverage-fix.tmp
30+
local number_files=`cat .coverage-fix.tmp | wc -l`
31+
32+
# because printf %s\n is used to generage .coverage-fix.tmp,
33+
# an empty array of ts_files still generates wc -l -> 1
34+
# in this case, mv will receive 2 empty arguments "", throwing an error
35+
# to avoid, detect if .coverage-fix.tmp has only one character \n
36+
if [[ `cat .coverage-fix.tmp | wc -m` -ne 1 ]]; then
37+
local last_index=$(( number_files - 1 ))
38+
for i in $(seq 0 $last_index); do
39+
echo Renaming "${tsd_files[$i]}" as "${ts_files[$i]}"...
40+
mv "${tsd_files[$i]}" "${ts_files[$i]}"
41+
done
42+
fi
43+
}
44+
45+
undo_change() {
46+
local ts_files=( `cat .coverage-fix.tmp` )
47+
local tsd_files=( `printf '%s\n' "${ts_files[@]}" | sed -e "s/.ts/.d.ts/g"` )
48+
local number_files=`cat .coverage-fix.tmp | wc -l`
49+
50+
if [[ `cat .coverage-fix.tmp | wc -m` -ne 1 ]]; then
51+
local last_index=$(( number_files - 1 ))
52+
for i in $(seq 0 $last_index); do
53+
echo Renaming "${ts_files[$i]}" as "${tsd_files[$i]}"...
54+
mv "${ts_files[$i]}" "${tsd_files[$i]}"
55+
done
56+
fi
57+
58+
rm .coverage-fix.tmp
59+
}
60+
61+
main $1

src/reducers/__tests__/__snapshots__/application.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
exports[`initial state should match a snapshot 1`] = `
44
Object {
55
"environment": "test",
6-
"title": "Conveyor",
6+
"title": "Cadet",
77
}
88
`;

yarn.lock

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,15 @@ cosmiconfig@^2.1.0, cosmiconfig@^2.1.1:
18131813
parse-json "^2.2.0"
18141814
require-from-string "^1.1.0"
18151815

1816+
cosmiconfig@^4.0.0:
1817+
version "4.0.0"
1818+
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-4.0.0.tgz#760391549580bbd2df1e562bc177b13c290972dc"
1819+
dependencies:
1820+
is-directory "^0.3.1"
1821+
js-yaml "^3.9.0"
1822+
parse-json "^4.0.0"
1823+
require-from-string "^2.0.1"
1824+
18161825
cpx@^1.5.0:
18171826
version "1.5.0"
18181827
resolved "https://registry.yarnpkg.com/cpx/-/cpx-1.5.0.tgz#185be018511d87270dedccc293171e37655ab88f"
@@ -2437,7 +2446,7 @@ errno@^0.1.3, errno@~0.1.7:
24372446
dependencies:
24382447
prr "~1.0.1"
24392448

2440-
error-ex@^1.2.0:
2449+
error-ex@^1.2.0, error-ex@^1.3.1:
24412450
version "1.3.1"
24422451
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc"
24432452
dependencies:
@@ -2622,6 +2631,18 @@ execa@^0.7.0:
26222631
signal-exit "^3.0.0"
26232632
strip-eof "^1.0.0"
26242633

2634+
execa@^0.9.0:
2635+
version "0.9.0"
2636+
resolved "https://registry.yarnpkg.com/execa/-/execa-0.9.0.tgz#adb7ce62cf985071f60580deb4a88b9e34712d01"
2637+
dependencies:
2638+
cross-spawn "^5.0.1"
2639+
get-stream "^3.0.0"
2640+
is-stream "^1.1.0"
2641+
npm-run-path "^2.0.0"
2642+
p-finally "^1.0.0"
2643+
signal-exit "^3.0.0"
2644+
strip-eof "^1.0.0"
2645+
26252646
exit@^0.1.2:
26262647
version "0.1.2"
26272648
resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c"
@@ -3509,6 +3530,20 @@ https-browserify@^1.0.0:
35093530
version "1.0.0"
35103531
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
35113532

3533+
husky@^1.0.0-rc.6:
3534+
version "1.0.0-rc.6"
3535+
resolved "https://registry.yarnpkg.com/husky/-/husky-1.0.0-rc.6.tgz#000f5ffe671015ae8c48da5c52b3390bbba9770d"
3536+
dependencies:
3537+
cosmiconfig "^4.0.0"
3538+
execa "^0.9.0"
3539+
find-up "^2.1.0"
3540+
is-ci "^1.1.0"
3541+
pkg-dir "^2.0.0"
3542+
pupa "^1.0.0"
3543+
read-pkg "^3.0.0"
3544+
run-node "^1.0.0"
3545+
slash "^2.0.0"
3546+
35123547
iconv-lite@0.4.19:
35133548
version "0.4.19"
35143549
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
@@ -3683,7 +3718,7 @@ is-callable@^1.1.1, is-callable@^1.1.3:
36833718
version "1.1.3"
36843719
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2"
36853720

3686-
is-ci@^1.0.10:
3721+
is-ci@^1.0.10, is-ci@^1.1.0:
36873722
version "1.1.0"
36883723
resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.1.0.tgz#247e4162e7860cebbdaf30b774d6b0ac7dcfe7a5"
36893724
dependencies:
@@ -4299,7 +4334,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
42994334
version "3.0.2"
43004335
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
43014336

4302-
js-yaml@^3.4.3, js-yaml@^3.7.0:
4337+
js-yaml@^3.4.3, js-yaml@^3.7.0, js-yaml@^3.9.0:
43034338
version "3.11.0"
43044339
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.11.0.tgz#597c1a8bd57152f26d622ce4117851a51f5ebaef"
43054340
dependencies:
@@ -4360,6 +4395,10 @@ json-loader@^0.5.4:
43604395
version "0.5.7"
43614396
resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.7.tgz#dca14a70235ff82f0ac9a3abeb60d337a365185d"
43624397

4398+
json-parse-better-errors@^1.0.1:
4399+
version "1.0.2"
4400+
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
4401+
43634402
json-schema-traverse@^0.3.0:
43644403
version "0.3.1"
43654404
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340"
@@ -4497,6 +4536,15 @@ load-json-file@^2.0.0:
44974536
pify "^2.0.0"
44984537
strip-bom "^3.0.0"
44994538

4539+
load-json-file@^4.0.0:
4540+
version "4.0.0"
4541+
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-4.0.0.tgz#2f5f45ab91e33216234fd53adab668eb4ec0993b"
4542+
dependencies:
4543+
graceful-fs "^4.1.2"
4544+
parse-json "^4.0.0"
4545+
pify "^3.0.0"
4546+
strip-bom "^3.0.0"
4547+
45004548
loader-runner@^2.3.0:
45014549
version "2.3.0"
45024550
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.3.0.tgz#f482aea82d543e07921700d5a46ef26fdac6b8a2"
@@ -5331,6 +5379,13 @@ parse-json@^2.2.0:
53315379
dependencies:
53325380
error-ex "^1.2.0"
53335381

5382+
parse-json@^4.0.0:
5383+
version "4.0.0"
5384+
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-4.0.0.tgz#be35f5425be1f7f6c747184f98a788cb99477ee0"
5385+
dependencies:
5386+
error-ex "^1.3.1"
5387+
json-parse-better-errors "^1.0.1"
5388+
53345389
parse-passwd@^1.0.0:
53355390
version "1.0.0"
53365391
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
@@ -5411,6 +5466,12 @@ path-type@^2.0.0:
54115466
dependencies:
54125467
pify "^2.0.0"
54135468

5469+
path-type@^3.0.0:
5470+
version "3.0.0"
5471+
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
5472+
dependencies:
5473+
pify "^3.0.0"
5474+
54145475
pbkdf2@^3.0.3:
54155476
version "3.0.14"
54165477
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.14.tgz#a35e13c64799b06ce15320f459c230e68e73bade"
@@ -5879,6 +5940,10 @@ punycode@^2.1.0:
58795940
version "2.1.0"
58805941
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.0.tgz#5f863edc89b96db09074bad7947bf09056ca4e7d"
58815942

5943+
pupa@^1.0.0:
5944+
version "1.0.0"
5945+
resolved "https://registry.yarnpkg.com/pupa/-/pupa-1.0.0.tgz#9a9568a5af7e657b8462a6e9d5328743560ceff6"
5946+
58825947
q@^1.1.2:
58835948
version "1.5.1"
58845949
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
@@ -6184,6 +6249,14 @@ read-pkg@^2.0.0:
61846249
normalize-package-data "^2.3.2"
61856250
path-type "^2.0.0"
61866251

6252+
read-pkg@^3.0.0:
6253+
version "3.0.0"
6254+
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389"
6255+
dependencies:
6256+
load-json-file "^4.0.0"
6257+
normalize-package-data "^2.3.2"
6258+
path-type "^3.0.0"
6259+
61876260
"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.4, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.2.9, readable-stream@^2.3.3:
61886261
version "2.3.6"
61896262
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
@@ -6438,6 +6511,10 @@ require-from-string@^1.1.0:
64386511
version "1.2.1"
64396512
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-1.2.1.tgz#529c9ccef27380adfec9a2f965b649bbee636418"
64406513

6514+
require-from-string@^2.0.1:
6515+
version "2.0.2"
6516+
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"
6517+
64416518
require-main-filename@^1.0.1:
64426519
version "1.0.1"
64436520
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"
@@ -6530,6 +6607,10 @@ run-async@^2.2.0:
65306607
dependencies:
65316608
is-promise "^2.1.0"
65326609

6610+
run-node@^1.0.0:
6611+
version "1.0.0"
6612+
resolved "https://registry.yarnpkg.com/run-node/-/run-node-1.0.0.tgz#46b50b946a2aa2d4947ae1d886e9856fd9cabe5e"
6613+
65336614
run-queue@^1.0.0, run-queue@^1.0.3:
65346615
version "1.0.3"
65356616
resolved "https://registry.yarnpkg.com/run-queue/-/run-queue-1.0.3.tgz#e848396f057d223f24386924618e25694161ec47"
@@ -6734,6 +6815,10 @@ slash@^1.0.0:
67346815
version "1.0.0"
67356816
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
67366817

6818+
slash@^2.0.0:
6819+
version "2.0.0"
6820+
resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44"
6821+
67376822
snapdragon-node@^2.0.1:
67386823
version "2.1.1"
67396824
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"

0 commit comments

Comments
 (0)