0
0
Gitdevops~10 mins

Automated testing on push in Git - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Git hook that runs tests on push.

Git
cd .git/hooks && mv pre-push.sample [1]
Drag options to blanks, or click blank then click option'
Apre-commit
Bpre-push
Ccommit-msg
Dpost-commit
Attempts:
3 left
💡 Hint
Common Mistakes
Using pre-commit instead of pre-push
Renaming to a non-hook filename
Not moving the sample file
2fill in blank
medium

Complete the script line to run tests automatically on push.

Git
#!/bin/sh

[1]
Drag options to blanks, or click blank then click option'
Anpm test
Bgit status
Cecho 'Push started'
Dls -l
Attempts:
3 left
💡 Hint
Common Mistakes
Using git status instead of running tests
Using echo which does not run tests
Listing files instead of testing
3fill in blank
hard

Fix the error in the hook script to stop push if tests fail.

Git
#!/bin/sh

npm test || [1]
Drag options to blanks, or click blank then click option'
Aexit 0
Bcontinue
Cexit 1
Dreturn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exit 0' which allows push even if tests fail
Using 'continue' or 'return' which are invalid in shell scripts
Not handling test failure at all
4fill in blank
hard

Fill both blanks to check test results and print a message.

Git
#!/bin/sh

if npm test [1]; then
  echo [2]
else
  exit 1
fi
Drag options to blanks, or click blank then click option'
A&& echo 'Tests passed!'
B|| echo 'Tests passed!'
C&& 'Tests passed!'
D'Tests passed!'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '||' which runs echo on failure
Not using echo to print the message
Putting the message without echo
5fill in blank
hard

Fill all three blanks to create a pre-push hook that runs tests and stops push on failure.

Git
#!/bin/sh

[1] || [2]

exit [3]
Drag options to blanks, or click blank then click option'
Anpm test
Bexit 1
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Exiting with 1 even if tests pass
Not running tests before exit
Using wrong exit codes