Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
console-fail-test
Advanced tools
Gently fails test runs if the console was used during them. 📢
Logging to the console during tests can be a sign of:
This little library throws an error after each test if a console method was called during it. It's got some nifty features:
stdout | src/index.test.ts > index > example test that console.logs
Whoopsies!
❯ src/index.test.ts (4)
❯ index (4)
× example test that console.logs
⠙ [ afterEach ]
✓ example test that does not console.log
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯- Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯-
FAIL src/index.test.ts > index > example test that console.logs
Error: Oh no! Your test called the following console method:
* log (1 call)
> Call 0: "Whoopsies!"
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.
For example, in a Jest config:
// jest.config.js
module.exports = {
setupFilesAfterEnv: ["console-fail-test/setup.js"],
};
See the Documentation link for each supported framework for how to set up console-fail-test with that framework.
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
|
Vitest | ✅️ ✨ |
"vitest"
|
Vitest.md
|
Cypress | ⚙️ |
/issues/199
| |
QUnit | ⚙️ |
/issues/19
| |
Playwright | ⚙️ |
/issues/198
| |
tape | ⚙️ |
/issues/17
| |
TestCafe | ⚙️ |
/issues/15
|
If your test framework provides its own spy library, console-fail-test will by default use that library.
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#spies
|
Jest | ✅️ |
"jest"
|
jest.fn()
|
Jest.md#spies
|
Sinon | ✅️ |
require("sinon")
|
sinon.spy()
|
Sinon.md#spies
|
Vitest | ✅️ |
"vitest"
|
vi.fn()
|
Vitest.md#spies
|
console
methodsBy 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
},
});
Requires:
After forking the repo from GitHub:
git clone https://github.com/<your-name-here>/console-fail-test
cd console-fail-test
yarn
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.
Colin MacKenzie 💻 🤔 | Dimitri Kopriwa 💻 | Joel 🤔 💻 | Josh Goldberg 🔧 💻 🚧 🚇 🤔 🐛 | SUZUKI Sosuke 💻 |
💙 This package is based on @JoshuaKGoldberg's create-typescript-app.
FAQs
Gently fails test runs if the console was used during them. 📢
The npm package console-fail-test receives a total of 11,756 weekly downloads. As such, console-fail-test popularity was classified as popular.
We found that console-fail-test demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.