Skip to content

Commit ef9afde

Browse files
committed
Run headless browser test in CI and document example script
1 parent 2dbb741 commit ef9afde

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ jobs:
2424
2525
- name: Build and test project
2626
run: ./run_tests.sh
27+
28+
- name: Build and test in headless browser
29+
run: ./run_headless_tests.sh

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ mocha.run();
7070

7171
Running `npm run test:watch` in one terminal window and `npm run test:browser` in another will watch purescript source and tests files and automatically run node and browser tests.
7272

73+
### Usage with headless browser
74+
75+
You can run `yarn test:headless` or `npm run test:headless` in this repo to see an example using the `test/index.html` file together with `mocha-headless-chrome`. Note that we need to disable-web-security in chromium to allow cross-origin requests.
76+
7377
## API Documentation
7478

7579
See [docs on Pursuit](https://pursuit.purescript.org/packages/purescript-spec-mocha).

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
"test:build:module": "spago bundle-module --main Test.Main --to ./output/test_module.js",
55
"test:watch": "spago bundle-app --watch --main Test.Main --to ./output/test.js --then \"mocha ./output/test.js\"",
66
"test:node": "$npm_execpath run test:build && mocha ./output/test.js",
7+
"test:headless": "$npm_execpath run test:build && mocha-headless-chrome -f test/index.html -a disable-web-security",
78
"test:browser": "$npm_execpath run test:build && parcel test/index.html --open",
89
"test:browser:module": "$npm_execpath run test:build:module && parcel test/index_module.html --open"
910
},
1011
"dependencies": {
1112
"bower": "^1.8.14",
1213
"esbuild": "^0.18.15",
13-
"mocha": "^10.2.0",
14+
"mocha": "^9.2.0",
1415
"purescript": "^0.15.10",
1516
"spago": "^0.21.0"
1617
},
1718
"devDependencies": {
19+
"mocha-headless-chrome": "^4.0.0",
1820
"parcel": "^2.9.3"
1921
}
2022
}

run_headless_tests.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
npx spago bundle-app --main Test.Main --to output/bundle.js
6+
7+
# need to disable-web-security in chromium to allow cross-origin requests
8+
npx mocha-headless-chrome -f test/index.html -o output/test-output-headless.txt -a disable-web-security || echo "Checking test output..."
9+
10+
fail() {
11+
echo -e "\nTests output:\n"
12+
cat output/test-output-headless.txt
13+
exit 1
14+
}
15+
16+
test_single() {
17+
str="$1"
18+
echo -n "${str}? "
19+
if ! grep -q "$str" output/test-output-headless.txt; then
20+
echo "Nope."
21+
fail
22+
else
23+
echo "Yes!"
24+
fi
25+
}
26+
27+
test_single "\"passes\":2"
28+
test_single "\"pending\":1"
29+
test_single "\"failures\":2"

0 commit comments

Comments
 (0)