dim-console

A console object that outputs its contents dimmed. For testing.

Usage no npm install needed!

<script type="module">
  import dimConsole from 'https://cdn.skypack.dev/dim-console';
</script>

README

Node.JS Dim Console

A console object for testing console output of libraries

Circle CI dependencies Status devDependencies Status

  • Does not interfere with the built-in console: You inject this library as a dependency into your code. This is cleaner, and simpler in larger code bases or test setups. It ensures that you only capture the output of your library under test. The output of other parts of the system - like your test framework, debuggers, tracers, or other libraries - is not affected.

  • Captures the output to the console: You can verify it against expected output.

  • Dumps the ongoing output as it is captured: Prints it dimmed, so that it is distinguishable from other output.

Usage

const dimConsole = require('dim-console')

// use the dim console in your test code somewhere
// your code must understand and use the respective parameters
myMethodUnderTest({console: dimConsole.console})
myMethodUnderTest({process: dimConsole.process})
myMethodUnderTest({stdout: dimConsole.process.stdout})
myMethodUnderTest({stderr: dimConsole.process.stderr})

// get the stdout output captured so far
dimConsole.stdoutOutput

// get the stderr output captured so far
dimConsole.stderrOutput

// get the cumulated output (stdout + stderr) captured so far
dimConsole.output

// reset the captured output
dimConsole.reset()

Related projects

Update dependencies

$ update

Release a new version

$ publish <patch|minor|major>