Skip to content

Latest commit

 

History

History

nightingale-unit-testing

nightingale-unit-testing

nightingale default config for unit testing

Install

npm install --save-dev nightingale-unit-testing

Display a library logs

In your source file, use nightingale-logger.

In test-setup for example:

import "nightingale-unit-testing";

By default, only log above 'ERROR' are displayed

When running test, use DEBUG to show all logs.

Example with jest:

DEBUG='my-lib' npm test

You can also use NIGHTINGALE_LIB_MIN_LEVEL to change the default level of log (but applies to every libraries). See nightingale-levels to know what values can be used.

# display all logs above 'INFO'
NIGHTINGALE_LIB_MIN_LEVEL=200 npm test

You can of course also combine the two

# display all logs above 'INFO', unless it's `my-lib` for which all logs are displayed
NIGHTINGALE_LIB_MIN_LEVEL=200 DEBUG='my-lib' npm test

Logging in tests

import { testLogger } from "nightingale-unit-testing";

it("should test something", () => {
  const value = "hello world";
  testLogger.inspectValue(value);
  expect(value).toBe("hello world");
});

By default, only log above 'DEBUG' are displayed in DEV and above 'INFO' in PRODUCTION (process.env.NODE_ENV === 'production')