Git Product home page Git Product logo

purescript-spec-mocha's Introduction

purescript-spec-mocha

purescript-spec-mocha is a runner and reporter for purescript-spec that run tests and reports the results using the Mocha interface (describe, it etc). This enables you to use purescript-spec together with mocha and karma, and thus run tests in web browsers, as well as NodeJS.

Usage

bower install purescript-spec-mocha
module Main where

import Prelude
import Control.Monad.Eff (Eff)
import Test.Spec (SpecEffects, describe, it)
import Test.Spec.Assertions (shouldEqual)
import Test.Spec.Mocha (MOCHA, runMocha)

main :: Eff (SpecEffects (mocha :: MOCHA)) Unit
main = runMocha do
  describe "your feature" do
    it "works" $
      (1 + 1) `shouldEqual` 2

Usage with bundled Purescript

If you bundle your compiled PureScript it can be run with mocha bundle.js or using Karma and karma-mocha.

pulp browserify -I test --main Test.Main > bundle.js
mocha bundle.js

Usage in the browser

If you want to mix in Purescript tests with existing Javascript (or Coffeescript) Mocha tests running in the browser, you'll need to import the file and call the function exported by your Purescript test. E.g. combining the example from Running Mocha in the Browser with the above Purscript spec, you'll need:

<!-- test/index.html -->
...
  <script>mocha.setup('bdd')</script>
  <script src="all_tests.js"></script>
  <script>
    mocha.checkLeaks();
    mocha.globals(['jQuery']);
    mocha.run();
  </script>
...
// all_tests.js
require('test.array.js');               // Javascript specs load when the the file is parsed.
require('test.object.js');
require('test.xhr.js');

{main} = require('my_purescript_spec');
main();                                 // Purescript specs load when the function is called.

Usage with Spago and Parcel

With spago and parcel-bundler, and the above test/index.html you can build tests, and run them on node and browsers with the following entries in your package.json

...
  "scripts": {
    "test:build": "spago bundle-app --main Test.Main --to ./output/test.js",
    "test:watch": "spago bundle-app --watch --main Test.Main --to ./output/test.js --then \"npm run -s test:node\"",
    "test:node": "mocha ./output/test.js",
    "test:browser": "parcel test/index.html --open"
  },
...

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.

API Documentation

See docs on Pursuit.

Contribute

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

Running Tests

This project's tests include some failures to test the Mocha integration. Thus, use run_tests.sh instead of pulp test to check that everything is all right.

License

MIT License.

purescript-spec-mocha's People

Contributors

owickstrom avatar alexadewit avatar anttih avatar anton-k avatar jcsanpedro avatar jmatsushita avatar winstonwolff avatar

Watchers

 avatar

Forkers

ilyakooo0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.