5.2.5 • Published 3 months ago

node-tdd v5.2.5

Weekly downloads
1,511
License
MIT
Repository
github
Last release
3 months ago

node-tdd

Build Status Test Coverage Dependabot Status Dependencies NPM Downloads Semantic-Release Gardener

Drop in replacement for mocha to abstract commonly used test setups

Install

Install with npm:

$ npm install --save node-tdd

Usage

Drop-in extension for mocha by simply importing describe as below.

import { expect } from 'chai';
import { describe } from 'node-tdd';

describe('Testing some stuff', /* { ...options }, */ () => {
  it('Testing a thing', () => {
    expect(3 * 7).to.equal(21);
  });
});

Please see tests for further usage examples.

Custom Cassette Logic

delayConnection

Delay the connection by a certain number of ms.

delayBody

Delay the response body by a certain number of ms.

Function Kwargs

dir

Type: string

The tmp directory for this test. Only available when useTmpDir is set.

recorder

Type: object

Can be called to interact with the currently captured logs. Exposes the following functions:

  • get(level = null): Returns array of recorded logs. Can be restricted by passing in the log level.
  • reset(): Reset currently captured logs
  • verbose(flag: boolean): Set verbosity mode of capture (if the original logger function is called)

    Only available when record option is used.

capture

Type: function

Utility function that takes a function as an argument, calls it and expects it to raise an error. The raised error is returned. If no error is raised an assertion error is thrown instead.

fixture

Type: function

Utility function that can be used to load test fixtures from the fixtureFolder.

Internally this uses smart-fs to determine how a file extension is loaded.

If the fixture is unique, the file extensions is not required.

CLI Args

nock-heal

Used to heal nock recordings. This is useful when the body of (some) recordings is outdated or the recording order is invalid. Can be used in the following ways:

  • --nock-heal: Will try to heal ordering of nock cassette recordings
  • --nock-heal prune: Will remove unmatched recordings from nock cassette
  • --nock-heal headers: Will try to heal request headers of nock cassette recordings
  • --nock-heal body: Will try to heal bodies of nock cassette recordings
  • --nock-heal path: Will try to heal paths of nock cassette recordings
  • --nock-heal response: Will try to heal responses
  • --nock-heal record: Will record the next unmatched request
  • --nock-heal stub: Will stub the next unmatched request
  • --nock-heal magic: Shorthand for headers,body,path,response

Notes:

  • Different flags can be combined as e.g. --nock-heal body,path
  • Healing cassettes containing out-of-order requests can result in undesired behaviour

Options

useTmpDir

Type: boolean Default: false

When set to true, a fresh temporary directory is set up for each test. The directory is cleaned up after the test run has completed.

useNock

Type: boolean Default: false

When set to true, all requests are automatically nocked. The recording files are automatically created relative to the current test file.

nockFolder

Type: string Default: $FILENAME__cassettes

Used to customize the folder name that contains the nock cassettes. This can be useful when multiple describe in the same file use nock.

nockModifiers

Type: object Default: {}

Used to define modifiers that can be used in cassettes. E.g. can be used to make encoded response bodies more readable. See tests for how to use in detail.

nockStripHeaders

Type: boolean Default: false

When set to true, all headers are stripped when requests are recorded.

nockReqHeaderOverwrite

Type: object Default: {}

Can be used to overwrite reqheaders in recordings. Cassette files are only updated when changed.

fixtureFolder

Type: string Default: $FILENAME__fixtures

Used to customize the folder name that contains the test fixtures. Fixtures can be loaded by calling fixture(FIXTURE_NAME).

envVarsFile

Type: string Default: $FILENAME.env.yml

Used to customize the name of the file that environment variables are loaded from, if it exists.

To allow overwriting of environment variables, prefix the name of the environment variable with ^.

envVars

Type: object Default: -

Used to declare environment variables per describe. Overwrites environment variables loaded from envVarsFile (if allowed).

To allow overwriting of environment variables, prefix the name of the environment variable with ^.

clearCache

Type: boolean Default: true

Known accessed caches will be cleared after test has executed when set to true.

timestamp

Type: number|string Default: -

Set timestamp to freeze time to. Will modify the result of e.g. new Date().

record

Type: object Default: -

Expects logger (e.g. console) to be passed in and captures input, which can be accessed by using recorder from within the test.

cryptoSeed

Type: string Default: -

When set, randomization is overwritten and consistent per test using the provided seed.

cryptoSeedReseed

Type: boolean Default: false

When set to true, all random functions are re-seeded. This results in reduced randomness.

Only allowed when cryptoSeed is provided.

timeout

Type: number Default: -

Set the timeout for all tests in the suite.

5.2.5

3 months ago

5.2.4

7 months ago

5.2.3

7 months ago

5.2.2

7 months ago

5.2.1

7 months ago

5.2.0

7 months ago

5.1.1

8 months ago

5.0.1

9 months ago

5.0.0

9 months ago

5.1.0

9 months ago

4.1.1

11 months ago

4.0.5

12 months ago

4.0.4

12 months ago

4.0.3

12 months ago

4.0.2

1 year ago

4.1.0

12 months ago

4.0.1

1 year ago

4.0.0

1 year ago

3.5.3

1 year ago

3.5.2

1 year ago

3.5.1

1 year ago

3.5.4

1 year ago

3.5.0

2 years ago

3.4.3

2 years ago

3.4.2

2 years ago

3.4.1

3 years ago

3.4.0

3 years ago

3.3.3

3 years ago

3.2.0

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.3.2

3 years ago

3.1.0

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

2.19.2

4 years ago

2.19.3

4 years ago

3.0.0

4 years ago

2.19.1

4 years ago

2.19.0

4 years ago

2.18.13

4 years ago

2.18.12

4 years ago

2.18.11

4 years ago

2.18.10

4 years ago

2.18.9

4 years ago

2.18.8

4 years ago

2.18.7

4 years ago

2.18.6

4 years ago

2.18.5

4 years ago

2.18.4

4 years ago

2.18.3

4 years ago

2.18.2

4 years ago

2.18.1

4 years ago

2.18.0

4 years ago

2.17.0

4 years ago

2.16.1

4 years ago

2.16.0

4 years ago

2.15.1

4 years ago

2.15.0

4 years ago

2.14.0

4 years ago

2.13.0

4 years ago

2.12.1

4 years ago

2.12.0

4 years ago

2.11.5

4 years ago

2.11.4

4 years ago

2.11.3

4 years ago

2.11.2

4 years ago

2.11.1

5 years ago

2.11.0

5 years ago

2.10.6

5 years ago

2.10.5

5 years ago

2.10.4

5 years ago

2.10.2

5 years ago

2.10.3

5 years ago

2.10.1

5 years ago

2.10.0

5 years ago

2.9.13

5 years ago

2.9.12

5 years ago

2.9.11

5 years ago

2.9.10

5 years ago

2.9.9

5 years ago

2.9.8

5 years ago

2.9.7

5 years ago

2.9.6

5 years ago

2.9.5

5 years ago

2.9.4

5 years ago

2.9.3

5 years ago

2.9.2

5 years ago

2.9.1

5 years ago

2.9.0

5 years ago

2.8.0

5 years ago

2.7.2

5 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.6.2

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.5.28

5 years ago

2.5.27

5 years ago

2.5.26

5 years ago

2.5.25

5 years ago

2.5.24

5 years ago

2.5.23

5 years ago

2.5.22

5 years ago

2.5.21

5 years ago

2.5.20

5 years ago

2.5.19

5 years ago

2.5.18

5 years ago

2.5.17

5 years ago

2.5.16

5 years ago

2.5.15

5 years ago

2.5.14

5 years ago

2.5.13

5 years ago

2.5.12

5 years ago

2.5.11

5 years ago

2.5.10

5 years ago

2.5.9

5 years ago

2.5.8

5 years ago

2.5.7

5 years ago

2.5.6

5 years ago

2.5.5

5 years ago

2.5.4

5 years ago

2.5.3

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.0

5 years ago

2.3.0

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.13.0

5 years ago

1.12.3

5 years ago

1.12.2

5 years ago

1.12.1

5 years ago

1.12.0

5 years ago

1.11.2

5 years ago

1.11.1

5 years ago

1.11.0

5 years ago

1.10.1

5 years ago

1.10.0

5 years ago

1.9.1

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago