Giter VIP home page Giter VIP logo

console-fail-test's Introduction

console-fail-test

Circle CI NPM version Downloads 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"),
});
Framework Support? API Request Documentation
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",
});
Library Support? API Request Spy Documentation
Jasmine ✅️ "jasmine" jasmine.createSpy() Jasmine.md
Jest ✅️ "jest" jest.fn() Jest.md
Sinon ✅️ require("sinon") sinon.spy() Sinon.md

Ignoring console methods

By default, console-fail-test will error on any called console method. If you'd like allow certain methods, pass a console object to the cft API when you set it up:

require("console-fail-test").cft({
    console: {
        warn: true, // won't error on any instance of console.warn
    },
});

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

Development

Requires:

After forking the repo from GitHub:

git clone https://github.com/<your-name-here>/console-fail-test
cd console-fail-test
yarn
yarn run verify

yarn run verify will run a full build and set up the package to be consumed locally.

Contribution Guidelines

We'd love to have you contribute! Check the issue tracker for issues labeled accepting prs to find bug fixes and feature requests the community can work on. If this is your first time working with this code, the good first issue label indicates good introductory issues.

Please note that this project is released with a Contributor Covenant. By participating in this project you agree to abide by its terms. See CODE_OF_CONDUCT.md.

console-fail-test's People

Contributors

greenkeeper[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.