Testing framework for Purescript

functional-programming, purescript, test-driven-development, testing, type-safety
psc-package install spec


purescript-spec Build Status

purescript-spec is a simple testing framework for Purescript using NodeJS. It's inspired by hspec.


bower install purescript-spec


The specs shown in the image above:

module Main where

import Prelude

import Control.Monad.Aff
import Test.Spec                  (describe, pending, it)
import Test.Spec.Runner           (run)
import Test.Spec.Assertions       (shouldEqual)
import Test.Spec.Reporter.Console (consoleReporter)

main = run [consoleReporter] do
  describe "purescript-spec" do
    describe "What is it?" do
      it "awesome" do
        let isAwesome = true
        isAwesome `shouldEqual` true
    describe "Features" do
      it "runs in NodeJS" $ return unit
      it "runs in the browser" $ return unit
      it "supports async specs" do
        res <- later' 100 $ return "Alligator"
        res `shouldEqual` "Alligator"
      it "is PureScript 0.7 compatible" $ return unit

Combining Specs

You can split test specs into multiple files and combine them in Test.Main using a do expression.

main = run [consoleReporter] do


Reporters can be passed to the runner, e.g. run [reporter1, ..., reporterN] spec. Currently there are these reporters available:


Specs can be async as the test body type of it is forall e. Aff e Unit

Running Tests

When using run you can follow the conventions of pulp and run your tests with pulp test.

If you're not using pulp you can compile using psc and run the compiled Javascript with node.

# compile with psc (modify the command to include all your sources)
psc -o output/tests 'test/**/*.purs' 'src/**/*.purs' --ffi 'src/**/*.js'
# run using node
NODE_PATH=output/tests node -e "require('Test.Main').main();"

Browser Testing

Compile and bundle your tests using pulp browserify -I test --main Test.Main and run the bundled Javascript using mocha or karma. For more information, see purescript-spec-reporter-mocha.


You can use QuickCheck together with the purescript-spec-quickcheck adapter to get nice output formatting for QuickCheck tests.



This projects uses pulp for most of its build. For stuff not supported by pulp we use Make.

# Make the library
pulp build
# Run tests
pulp test
# Generate docs
pulp docs

Generate Example

Generating the example.png requires:

  • make
  • phantomjs
  • aha
  • imagemagick
make example.png


This target generates a CTags file tags.

make ctags


  • 0.7.4
    • Use purescript-node-process instead of custom PROCESS effect.
  • 0.7.2
    • Update purescript-strings for PS 0.7.4 compatibility.
    • Make all dependencies flexible.
    • Fix case statements to remove warnings.
  • 0.7.1
  • 0.7.0
    • Rename runNode to run and place it in Test.Spec.Runner.
    • Support browser testing.
  • 0.6.2
    • Add more assertions.
  • 0.6.1
    • Fix bug in shouldContain assertion for strings.
  • 0.6.0
    • Adapt for PureScript 0.7 compatibility.
  • 0.5.0
    • Make reporters pluggable.
  • 0.4.0
    • Add async support in it using Aff.


If you have any issues or possible improvements please file them as GitHub Issues. Pull requests are encouraged.


MIT License.