Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sbt/sbt-mocha
SBT plugin for running mocha JavaScript unit tests on node
https://github.com/sbt/sbt-mocha
Last synced: 2 months ago
JSON representation
SBT plugin for running mocha JavaScript unit tests on node
- Host: GitHub
- URL: https://github.com/sbt/sbt-mocha
- Owner: sbt
- License: apache-2.0
- Created: 2014-03-03T06:24:56.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2024-10-16T09:42:13.000Z (3 months ago)
- Last Synced: 2024-10-18T05:49:25.451Z (3 months ago)
- Language: Scala
- Size: 128 KB
- Stars: 17
- Watchers: 10
- Forks: 17
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-sbt-plugins - sbt-mocha
README
sbt-mocha
=========[![Build Status](https://github.com/sbt/sbt-mocha/actions/workflows/build-test.yml/badge.svg)](https://github.com/sbt/sbt-mocha/actions/workflows/build-test.yml)
Allows mocha to be used from within sbt via the use of [sbt-web](https://github.com/sbt/sbt-web). You can therefore run your JS tests using SBT conventions either in-JVM (eg Trireme), or on (Node).
To use this plugin use the addSbtPlugin command within your project's plugins.sbt (or as a global setting) i.e.:
addSbtPlugin("com.github.sbt" % "sbt-mocha" % "2.0.0")
Then declare the settings required in your build file:
lazy val root = (project in file(".")).enablePlugins(SbtWeb)
By default, any tests matching either `*Test.js` or `*Spec.js` are tested. This can be overridden by defining a different includes, for example:
```scala
TestAssets / WebKeys.jsFilter := GlobFilter("Test*.js")
```Tests are read from `src/test/assets` and `src/test/public`. For example, you can create `src/test/assets/FooSpec`:
```js
var assert = require("assert");
describe("Foo", function() {
it("say hello", function() {
var foo = require("./Foo");
assert.equal(foo.hello("world"), "hello world");
});
});
```All assets are copied to a working directory, which means any test or main assets may be imported via relative paths from that working directory.
Any node WebJars are made available as normal node modules via the `require` method, and all other WebJars are installed in the `lib` directory under the WebJars name.
The following options are supported:
* `MochaKeys.requires` - A list of resources that should be required before each test run.
* `MochaKeys.globals` - A list of variables that Mocha should make global.
* `MochaKeys.checkLeaks` - Set to true to run mocha in check leaks mode.
* `MochaKeys.bail` - Set to true to tell mocha to bail after the first run.