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
Copy file name to clipboardExpand all lines: README.md
+25-35Lines changed: 25 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,12 @@ main = runMocha do
28
28
(1 + 1) `shouldEqual` 2
29
29
```
30
30
31
+
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.
32
+
31
33
### Usage with bundled Purescript
34
+
35
+
You can run `yarn test:node` or `npm run test:node` in this repo to see an example.
36
+
32
37
If you bundle your compiled PureScript it can be run with `mocha bundle.js` or
33
38
using Karma and [karma-mocha](https://github.com/karma-runner/karma-mocha).
34
39
@@ -38,52 +43,37 @@ mocha bundle.js
38
43
```
39
44
40
45
### Usage in the browser
41
-
If you want to mix in Purescript tests with existing Javascript (or
42
-
Coffeescript) Mocha tests running in the browser, you'll need to import the file
43
-
and call the function exported by your Purescript test. E.g. combining the
44
-
example from [Running Mocha in the
45
-
Browser](https://mochajs.org/#running-mocha-in-the-browser) with the above
46
-
Purscript spec, you'll need:
46
+
47
+
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.
47
48
48
49
```html
49
-
<!-- test/index.html -->
50
-
...
51
-
<script>mocha.setup('bdd')</script>
52
-
<scriptsrc="all_tests.js"></script>
53
-
<script>
54
-
mocha.checkLeaks();
55
-
mocha.globals(['jQuery']);
56
-
mocha.run();
57
-
</script>
58
-
...
50
+
<script>mocha.setup("bdd");</script>
51
+
<scriptsrc="../../output/test.js"></script>
52
+
<script>mocha.run();</script>
59
53
```
60
54
61
-
```javascript
62
-
// all_tests.js
63
-
require('test.array.js'); // Javascript specs load when the the file is parsed.
64
-
require('test.object.js');
65
-
require('test.xhr.js');
55
+
It's also possible to bundle the test as a module in which case you'll need to use `type="module"`:
66
56
67
-
{main} =require('my_purescript_spec');
68
-
main(); // Purescript specs load when the function is called.
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`
and to import the test module as shown in the `test/browser/index_module.js` file:
62
+
63
+
```javascript
64
+
import { main } from"../../output/test_module.js";
65
+
66
+
mocha.setup("bdd");
67
+
main();
68
+
mocha.run();
83
69
```
84
70
85
71
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.
86
72
73
+
### Usage with headless browser
74
+
75
+
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.
76
+
87
77
## API Documentation
88
78
89
79
See [docs on Pursuit](https://pursuit.purescript.org/packages/purescript-spec-mocha).
0 commit comments