https://github.com/purescript-spec/purescript-spec-mocha
A test runner and reporter for purescript-spec that integrates with Mocha
https://github.com/purescript-spec/purescript-spec-mocha
Last synced: 4 months ago
JSON representation
A test runner and reporter for purescript-spec that integrates with Mocha
- Host: GitHub
- URL: https://github.com/purescript-spec/purescript-spec-mocha
- Owner: purescript-spec
- License: mit
- Created: 2015-07-27T17:42:05.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-07-20T22:12:49.000Z (almost 2 years ago)
- Last Synced: 2025-10-22T21:55:25.539Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 52.7 KB
- Stars: 5
- Watchers: 2
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# purescript-spec-mocha
purescript-spec-mocha is a runner and reporter for
[purescript-spec](https://github.com/purescript-spec/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
```bash
spago install spec-mocha
```
```purescript
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 (runMocha)
main :: Effect Unit
main = runMocha do
describe "your feature" do
it "works" $
(1 + 1) `shouldEqual` 2
```
See `test/Main.purs` for a more detailed example. The `package.json` scripts in this repo, show a number of usage patterns further detailed below. Note that the example tests contain 2 passing tests, a pending test and 2 failing tests, to demonstrate both success and failure.
### Usage with bundled Purescript
You can run `yarn test:node` or `npm run test:node` in this repo to see an example.
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
spago bundle --outfile bundle.js
mocha bundle.js
```
### Usage in the browser
To run mocha tests in the browser, you can run `yarn test:browser` or `npm run test:browser` in this repo to see an example using the `test/browser/index.html` file.
```html
mocha.setup("bdd");
mocha.run();
```
It's also possible to bundle the test as a module in which case you'll need to use `type="module"`:
```html
```
and to import the test module as shown in the `test/browser/index_module.js` file:
```javascript
import { main } from "../../output/test_module.js";
mocha.setup("bdd");
main();
mocha.run();
```
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.
### Usage with headless browser
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.
## API Documentation
See [docs on Pursuit](https://pursuit.purescript.org/packages/purescript-spec-mocha).
## Contribute
If you have any issues or possible improvements please file them as
[GitHub Issues](https://github.com/purescript-spec/purescript-spec-mocha/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 `spago test` to check
that everything is all right.
## License
[MIT License](LICENSE.md).