Skip to content

Commit 9a1fd27

Browse files
committed
Added npm tasks to speed up automated testing.
1 parent d3f3609 commit 9a1fd27

6 files changed

Lines changed: 98 additions & 30 deletions

File tree

bin/checkHTML.sh

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,27 @@
1919
# 100 - VNU checks returns errors
2020
# 101 - aXe returned errors
2121
# 102 - pa11y returned errors
22+
#
23+
#
24+
# Arguments:
25+
# checkHTML.sh all --for-pr : Just check files relevant for the PR.
2226
#######################################################################
2327

2428
echo "PATH is $PATH"
2529
which axe
2630

2731
VNU_JAR="node_modules/vnu-jar/build/dist/vnu.jar"
2832
VNU_CMD="java -jar $VNU_JAR"
33+
TEMPLIST_FILE="tmp/temp-files.txt"
34+
JUST_FOR_PR="0"
2935

30-
which ifconfig 1>&2 2> /dev/null
31-
if [ "$?" = "0" ]
36+
if [ "$2" = "--for-pr" ]
3237
then
33-
MYIP=`ifconfig -a | grep inet | grep -v inet6 | awk '{print $2}' | head -2 | tail -1`
34-
else
35-
id=$(netsh interface show interface | grep "Connected" | awk '{print $4}')
36-
MYIP=$(ipconfig | awk -v desc="$id" '
37-
BEGIN {found=0}
38-
{
39-
if ($0 ~ desc) {
40-
found=1
41-
} else if ($0 ~ /^[^ ]/ && found) {
42-
found=0
43-
}
44-
if (found && /IPv4 Address/) {
45-
gsub(/.*: /, "", $0)
46-
print $0
47-
exit
48-
}
49-
}')
38+
echo "Just running tests for this PR"
39+
JUST_FOR_PR="1"
5040
fi
41+
42+
MYIP=`bin/my-ip.sh`
5143
PROJECT_URL="http://$MYIP:8888/index.php"
5244
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
5345
PHP=`bin/findPHP.sh`
@@ -229,7 +221,13 @@ checkDependencies() {
229221
downloadHTML() {
230222
checkDependencies
231223

232-
URLS=`bin/getPages.js $MYIP`;
224+
if [ "$JUST_FOR_PR" = "0" ]
225+
then
226+
URLS=`bin/getPages.js $MYIP`;
227+
else
228+
URLS=`bin/pages-affected-in-PR.sh`
229+
fi
230+
233231
DOWNLOADED_URLS=""
234232
TEMP_FILES=""
235233

@@ -269,19 +267,20 @@ downloadHTML() {
269267
echo
270268

271269
printf "%s\n" $DOWNLOADED_URLS > tmp/downloaded-urls.txt
272-
echo -n $TEMP_FILES > tmp/temp-files.txt
270+
echo -n $TEMP_FILES > $TEMPLIST_FILE
273271
echo -n $AXE_DELAYED_FILES > tmp/axe-delayed-files.txt
274272
}
275273

276274

277275
runVNUTests() {
276+
echo "Running VNU Tests ..."
278277
#. Download the HTML files if they have not already been downloaded
279-
if ! [ -f tmp/temp-files.txt ]
278+
if ! [ -f $TEMPLIST_FILE ]
280279
then
281280
bin/generateSiteMap.sh
282281
downloadHTML
283282
else
284-
: "${TEMP_FILES:=`cat tmp/temp-files.txt`}"
283+
: "${TEMP_FILES:=`cat $TEMPLIST_FILE`}"
285284
fi
286285
numTempFiles=$(echo "${TEMP_FILES}" | awk -F" " '{print NF}')
287286

@@ -483,7 +482,7 @@ function runLighthouseTests() {
483482
node bin/lighthouse-accessibility-scan.js
484483
}
485484

486-
if [ "$#" = "1" ]
485+
if [ "$#" = "2" ]
487486
then
488487
TYPE="$1"
489488
FILES="${@:2}"
@@ -504,6 +503,8 @@ fi
504503
bin/generateSiteMap.sh
505504
downloadHTML
506505

506+
echo "TYPE: $TYPE"
507+
507508

508509
#.. Run specific tests based on the argument passed in when running this script
509510
if [ "$TYPE" = "vnu" ]
@@ -530,4 +531,3 @@ then
530531
rm tmp/* 2> /dev/null
531532
fi
532533

533-
echo "DOWNLOADED_URLS: $DOWNLOADED_URLS"

bin/find-affected-pages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* --match <mode> Matching mode: "suffix" (default) or "basename"
1818
* --exts <csv> Extra HTML-like extensions to include (default: ".html,.htm")
1919
* --results-relative Output only filenames (no paths) for pages and assets
20-
* --just-pages Output only the list of affected pages (no assets)
20+
* --just-pages Output only the list of affected pages (no assets like js or CSS files)
2121
* --quiet Machine-friendly output:
2222
* - default: CSV "page,assets"
2323
* - with --just-pages: one page per line

bin/my-ip.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
which ifconfig 1> /dev/null 2> /dev/null
4+
if [ "$?" = "0" ]
5+
then
6+
MYIP=`ifconfig -a | grep inet | grep -v inet6 | awk '{print $2}' | head -2 | tail -1`
7+
else
8+
id=$(netsh interface show interface | grep "Connected" | awk '{print $4}')
9+
MYIP=$(ipconfig | awk -v desc="$id" '
10+
BEGIN {found=0}
11+
{
12+
if ($0 ~ desc) {
13+
found=1
14+
} else if ($0 ~ /^[^ ]/ && found) {
15+
found=0
16+
}
17+
if (found && /IPv4 Address/) {
18+
gsub(/.*: /, "", $0)
19+
print $0
20+
exit
21+
}
22+
}')
23+
fi
24+
25+
echo $MYIP

bin/pages-affected-in-PR.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ CSS_LIST=`echo "$FILE_LIST" | grep ".css$"`
88

99
BASE_PHP_LIST=`echo "$PHP_LIST" | awk -F"/" '{print $NF}' `
1010

11-
PHP_FILES_AFFECTED_BY_JS_OR_CSS=`node bin/find-affected-pages.js \
11+
MYIP=`bin/my-ip.sh`
12+
13+
14+
15+
16+
PHP_FILES_AFFECTED=`node bin/find-affected-pages.js \
1217
--dir ./tmp/vnu/ \
1318
--exts ".php" \
1419
--quiet --just-pages --results-relative \
1520
--match basename \
16-
--files "$(git diff --name-only origin/main...HEAD | paste -sd, -)" `
21+
--files "$(git diff --name-only origin/main...HEAD | paste -sd, -)"
22+
--add-prefix= `
23+
1724

1825

1926
LIST="$BASE_PHP_LIST
20-
$PHP_FILES_AFFECTED_BY_JS_OR_CSS"
27+
$PHP_FILES_AFFECTED"
2128

22-
echo "$LIST" | sort -u
29+
echo "$LIST" | sort -u | awk -v myip="$MYIP" '{printf ("http://%s:8888/%s\n", myip, $1)}'

bin/runJestForPR.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
FILE_LIST=`git diff --name-only origin/main...HEAD`
4+
5+
PHP_LIST=`echo "$FILE_LIST" | egrep ".php$"`
6+
JS_LIST=`echo "$FILE_LIST" | grep ".js$"`
7+
CSS_LIST=`echo "$FILE_LIST" | grep ".css$"`
8+
9+
BASE_PHP_LIST=`echo "$PHP_LIST" | awk -F"/" '{print $NF}' `
10+
11+
MYIP=`bin/my-ip.sh`
12+
13+
14+
15+
16+
PHP_FILES_AFFECTED=`node bin/find-affected-pages.js \
17+
--dir ./tmp/vnu/ \
18+
--exts ".php" \
19+
--quiet --just-pages --results-relative \
20+
--match basename \
21+
--files "$(git diff --name-only origin/main...HEAD | paste -sd, -)"
22+
`
23+
24+
POSSIBLE_TEST_FILES=`echo "$PHP_FILES_AFFECTED" | sed "s/.php/.test.js/"`
25+
TEST_FILES=""
26+
27+
for i in $POSSIBLE_TEST_FILES
28+
do
29+
if [ -f "js/test/$i" ]
30+
then
31+
TEST_FILES="$TEST_FILES $i"
32+
fi
33+
done
34+
35+
node node_modules/jest/bin/jest.js --run-in-band --runInBand $TEST_FILES

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"scripts": {
3838
"jest": "jest --runInBand",
3939
"test": "bin/enforceRemFontSize.sh && bin/checkHTML.sh && jest --runInBand",
40+
"test-pr": "bin/enforceRemFontSize.sh && bin/checkHTML.sh all --for-pr && bin/runJestForPR.sh",
4041
"jest-local": "jest --maxWorkers=75%",
4142
"test-local": "bin/checkHTML.sh && jest --maxWorkers=75%",
4243
"jest-debug-memory-leak": "node --expose-gc ./node_modules/.bin/jest --runInBand --logHeapUsage",

0 commit comments

Comments
 (0)