From dedee06051a5cb36f472ed1d72b6aaa994ab3cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wickstr=C3=B6m?= Date: Mon, 27 Jul 2015 19:41:57 +0200 Subject: [PATCH] Initial commit --- .gitignore | 8 ++++ LICENSE | 21 ++++++++++ README.md | 53 +++++++++++++++++++++++++ bower.json | 19 +++++++++ karma.conf.js | 65 +++++++++++++++++++++++++++++++ src/Test/Spec/Reporter/Mocha.js | 43 ++++++++++++++++++++ src/Test/Spec/Reporter/Mocha.purs | 39 +++++++++++++++++++ test/Main.purs | 21 ++++++++++ 8 files changed, 269 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 bower.json create mode 100644 karma.conf.js create mode 100644 src/Test/Spec/Reporter/Mocha.js create mode 100644 src/Test/Spec/Reporter/Mocha.purs create mode 100644 test/Main.purs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed1270d --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.psci +.psci_modules/ +bower_components/ +node_modules/ +output/ +tmp/ +/*.log +tags diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fc203ac --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..321745e --- /dev/null +++ b/README.md @@ -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). diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..8b9c800 --- /dev/null +++ b/bower.json @@ -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" + } +} diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..cfe3571 --- /dev/null +++ b/karma.conf.js @@ -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 + }) +} diff --git a/src/Test/Spec/Reporter/Mocha.js b/src/Test/Spec/Reporter/Mocha.js new file mode 100644 index 0000000..43a159b --- /dev/null +++ b/src/Test/Spec/Reporter/Mocha.js @@ -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(); + }); + }; + }; +}; diff --git a/src/Test/Spec/Reporter/Mocha.purs b/src/Test/Spec/Reporter/Mocha.purs new file mode 100644 index 0000000..4d1579e --- /dev/null +++ b/src/Test/Spec/Reporter/Mocha.purs @@ -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 diff --git a/test/Main.purs b/test/Main.purs new file mode 100644 index 0000000..6f1417a --- /dev/null +++ b/test/Main.purs @@ -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