forked from kortina/vscode-markdown-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest-focused.sh
executable file
·51 lines (45 loc) · 1.55 KB
/
jest-focused.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Usage:
# Run test at line 248 of extension.test.js:
# ./jest-run-focused-test.sh out/test/jest/extension.test.js:248
# Run all tests in extension.test.js:
# ./jest-run-focused-test.sh out/test/jest/extension.test.js
#
set -e
# location of script that will parse out the test function given a filepath and line
wd=`pwd`
test_at_line_js="$wd/out/test-at-line.js"
# arg $1 is the test filename
# replace "/./"" with "/" (artifact of vscode-run-in-terminal starting relative path with a "./")
filename=`echo "$1" | sed 's/\.\/src/.\/out/'`
# replace 'ts' with 'js' in filename
filename=`echo "$filename" | sed 's/\.ts$/.js/'`
filename=`echo "$filename" | sed 's/\.ts:/.js:/'`
# strip the linenumber off the location
filename=`echo "$filename" | sed 's/:.*//'`
config_file="jest.config.js"
npm run compile
# if given file + line number, parse out the test name to run and pass in as a focused test run
if echo "$1" | grep -q ":[0-9]\+$" ; then
bdd_description=$(node $test_at_line_js $1)
bdd_size=${#bdd_description}
if [ $bdd_size -eq 0 ]; then
echo "Not in a describe block, nothing to run!"
exit 1
fi
else
echo "No line number, running entire file."
fi
echo ""
echo "$bdd_description"
echo ""
shift;
# Removed --max_old_space_size=4096
if [[ $* == *--debug* ]]
then
set -x
node --inspect --inspect-brk ./node_modules/.bin/jest --config "$config_file" --runInBand "$filename" -t "$bdd_description" "$@"
else
set -x
node ./node_modules/.bin/jest --config "$config_file" "$filename" -t "$bdd_description" "$@"
fi