Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshuakgoldberg/console-fail-test
Gently fails test runs if the console was used during them. ๐ข
https://github.com/joshuakgoldberg/console-fail-test
console info jasmine jest karma mocha test warn
Last synced: 5 days ago
JSON representation
Gently fails test runs if the console was used during them. ๐ข
- Host: GitHub
- URL: https://github.com/joshuakgoldberg/console-fail-test
- Owner: JoshuaKGoldberg
- License: mit
- Created: 2019-02-28T16:54:42.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T08:17:56.000Z (about 2 months ago)
- Last Synced: 2024-10-29T09:31:07.397Z (about 2 months ago)
- Topics: console, info, jasmine, jest, karma, mocha, test, warn
- Language: TypeScript
- Homepage:
- Size: 2.08 MB
- Stars: 16
- Watchers: 14
- Forks: 6
- Open Issues: 29
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
console-fail-test
Gently fails test runs if the console was used during them. ๐ข
## 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 windowThis 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```plaintext
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!"
```## 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.For example, in a Jest config:
```js
// jest.config.js
module.exports = {
setupFilesAfterEnv: ["console-fail-test/setup.mjs"],
};
```> If your package only supports CommonJS, you can use `console-fail-test/setup.cjs`.
### Test Frameworks
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
### Spy Libraries
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:
```js
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
## 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:```js
require("console-fail-test").cft({
console: {
warn: true, // won't error on any instance of console.warn
},
});
```## Development
Requires:
- [Node.js](https://nodejs.org) >14 (LTS)
- [Yarn](https://yarnpkg.com/en)After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo):
```shell
git clone https://github.com//console-fail-test
cd console-fail-test
yarn
```### Contribution Guidelines
We'd love to have you contribute!
Check the [issue tracker](https://github.com/JoshuaKGoldberg/console-fail-test/issues) for issues labeled [`accepting prs`](https://github.com/JoshuaKGoldberg/console-fail-test/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3A%22accepting+prs%22) 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`](https://github.com/JoshuaKGoldberg/console-fail-test/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+) label indicates good introductory issues.Please note that this project is released with a [Contributor Covenant](https://www.contributor-covenant.org).
By participating in this project you agree to abide by its terms.
See [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md).## Contributors
Colin MacKenzie
๐ป ๐ค
Dimitri Kopriwa
๐ป
Faraz Patankar
๐
Joel
๐ค ๐ป
Josh Goldberg
๐ง ๐ป ๐ง ๐ ๐ค ๐ โ ๏ธ
SUZUKI Sosuke
๐ป
> ๐ This package is based on [@JoshuaKGoldberg](https://github.com/JoshuaKGoldberg)'s [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).