fail-on-console 1.0.1 â 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +24 -18
- package/index.d.ts +8 -2
- package/index.js +5 -4
- package/package.json +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.1.1](https://github.com/benquarmby/fail-on-console/compare/v1.1.0...v1.1.1) (2026-07-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* add missing keywords and refine description ([3d8688a](https://github.com/benquarmby/fail-on-console/commit/3d8688aa33ce9a717adb7e01b0f8431cbd86ea0e))
|
|
9
|
+
|
|
10
|
+
## [1.1.0](https://github.com/benquarmby/fail-on-console/compare/v1.0.1...v1.1.0) (2026-07-06)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add setupConsole export ([073ba69](https://github.com/benquarmby/fail-on-console/commit/073ba69ce1b7e07d09880ef110aea55f34b7f995))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* deprecate setup export ([21f732a](https://github.com/benquarmby/fail-on-console/commit/21f732a1b48420818d055f0dace57eab3e4eb69e))
|
|
21
|
+
|
|
3
22
|
## [1.0.1](https://github.com/benquarmby/fail-on-console/compare/v1.0.0...v1.0.1) (2026-07-06)
|
|
4
23
|
|
|
5
24
|
|
package/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# Fail on Console
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Fail Vitest or Jest tests when unexpected console logs, warnings or errors occur.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/fail-on-console)
|
|
6
|
+
[](https://github.com/benquarmby/fail-on-console/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
The `fail-on-console` utility fails test suites whenever unexpected `console` logs, warnings, or errors are triggered, keeping test results clear and easy to read.
|
|
6
9
|
|
|
7
10
|
## Features
|
|
8
11
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- **Flexible Allowlist**: Suppresses known or expected console outputs globally, per suite, or per individual test. Exceptions can be matched against strings, regular expressions, or custom predicate functions.
|
|
12
|
+
- **⥠Vitest and Jest Native**: Seamless integration with Vitest (including Browser Mode) and Jest using standard lifecycle hooks.
|
|
13
|
+
- **đĒļ Zero Dependencies**: Pure, lightweight JavaScript with a tiny footprint.
|
|
14
|
+
- **đ¯ Configurable Targets**: Choose exactly which console methods to monitor (`log`, `warn`, `error`, `info`, `debug`).
|
|
15
|
+
- **đ Flexible Allowlist**: Easily suppress expected console noise globally, per suite, or per test using strings, regular expressions, or custom predicates.
|
|
14
16
|
|
|
15
17
|
## Installation
|
|
16
18
|
|
|
@@ -27,24 +29,28 @@ yarn add --dev fail-on-console
|
|
|
27
29
|
|
|
28
30
|
## Setup
|
|
29
31
|
|
|
30
|
-
`setup` should be called once in a global setup file, accepting the lifecycle hooks and `expect` utility from the testing framework.
|
|
31
|
-
|
|
32
32
|
### With Vitest
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
Initialize `setupConsole` inside a configured [`setupFiles`](https://vitest.dev/config/setupfiles) module (e.g., `vitest.setup.js`).
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
// vitest.setup.js
|
|
35
38
|
import {beforeEach, afterEach, expect} from "vitest";
|
|
36
|
-
import {
|
|
39
|
+
import {setupConsole} from "fail-on-console";
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
setupConsole({beforeEach, afterEach, expect});
|
|
39
42
|
```
|
|
40
43
|
|
|
41
44
|
### With Jest
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
Initialize `setupConsole` inside a configured [`setupFilesAfterEnv`](https://jestjs.io/docs/configuration#setupfilesafterenv-array) module (e.g., `jest.setup.js`).
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// jest.setup.js
|
|
44
50
|
import {beforeEach, afterEach, expect} from "@jest/globals";
|
|
45
|
-
import {
|
|
51
|
+
import {setupConsole} from "fail-on-console";
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
setupConsole({beforeEach, afterEach, expect});
|
|
48
54
|
```
|
|
49
55
|
|
|
50
56
|
### Customizing Monitored Methods
|
|
@@ -52,11 +58,11 @@ setup({beforeEach, afterEach, expect});
|
|
|
52
58
|
By default, `debug` is not monitored but `error`, `warn`, `info`, and `log` are. This can be customized by passing a `methods` array:
|
|
53
59
|
|
|
54
60
|
```ts
|
|
55
|
-
|
|
61
|
+
setupConsole({
|
|
56
62
|
beforeEach,
|
|
57
63
|
afterEach,
|
|
58
64
|
expect,
|
|
59
|
-
// Fail on console.error, console.warn and console.debug.
|
|
65
|
+
// Fail on console.error, console.warn, and console.debug.
|
|
60
66
|
methods: ["error", "warn", "debug"]
|
|
61
67
|
});
|
|
62
68
|
```
|
|
@@ -85,7 +91,7 @@ allowConsole("error", ["known warning", /deprecated/, (msg) => msg.includes("thi
|
|
|
85
91
|
|
|
86
92
|
## API Reference
|
|
87
93
|
|
|
88
|
-
### `
|
|
94
|
+
### `setupConsole(options)`
|
|
89
95
|
|
|
90
96
|
Initializes console spies that monitor active tests.
|
|
91
97
|
|
package/index.d.ts
CHANGED
|
@@ -28,6 +28,12 @@ export interface AllowPredicate {
|
|
|
28
28
|
|
|
29
29
|
export type AllowRule = string | RegExp | AllowPredicate;
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use setupConsole() instead. This function will be removed in a
|
|
33
|
+
* future major version.
|
|
34
|
+
*/
|
|
35
|
+
export function setup(options: SetupOptions): void;
|
|
36
|
+
|
|
31
37
|
/**
|
|
32
38
|
* Installs console spies that fail the current test if any monitored console
|
|
33
39
|
* method is called. Call once at the top of the test setup file, passing the
|
|
@@ -37,7 +43,7 @@ export type AllowRule = string | RegExp | AllowPredicate;
|
|
|
37
43
|
* @param {Function} options.beforeEach The beforeEach hook from the test framework.
|
|
38
44
|
* @param {Function} options.afterEach The afterEach hook from the test framework.
|
|
39
45
|
* @param {Object} options.expect The expect object from the test framework. Must expose getState().
|
|
40
|
-
* @param {string[]} [options.methods=["error","warn","info","log"]]
|
|
46
|
+
* @param {string[]} [options.methods=["error","warn","info","log"]] Console methods to monitor.
|
|
41
47
|
* @example
|
|
42
48
|
* // Jest
|
|
43
49
|
* import {beforeEach, afterEach, expect} from "@jest/globals";
|
|
@@ -51,7 +57,7 @@ export type AllowRule = string | RegExp | AllowPredicate;
|
|
|
51
57
|
*
|
|
52
58
|
* setup({beforeEach, afterEach, expect});
|
|
53
59
|
*/
|
|
54
|
-
export function
|
|
60
|
+
export function setupConsole(options: SetupOptions): void;
|
|
55
61
|
|
|
56
62
|
/**
|
|
57
63
|
* Allows specific console calls to pass. Console exceptions can be configured
|
package/index.js
CHANGED
|
@@ -46,9 +46,9 @@ function isAllowed(message, rule) {
|
|
|
46
46
|
return rule.test(message);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
function
|
|
49
|
+
function setupConsole({beforeEach, afterEach, expect, methods = defaultMethods}) {
|
|
50
50
|
if (testApi) {
|
|
51
|
-
throw new Error("fail-on-console: Call
|
|
51
|
+
throw new Error("fail-on-console: Call setupConsole() only once.");
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
testApi = {beforeEach, afterEach, expect};
|
|
@@ -95,7 +95,7 @@ function setup({beforeEach, afterEach, expect, methods = defaultMethods}) {
|
|
|
95
95
|
|
|
96
96
|
function allowConsole(method, rules) {
|
|
97
97
|
if (!testApi) {
|
|
98
|
-
throw new Error("fail-on-console: Call
|
|
98
|
+
throw new Error("fail-on-console: Call setupConsole() before using allowConsole().");
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
const normalized = Array.isArray(rules) ? rules : [rules];
|
|
@@ -113,5 +113,6 @@ function allowConsole(method, rules) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
exports.setup =
|
|
116
|
+
exports.setup = setupConsole;
|
|
117
|
+
exports.setupConsole = setupConsole;
|
|
117
118
|
exports.allowConsole = allowConsole;
|
package/package.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fail-on-console",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Fail Vitest or Jest tests when unexpected console logs, warnings or errors occur.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"jest",
|
|
7
|
+
"vitest",
|
|
8
|
+
"console",
|
|
9
|
+
"testing"
|
|
10
|
+
],
|
|
5
11
|
"repository": {
|
|
6
12
|
"type": "git",
|
|
7
13
|
"url": "https://github.com/benquarmby/fail-on-console"
|