2016-10-23 19:43:20 +03:00
|
|
|
# purescript-spec-mocha
|
2015-07-27 20:41:57 +03:00
|
|
|
|
2016-10-23 19:43:20 +03:00
|
|
|
purescript-spec-mocha is a runner and reporter for
|
|
|
|
[purescript-spec](https://github.com/owickstrom/purescript-spec) that run tests
|
|
|
|
and reports the results using the Mocha interface (`describe`, `it` etc). This
|
2017-01-12 09:46:36 +03:00
|
|
|
enables you to use purescript-spec together with `mocha` and `karma`, and thus
|
|
|
|
run tests in web browsers, as well as NodeJS.
|
2016-02-09 22:34:40 +03:00
|
|
|
|
2015-07-27 20:41:57 +03:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
```bash
|
2016-10-23 19:43:20 +03:00
|
|
|
bower install purescript-spec-mocha
|
2015-07-27 20:41:57 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```purescript
|
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Prelude
|
2017-01-12 09:46:36 +03:00
|
|
|
import Control.Monad.Eff (Eff)
|
|
|
|
import Test.Spec (SpecEffects, describe, it)
|
|
|
|
import Test.Spec.Assertions (shouldEqual)
|
|
|
|
import Test.Spec.Mocha (MOCHA, runMocha)
|
2015-07-27 20:41:57 +03:00
|
|
|
|
2017-01-12 09:46:36 +03:00
|
|
|
main :: Eff (SpecEffects (mocha :: MOCHA)) Unit
|
2016-10-23 19:43:20 +03:00
|
|
|
main = runMocha do
|
2017-01-12 09:46:36 +03:00
|
|
|
describe "your feature" do
|
|
|
|
it "works" $
|
|
|
|
(1 + 1) `shouldEqual` 2
|
2015-07-27 20:41:57 +03:00
|
|
|
```
|
|
|
|
|
2018-03-08 20:40:47 +03:00
|
|
|
### Usage with bundled Purescript
|
2015-07-27 20:41:57 +03:00
|
|
|
If you bundle your compiled PureScript it can be run with `mocha bundle.js` or
|
|
|
|
using Karma and [karma-mocha](https://github.com/karma-runner/karma-mocha).
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pulp browserify -I test --main Test.Main > bundle.js
|
|
|
|
mocha bundle.js
|
|
|
|
```
|
|
|
|
|
2018-03-08 20:40:47 +03:00
|
|
|
### 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](https://mochajs.org/#running-mocha-in-the-browser) with the above
|
|
|
|
Purscript spec, you'll need:
|
|
|
|
|
|
|
|
```html
|
|
|
|
<!-- test/index.html -->
|
|
|
|
...
|
|
|
|
<script>mocha.setup('bdd')</script>
|
|
|
|
<script src="all_tests.js"></script>
|
|
|
|
<script>
|
|
|
|
mocha.checkLeaks();
|
|
|
|
mocha.globals(['jQuery']);
|
|
|
|
mocha.run();
|
|
|
|
</script>
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
// 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.
|
|
|
|
```
|
|
|
|
|
2015-07-27 20:41:57 +03:00
|
|
|
## API Documentation
|
|
|
|
|
2016-10-23 19:43:20 +03:00
|
|
|
See [docs on Pursuit](https://pursuit.purescript.org/packages/purescript-spec-mocha).
|
2015-07-27 20:41:57 +03:00
|
|
|
|
|
|
|
## Contribute
|
|
|
|
|
|
|
|
If you have any issues or possible improvements please file them as
|
2016-10-23 19:43:20 +03:00
|
|
|
[GitHub Issues](https://github.com/owickstrom/purescript-spec-mocha/issues).
|
2015-07-27 20:41:57 +03:00
|
|
|
Pull requests requests are encouraged.
|
|
|
|
|
2017-10-04 09:02:08 +03:00
|
|
|
### 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.
|
|
|
|
|
2015-07-27 20:41:57 +03:00
|
|
|
## License
|
|
|
|
|
|
|
|
[MIT License](LICENSE.md).
|