You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PureScript code is pure and total, so most testing is usually a form of documentation or done with generative tests. However,
occasionally tests need to test FFI bindings, which is where PhantomJS comes in handy. If you need to test some code that deals
with Window, or the DOM, or some web APIs, these bindings come in handy. It can be used as a simpler replacement to the karma
test-runner framework.
QuickStart
importPrelude ((>>=), bind)
importData.Enum (fromEnum)
importExitCodes (ExitCode(Success))
importPhantomJS.Phantom (version, exit)
importControl.Monad.Eff.Console (logShow)
main = do
version >>= logShow
exit (fromEnum Success)
Compatibility
Purescript
purescript-phantom
phantomjs
v0.11.x
v2.x.x
2.1.x
v0.10.1 - v0.10.7
v1.x.x
2.1.x
Examples
If you do not have phantomjs installed, you can install phantomjs-prebuilt from npm, and it will be installed in
./node_modules/.bin/phantomjs. You can then run pulp with the --runtime ./node_modules/.bin/phantomjs and the compiled
code will be run by phantomjs.
The examples folder contains two examples. First compile by running:
pulp build --include examples --main Example --to examples-output/example.js
# or
pulp build --include examples --main Example.Stream --to examples-output/stream.js
You can then run the examples in the examples-output folder:
cd examples-output
../node_modules/.bin/phantomjs example.js
../node_modules/.bin/phantomjs stream.js
Testing
Assuming you have purescript and phantomjs installed, run the following in the project root...
PHANTOM_TEST_PATH=$(pwd) pulp test --runtime phantomjs
PHANTOM_TEST_PATH=$(pwd) pulp test --runtime ./node_modules/.bin/phantomjs
You can also run the tests, in the purescript-docker image.
If you're using docker, follow the instructions in the comments of test.sh to get a working container. You can then run the
tests inside of the container by running ./test.sh on the host, which will run pulp --watch test inside the container.