0.8.3 • Published 2 years ago

wattle v0.8.3

Weekly downloads
3
License
MIT
Repository
-
Last release
2 years ago

Wattle

...as in, "wattle happen when I run this code?"

Wattle is a hierarchical test runner for Node that aims to make writing tests as easy as possible.

Getting Started

Install NPM package both locally and globally with:

npm install --save-dev wattle
npm install --global wattle

or

yarn add --dev wattle
yarn global add wattle

In your test files, import the test functions:

import { describe, when, then, it, test } from 'wattle';

(note that all these functions do the same thing - they're just for readability)

Import an assertion library (I recommend chai):

import { expect } from 'chai';

Then start writing tests:

describe("my class", () => {
    let sut = new MyClass(); // setup

    when("poked", () => {
        sut.poke(); // more setup

        when("prodded", () => {
            sut.prod(); // even more setup (nest as much as you want)

            it("does what it's told", () => expect(sut.didTheThing).to.be.true);
        });

        sut.settleDown(); // clean up after being poked and prodded
    });
});

To run the tests, just run the wattle command from the folder containing your test files.

Command Line

wattle [-t|--test-files] <test file globs> [options]
OptionDescription
-c, --configPath to wattle config file.
-t, --test-filesOne or more globs of test files to run.
-m, --middlewareAdd one or more middleware modules.
-s, --show-stacksInclude stack traces in output.
-v, --verbosityLogging verbosity (quiet, default, or full).
-b, --build-serverOutput results in a format suitable for a build server. Currently supports TeamCity, AppVeyor, and TFS/VSTS.
-p, --process-countNumber of test processes to use. If 0 is specified, tests will be run synchronously in the main process.
-w, --watchKeep open after initial test run and re-run tests that have changed.
--ts-projectPath to custom tsconfig file.

Options specified via the command line will override options in the configuration file.

Configuration File

In addition to the command line options, you can configure wattle via javascript. By default, this should be a file in the root of your project called wattle.config.js, but you can specify a different file using the --config command line option. The file should look something like this:

require('wattle').configure({
    testFiles: ['./tests/**/*'],
    // ...other options
});

See the Command Line section above for available options. Note that options are specified as camelCase, rather than kebab-case.

Build Server Support

With the --build-server option, test results will be automatically logged to TeamCity and AppVeyor. For TFS/VSTS, wattle will create a wattle-results.trx file that needs to be published with a Publish Test Results build step.

Visual Studio Code Integration

There are example launch and task configurations in the examples folder that you can use to get started. The task configuration includes a problem matcher will will show test failures as errors in the code. Example snippets are also included in the examples folder, which can make writing tests a lot faster.

Middleware

You can specify custom middleware with the --middleware option. Middleware modules should export an ITestMiddleware object as their default export. The easiest way to implement middleware is to extend TestMiddleware:

// CustomMiddleware.ts
import { TestMiddleware } from 'wattle';

class CustomMiddleware extends TestMiddleware {
    // Override one or more methods here
}

export default new CustomMiddleware();

and then use it with:

wattle -m ./CustomMiddleware
0.8.3

2 years ago

0.8.2

2 years ago

0.8.1

2 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago