mirror of
https://github.com/ilyakooo0/purescript-spec-mocha.git
synced 2024-11-22 02:32:08 +03:00
Initial commit
This commit is contained in:
commit
dedee06051
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.psci
|
||||||
|
.psci_modules/
|
||||||
|
bower_components/
|
||||||
|
node_modules/
|
||||||
|
output/
|
||||||
|
tmp/
|
||||||
|
/*.log
|
||||||
|
tags
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 Oskar Wickstrom
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
53
README.md
Normal file
53
README.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# purescript-spec-reporter-mocha
|
||||||
|
|
||||||
|
purescript-spec-reporter-mocha is a reporter for
|
||||||
|
[purescript-spec](https://github.com/owickstrom/purescript-spec) that reports
|
||||||
|
the test results using the Mocha interface (`describe`, `it` etc). This enables
|
||||||
|
you to use purescript-spec together with `mocha` and `karma`.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bower install purescript-spec-reporter-mocha
|
||||||
|
```
|
||||||
|
|
||||||
|
```purescript
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Test.Spec
|
||||||
|
import Test.Spec.Runner
|
||||||
|
import Test.Spec.Reporter.Mocha
|
||||||
|
|
||||||
|
main = run [mochaReporter] do
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
## API Documentation
|
||||||
|
|
||||||
|
See [the docs directory](docs/).
|
||||||
|
|
||||||
|
### Generating Docs
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pulp docs
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contribute
|
||||||
|
|
||||||
|
If you have any issues or possible improvements please file them as
|
||||||
|
[GitHub Issues](https://github.com/owickstrom/purescript-spec-reporter-mocha/issues).
|
||||||
|
Pull requests requests are encouraged.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[MIT License](LICENSE.md).
|
19
bower.json
Normal file
19
bower.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "purescript-spec-reporter-mocha",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"moduleType": [
|
||||||
|
"node"
|
||||||
|
],
|
||||||
|
"ignore": [
|
||||||
|
"**/.*",
|
||||||
|
"node_modules",
|
||||||
|
"bower_components",
|
||||||
|
"output"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"purescript-console": "^0.1.0",
|
||||||
|
"purescript-foldable-traversable": "~0.4.0",
|
||||||
|
"purescript-exceptions": "~0.3.0",
|
||||||
|
"purescript-spec": "~0.7.0"
|
||||||
|
}
|
||||||
|
}
|
65
karma.conf.js
Normal file
65
karma.conf.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// Karma configuration
|
||||||
|
// Generated on Sat Jul 25 2015 15:47:13 GMT+0200 (CEST)
|
||||||
|
|
||||||
|
module.exports = function(config) {
|
||||||
|
config.set({
|
||||||
|
|
||||||
|
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||||
|
basePath: '',
|
||||||
|
|
||||||
|
|
||||||
|
// frameworks to use
|
||||||
|
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||||
|
frameworks: ['mocha'],
|
||||||
|
|
||||||
|
|
||||||
|
// list of files / patterns to load in the browser
|
||||||
|
files: [
|
||||||
|
'output/bundle.js'
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
// list of files to exclude
|
||||||
|
exclude: [
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
// preprocess matching files before serving them to the browser
|
||||||
|
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||||
|
preprocessors: {
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// test results reporter to use
|
||||||
|
// possible values: 'dots', 'progress'
|
||||||
|
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||||
|
reporters: ['progress', 'bdd'],
|
||||||
|
|
||||||
|
|
||||||
|
// web server port
|
||||||
|
port: 9876,
|
||||||
|
|
||||||
|
|
||||||
|
// enable / disable colors in the output (reporters and logs)
|
||||||
|
colors: true,
|
||||||
|
|
||||||
|
|
||||||
|
// level of logging
|
||||||
|
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||||
|
logLevel: config.LOG_INFO,
|
||||||
|
|
||||||
|
|
||||||
|
// enable / disable watching file and executing tests whenever any file changes
|
||||||
|
autoWatch: true,
|
||||||
|
|
||||||
|
|
||||||
|
// start these browsers
|
||||||
|
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
||||||
|
browsers: ['Chrome'],
|
||||||
|
|
||||||
|
|
||||||
|
// Continuous Integration mode
|
||||||
|
// if true, Karma captures browsers, runs the tests and exits
|
||||||
|
singleRun: false
|
||||||
|
})
|
||||||
|
}
|
43
src/Test/Spec/Reporter/Mocha.js
Normal file
43
src/Test/Spec/Reporter/Mocha.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/* global exports, it */
|
||||||
|
|
||||||
|
// module Test.Spec.Reporter.Mocha
|
||||||
|
|
||||||
|
if (!describe || !it) {
|
||||||
|
throw new Error('Mocha globals seem to be unavailable!');
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.itSuccess = function (name) {
|
||||||
|
"use strict";
|
||||||
|
return function () {
|
||||||
|
it(name, function () {});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.itFailure = function (name) {
|
||||||
|
"use strict";
|
||||||
|
return function (err) {
|
||||||
|
return function () {
|
||||||
|
it(name, function () {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.itPending = function (name) {
|
||||||
|
"use strict";
|
||||||
|
return function () {
|
||||||
|
it(name);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.describe = function (name) {
|
||||||
|
"use strict";
|
||||||
|
return function (nested) {
|
||||||
|
return function () {
|
||||||
|
describe(name, function () {
|
||||||
|
nested();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
39
src/Test/Spec/Reporter/Mocha.purs
Normal file
39
src/Test/Spec/Reporter/Mocha.purs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
module Test.Spec.Reporter.Mocha (
|
||||||
|
mochaReporter,
|
||||||
|
MOCHA()
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Control.Monad.Eff (Eff())
|
||||||
|
import Control.Monad.Eff.Exception (Error())
|
||||||
|
import Data.Foldable (traverse_)
|
||||||
|
import Test.Spec (Result(..), Group(..))
|
||||||
|
import Test.Spec.Reporter (Reporter())
|
||||||
|
|
||||||
|
foreign import data MOCHA :: !
|
||||||
|
|
||||||
|
foreign import itSuccess :: forall e. String
|
||||||
|
-> Eff (mocha :: MOCHA | e) Unit
|
||||||
|
|
||||||
|
foreign import itFailure :: forall e. String
|
||||||
|
-> Error
|
||||||
|
-> Eff (mocha :: MOCHA | e) Unit
|
||||||
|
|
||||||
|
foreign import itPending :: forall e. String
|
||||||
|
-> Eff (mocha :: MOCHA | e) Unit
|
||||||
|
|
||||||
|
foreign import describe :: forall e. String
|
||||||
|
-> Eff (mocha :: MOCHA | e) Unit
|
||||||
|
-> Eff (mocha :: MOCHA | e) Unit
|
||||||
|
|
||||||
|
registerGroup :: forall e. Group
|
||||||
|
-> Eff (mocha :: MOCHA | e) Unit
|
||||||
|
registerGroup (It name Success) = itSuccess name
|
||||||
|
registerGroup (It name (Failure err)) = itFailure name err
|
||||||
|
registerGroup (Pending name) = itPending name
|
||||||
|
registerGroup (Describe name groups) =
|
||||||
|
describe name (traverse_ registerGroup groups)
|
||||||
|
|
||||||
|
mochaReporter :: forall e. Reporter (mocha :: MOCHA | e)
|
||||||
|
mochaReporter groups = traverse_ registerGroup groups
|
21
test/Main.purs
Normal file
21
test/Main.purs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
module Test.Main where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Control.Monad.Eff.Console
|
||||||
|
|
||||||
|
import Test.Spec (describe, it, pending)
|
||||||
|
import Test.Spec.Runner (run)
|
||||||
|
import Test.Spec.Assertions (shouldEqual)
|
||||||
|
import Test.Spec.Reporter.Mocha (mochaReporter)
|
||||||
|
|
||||||
|
main = run [mochaReporter] do
|
||||||
|
describe "test" $
|
||||||
|
describe "nested" do
|
||||||
|
it "works" $
|
||||||
|
(1 + 1) `shouldEqual` 2
|
||||||
|
pending "is pending"
|
||||||
|
|
||||||
|
describe "test" $
|
||||||
|
describe "other" do
|
||||||
|
it "breaks" $ 1 `shouldEqual` 2
|
Loading…
Reference in New Issue
Block a user