Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

console-fail-test

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-fail-test

Gently fails test runs if the console was used during them.

  • 0.1.1-beta0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-6.35%
Maintainers
1
Weekly downloads
 
Created
Source

console-fail-test

Circle CI Greenkeeper Code Style: Prettier

Gently fails test runs if the console was used during them.

Usage

console-fail-test is meant to support any (test framework) & (spy library) combination. It will auto-detect your combination if possible and use the most appropriate environment hooks and function spies it can find.

In general, you can use the Node API to request specific test frameworks and spy libraries:

require("console-fail-test").cft({
    testFramework: "jest",
    spyLibrary: "jasmine",
});

Test Frameworks

Test frameworks that are ✨ auto-detectable can be supported by just running console-fail-test/setup.js before tests. For others, use the Node API with their API request:

require("console-fail-test").cft({
    testFramework: require("ava"),
});
FrameworkSupport?API RequestDocumentation
Ava ✅️ require("ava") Ava.md
Mocha ✅️ "mocha" Mocha.md
Jasmine ✅️ "jasmine" Jasmine.md
Jest ✅️ "jest" Jest.md
lab exports.lab Lab.md
node-tap ✅️ require("node-tap") NodeTap.md
QUnit ⚙️ /issues/19
tape ⚙️ /issues/17
TestCafe ⚙️ /issues/15

See open test framework support issues for progress!

Spy Libraries

If a supported spy library isn't detected, an internal fallback will be used to spy on console methods.

You can request a specific test library using the Node API with its API request:

require("console-fail-test").cft({
    spyLibrary: "sinon",
});
LibrarySupport?API RequestSpyDocumentation
Jasmine ✅️ "jasmine" jasmine.createSpy() Jasmine.md
Jest ✅️ "jest" jest.fn() Jest.md
Sinon ✅️ require("sinon") sinon.spy() Sinon.md

Why?

Logging to the console during tests can be a sign of

  • 🚫 warnings from third-party libraries such as React for improper usage
  • 🤕 temporary code that shouldn't be checked into your project
  • 📢 unnecessary spam in your tests window

This little library throws an error after each test if a console method was called during it. It's got some nifty features:

  • 📊 Summary of which methods are called with calling arguments
  • 🛫 Failures are thrown after tests finish, so your tests will fail normally if they should

Look how fancy the terminal output is with Jest!

Terminal output showing details on each console call failing a test

Keywords

FAQs

Package last updated on 04 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc