Skip to content

Instantly share code, notes, and snippets.

@raphaelbs
Last active November 3, 2020 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raphaelbs/e8d4b030089220f33f73d8d6b92247bc to your computer and use it in GitHub Desktop.
Save raphaelbs/e8d4b030089220f33f73d8d6b92247bc to your computer and use it in GitHub Desktop.
Generate shortcuts for Jest tests
#!/bin/bash
LOCAL=/usr/local/bin
TEST_WATCH="tw"
TEST_COVERAGE="tc"
JEST="./node_modules/jest/bin/jest"
echo "Add test watch script \"$TEST_WATCH\" at $LOCAL/$TEST_WATCH"
echo "#!/bin/bash" > "$LOCAL/$TEST_WATCH"
echo "echo \"Testing w/ watch with pattern: \$1\"" >> "$LOCAL/$TEST_WATCH"
echo "NODE_ENV=test node $JEST --watchAll \"\$1\"" >> "$LOCAL/$TEST_WATCH"
chmod +x $LOCAL/$TEST_WATCH
echo "Add test coverate script \"$TEST_COVERAGE\" at $LOCAL/$TEST_COVERAGE"
echo "#!/bin/bash" > $LOCAL/$TEST_COVERAGE
echo "echo \"Testing w/ coverage with pattern: \$1"\" >> $LOCAL/$TEST_COVERAGE
echo "NODE_ENV=test node $JEST --coverage \"\$1\" --collectCoverageFrom=\"**/\$1/**\" \"\${@:2}\"" >> $LOCAL/$TEST_COVERAGE
chmod +x $LOCAL/$TEST_COVERAGE
echo ""
echo "Instructions"
echo ""
echo "** Make sure you have jest installed inside the directory you will run these commands (./node_modules/jest). **"
echo ""
echo "tw"
echo " Test and watch files given a pattern."
echo " Examples"
echo " \"tw review\" -> will test and watch test files with \"review\" keyword"
echo " \"tw app/containers/Reviews/Review/tests/ReviewFunctions.test.js\" -> will test and watch a single file specified by path"
echo ""
echo "tc"
echo " Test and generate coverage given a pattern. Strong suggest using this command supplying a folder name instead a single file."
echo " Examples"
echo " \"tc Review\" -> will test and generate coverage for **/Review/** folder"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment