Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

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.