-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun
executable file
·53 lines (42 loc) · 1.62 KB
/
run
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
52
53
#!/bin/bash
# Check if the argument is 'install'
if [ "$1" == "install" ]; then
echo "Installing.."
npm install
npm run build
if [ $? -eq 0 ]; then
echo "Install succeeded. Build successful."
exit 0
else
echo "Install failed"
exit 1
fi
fi
if [ "$1" == "test" ]; then
# Run the tests and generate a coverage report, directing stderr to /dev/null
OUTPUT=$(npx vitest run --coverage 2>/dev/null)
VITEST_EXIT_CODE=$?
# If Vitest fails, still display the number of passed tests
if [ $VITEST_EXIT_CODE -ne 0 ]; then
# Extract the number of failed tests and total tests
TESTS_FAILED=$(echo "$OUTPUT" | grep 'Tests' | awk '{print $2}')
TOTAL_TESTS=$(echo "$OUTPUT" | grep 'Tests' | awk '{print $5}' | sed 's/[()]//g')
# Calculate the number of passed tests
TESTS_PASSED=$((TOTAL_TESTS - TESTS_FAILED))
# Output the results in the specified format
echo "$TESTS_PASSED/$TOTAL_TESTS test cases passed. ??% line coverage achieved."
exit 1
fi
# Extract the number of tests passed and total tests
TESTS_PASSED=$(echo "$OUTPUT" | grep 'Tests' | awk '{print $2}')
TOTAL_TESTS=$(echo "$OUTPUT" | grep 'Tests' | awk '{print $4}' | sed 's/[()]//g')
# Extract line coverage percentage
COVERAGE_PERCENT=$(echo "$OUTPUT" | grep 'All files' | awk '{print $10}')
# Round the coverage percentage to the nearest whole number
COVERAGE_ROUNDED=$(printf "%.0f" "$COVERAGE_PERCENT")
# Output the results in the specified format
echo "$TESTS_PASSED/$TOTAL_TESTS test cases passed. $COVERAGE_ROUNDED% line coverage achieved."
exit 0
fi
# Handle other cases
node dist/index.js "$1"