0.4.28 • Published 10 days ago

@thi.ng/testament v0.4.28

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
10 days ago

testament

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Minimal, rational & TypeScript-friendly test runner, result export as CSV/JSON, watch mode.

Status

ALPHA - bleeding edge / work-in-progress

Search or submit any issues for this package

Installation

yarn add @thi.ng/testament

ES module import:

<script type="module" src="https://cdn.skypack.dev/@thi.ng/testament"></script>

Skypack documentation

For Node.js REPL:

# with flag only for < v16
node --experimental-repl-await

> const testament = await import("@thi.ng/testament");

Package sizes (gzipped, pre-treeshake): ESM: 1.04 KB

Dependencies

CLI

The library includes a CLI runner to execute tests in various files once, or watch them for changes and then re-execute any changed files. Options and file paths can be given in any order.

testament --help

# Usage: testament [opts] path1 [path2...]
#
# Options:
# --all, -a        Run all tests (don't stop at 1st failure)
# --csv            Export results as CSV
# --json           Export results as JSON
# -o               Output file path for exported results
# --timeout, -t    Set default timeout value (milliseconds)
# --watch, -w      Watch given files/dirs for changes
#
# --help, -h       Print this help and quit

Note: The CLI tool respects the NO_COLOR convention.

Result exports

Test results can be exported in CSV or JSON formats. To include failed tests, make sure you include the --all/-a CLI flag. If no output file (-o) is given, the results will be written to stdout

testament --all --csv -o results.csv test

testament --all --json -o results.json test

The following details are recorded per test case:

  • group: Parent group ID/title
  • title: Test title/descriptor
  • time: Time taken (incl. retries) in milliseconds (rounded)
  • trials: Number of trials taken
  • error: Error message, failure reason

API

Generated API docs

Groups of test cases can be specified via group(). The tests are NOT executed immediately until execute() is being called (done automatically when using the CLI wrapper). All tests within the group will share the (optionally) provided configuration options (which themselves will be stubbed using GLOBAL_OPTS).

If a test is async, use the passed TestCtx handlers (esp. done() and setTimeout()) to ensure timeouts and any errors or test failures are handled properly.

If a test case function makes use of the provided TestCtx arg in any way, it MUST call done(), since testament assumes it is an async case.

Any uncaught errors thrown in the group's lifecycle handlers will not be caught by the group wrapper either (In fact, they will be caught, but then re-thrown...). Furthermore, if the exit option is true (default), any uncaught error will cause the entire process to terminate (unless running a browser).

See docs for full options

import { group, execute } from "@thi.ng/testament";
import { assert } from "@thi.ng/errors";

// register group of test cases
group(
  "basics",
  {
    add: () => { assert(1 + 1 === 2); },
    sub: ({ done, setTimeout }) => {
      setTimeout(() => { assert(3 - 1 === 1); done(); }, 50);
    }
  },
  // shared options for all cases in the group
  {
    maxTries: 3,
    timeOut: 100,
    beforeEach: ({ logger }) => logger.info("before"),
    afterEach: ({ logger }) => logger.info("after"),
  }
);

// only needed if NOT using the CLI runner
const results = await execute();

Authors

Karsten Schmidt

If this project contributes to an academic publication, please cite it as:

@misc{thing-testament,
  title = "@thi.ng/testament",
  author = "Karsten Schmidt",
  note = "https://thi.ng/testament",
  year = 2021
}

License

© 2021 Karsten Schmidt // Apache Software License 2.0

0.4.28

10 days ago

0.4.27

12 days ago

0.4.26

22 days ago

0.4.25

24 days ago

0.4.24

1 month ago

0.4.23

2 months ago

0.4.22

2 months ago

0.4.21

2 months ago

0.4.20

2 months ago

0.4.19

2 months ago

0.4.18

2 months ago

0.4.17

3 months ago

0.4.16

3 months ago

0.4.15

3 months ago

0.4.13

3 months ago

0.4.14

3 months ago

0.4.11

3 months ago

0.4.12

3 months ago

0.4.10

3 months ago

0.4.9

4 months ago

0.4.8

4 months ago

0.4.7

5 months ago

0.4.6

5 months ago

0.4.5

5 months ago

0.4.4

5 months ago

0.3.20

9 months ago

0.3.24

6 months ago

0.3.23

8 months ago

0.3.22

8 months ago

0.3.21

9 months ago

0.3.18

9 months ago

0.4.1

6 months ago

0.4.3

5 months ago

0.4.2

5 months ago

0.3.17

11 months ago

0.3.16

12 months ago

0.3.15

1 year ago

0.3.14

1 year ago

0.3.13

1 year ago

0.3.12

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.0

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.8

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.1.4

3 years ago

0.1.6

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago