cypress-fail-on-console-error 2.1.3 → 3.1.0
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/README.md +9 -7
- package/dist/index.d.ts +4 -5
- package/dist/index.js +74 -45
- package/dist/types/Config.d.ts +2 -1
- package/package.json +18 -16
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# cypress-fail-on-console-error
|
|
2
2
|
|
|
3
|
-
This Plugin observes console.error() function from [window object](https://developer.mozilla.org/de/docs/Web/API/Window).
|
|
3
|
+
This Plugin observes `console.error()` function from [window object](https://developer.mozilla.org/de/docs/Web/API/Window). Cypress test will fail when the error function gets executed.
|
|
4
4
|
|
|
5
5
|
### Installation
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ npm install cypress-fail-on-console-error --save-dev
|
|
|
10
10
|
|
|
11
11
|
### Usage
|
|
12
12
|
|
|
13
|
-
`cypress/support/index.
|
|
13
|
+
`cypress/support/index.js`
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
16
|
import failOnConsoleError from 'cypress-fail-on-console-error';
|
|
@@ -20,10 +20,11 @@ failOnConsoleError();
|
|
|
20
20
|
|
|
21
21
|
### Config (optional)
|
|
22
22
|
|
|
23
|
-
| Parameter | Default | Description
|
|
24
|
-
| --------------------- | --------------------- |
|
|
25
|
-
| `excludeMessages` | `undefined` | Exclude console messages from throwing `
|
|
26
|
-
| `includeConsoleTypes` | `[consoleType.ERROR]` | Include console types for observation
|
|
23
|
+
| Parameter | Default | Description |
|
|
24
|
+
| --------------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `excludeMessages` | `undefined` | Exclude console messages from throwing `AssertionError` <br /> When `console.error()` contains an error object from `new Error()`, then the whole stacktrace can be matched <br /> Regular expression parameters are acceptable. String parameters will be interpreted as regular expression. Be sure to [escape the string regular expression](https://javascript.info/regexp-escaping) for special characters. |
|
|
26
|
+
| `includeConsoleTypes` | `[consoleType.ERROR]` | Include console types for observation |
|
|
27
|
+
| `cypressLog` | `false` | Include debug logs for `errorMessage_excludeMessage_match` and `errorMessage_excluded` to cypress runner |
|
|
27
28
|
|
|
28
29
|
<br/>
|
|
29
30
|
|
|
@@ -32,12 +33,13 @@ failOnConsoleError();
|
|
|
32
33
|
import failOnConsoleError, { consoleType } from 'cypress-fail-on-console-error';
|
|
33
34
|
|
|
34
35
|
const config = {
|
|
35
|
-
excludeMessages: ['foo',
|
|
36
|
+
excludeMessages: ['foo', /^some bar-regex.*/],
|
|
36
37
|
includeConsoleTypes: [
|
|
37
38
|
consoleType.ERROR,
|
|
38
39
|
consoleType.WARN,
|
|
39
40
|
consoleType.INFO,
|
|
40
41
|
],
|
|
42
|
+
cypressLog: true,
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
failOnConsoleError(config);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,9 @@ export default function failOnConsoleError(config?: Config): void;
|
|
|
5
5
|
export declare const validateConfig: (config: Config) => void;
|
|
6
6
|
export declare const createConfig: (config: Config) => Config;
|
|
7
7
|
export declare const createSpies: (config: Config, console: Console) => Map<ConsoleType, sinon.SinonSpy>;
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const someIncludedCall: (spy: sinon.SinonSpy, config: Config) => boolean;
|
|
12
|
-
export declare const isExcludedMessage: (excludeMessages: string[], message: string) => boolean;
|
|
8
|
+
export declare const getIncludedCall: (spies: Map<ConsoleType, sinon.SinonSpy>, config: Config) => string | undefined;
|
|
9
|
+
export declare const findIncludedCall: (spy: sinon.SinonSpy, config: Config) => string | undefined;
|
|
10
|
+
export declare const isErrorMessageExcluded: (errorMessage: string, excludeMessage: string, cypressLog: boolean) => boolean;
|
|
13
11
|
export declare const callToString: (calls: any[]) => string;
|
|
12
|
+
export declare const cypressLogger: (name: string, message: any) => void;
|
|
14
13
|
export declare const consoleType: typeof ConsoleType;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,10 +26,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
27
|
};
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.consoleType = exports.
|
|
29
|
+
exports.consoleType = exports.cypressLogger = exports.callToString = exports.isErrorMessageExcluded = exports.findIncludedCall = exports.getIncludedCall = exports.createSpies = exports.createConfig = exports.validateConfig = void 0;
|
|
26
30
|
var chai = __importStar(require("chai"));
|
|
27
31
|
var sinon = __importStar(require("sinon"));
|
|
28
32
|
var sinon_chai_1 = __importDefault(require("sinon-chai"));
|
|
33
|
+
var type_detect_1 = __importDefault(require("type-detect"));
|
|
29
34
|
var ConsoleType_1 = require("./types/ConsoleType");
|
|
30
35
|
chai.should();
|
|
31
36
|
chai.use(sinon_chai_1.default);
|
|
@@ -34,21 +39,15 @@ function failOnConsoleError(config) {
|
|
|
34
39
|
var spies;
|
|
35
40
|
(0, exports.validateConfig)(config);
|
|
36
41
|
config = (0, exports.createConfig)(config);
|
|
37
|
-
Cypress.on('window:before:load', function (
|
|
38
|
-
spies = (0, exports.createSpies)(config,
|
|
39
|
-
});
|
|
40
|
-
Cypress.on('command:enqueued', function () {
|
|
41
|
-
if (spies) {
|
|
42
|
-
spies = (0, exports.resetSpies)(spies);
|
|
43
|
-
}
|
|
42
|
+
Cypress.on('window:before:load', function (window) {
|
|
43
|
+
spies = (0, exports.createSpies)(config, window.console);
|
|
44
44
|
});
|
|
45
45
|
Cypress.on('command:end', function () {
|
|
46
|
-
if (!spies
|
|
46
|
+
if (!spies)
|
|
47
47
|
return;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
chai.expect(spy).to.have.callCount(0);
|
|
48
|
+
var errorMessage = (0, exports.getIncludedCall)(spies, config);
|
|
49
|
+
if (errorMessage) {
|
|
50
|
+
chai.expect(errorMessage, 'console match found').to.be.undefined;
|
|
52
51
|
}
|
|
53
52
|
});
|
|
54
53
|
}
|
|
@@ -57,25 +56,29 @@ var validateConfig = function (config) {
|
|
|
57
56
|
if (config.excludeMessages) {
|
|
58
57
|
chai.expect(config.excludeMessages).not.to.be.empty;
|
|
59
58
|
config.excludeMessages.forEach(function (_excludeMessage) {
|
|
60
|
-
chai.expect(_excludeMessage).to.be.
|
|
61
|
-
|
|
59
|
+
chai.expect((0, type_detect_1.default)(_excludeMessage)).to.be.oneOf([
|
|
60
|
+
'string',
|
|
61
|
+
'RegExp',
|
|
62
|
+
]);
|
|
63
|
+
chai.expect(_excludeMessage.toString()).to.have.length.above(0);
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
66
|
if (config.includeConsoleTypes) {
|
|
65
67
|
chai.expect(config.includeConsoleTypes).not.to.be.empty;
|
|
66
68
|
config.includeConsoleTypes.forEach(function (_includeConsoleType) {
|
|
67
|
-
|
|
69
|
+
chai.expect((0, ConsoleType_1.someConsoleType)(_includeConsoleType), "includeConsoleTypes '".concat(_includeConsoleType, "' is an unknown ConsoleType")).to.be.true;
|
|
68
70
|
});
|
|
69
71
|
}
|
|
70
72
|
};
|
|
71
73
|
exports.validateConfig = validateConfig;
|
|
72
74
|
var createConfig = function (config) {
|
|
73
|
-
var _a;
|
|
75
|
+
var _a, _b;
|
|
74
76
|
return ({
|
|
75
77
|
excludeMessages: config.excludeMessages,
|
|
76
78
|
includeConsoleTypes: ((_a = config.includeConsoleTypes) === null || _a === void 0 ? void 0 : _a.length)
|
|
77
79
|
? config.includeConsoleTypes
|
|
78
80
|
: [ConsoleType_1.ConsoleType.ERROR],
|
|
81
|
+
cypressLog: (_b = config.cypressLog) !== null && _b !== void 0 ? _b : false,
|
|
79
82
|
});
|
|
80
83
|
};
|
|
81
84
|
exports.createConfig = createConfig;
|
|
@@ -89,43 +92,69 @@ var createSpies = function (config, console) {
|
|
|
89
92
|
return spies;
|
|
90
93
|
};
|
|
91
94
|
exports.createSpies = createSpies;
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
var getIncludedCall = function (spies, config) {
|
|
96
|
+
var errorMessage;
|
|
97
|
+
Array.from(spies.values()).forEach(function (spy) {
|
|
98
|
+
if (!spy.called)
|
|
99
|
+
return;
|
|
100
|
+
var includedCall = (0, exports.findIncludedCall)(spy, config);
|
|
101
|
+
if (includedCall !== undefined) {
|
|
102
|
+
errorMessage = includedCall;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return errorMessage;
|
|
101
106
|
};
|
|
102
|
-
exports.
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
exports.getIncludedCall = getIncludedCall;
|
|
108
|
+
var findIncludedCall = function (spy, config) {
|
|
109
|
+
var errorMessages = spy.args.map(function (call) { return (0, exports.callToString)(call); });
|
|
110
|
+
if (config.excludeMessages === undefined) {
|
|
111
|
+
return errorMessages[0];
|
|
106
112
|
}
|
|
107
|
-
return
|
|
108
|
-
|
|
113
|
+
return errorMessages.find(function (_errorMessage) {
|
|
114
|
+
var _isErrorMessageExcluded = config.excludeMessages.some(function (_excludeMessage) {
|
|
115
|
+
return (0, exports.isErrorMessageExcluded)(_errorMessage, _excludeMessage, config.cypressLog);
|
|
116
|
+
});
|
|
117
|
+
if (config.cypressLog === true) {
|
|
118
|
+
(0, exports.cypressLogger)('errorMessage_excluded', {
|
|
119
|
+
_errorMessage: _errorMessage,
|
|
120
|
+
_isErrorMessageExcluded: _isErrorMessageExcluded,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return !_isErrorMessageExcluded;
|
|
109
124
|
});
|
|
110
125
|
};
|
|
111
|
-
exports.
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
exports.findIncludedCall = findIncludedCall;
|
|
127
|
+
var isErrorMessageExcluded = function (errorMessage, excludeMessage, cypressLog) {
|
|
128
|
+
var _a;
|
|
129
|
+
var match = (((_a = errorMessage.match(excludeMessage)) === null || _a === void 0 ? void 0 : _a.length) || 0) > 0;
|
|
130
|
+
if (cypressLog) {
|
|
131
|
+
(0, exports.cypressLogger)('errorMessage_excludeMessage_match', {
|
|
132
|
+
errorMessage: errorMessage,
|
|
133
|
+
excludeMessage: excludeMessage,
|
|
134
|
+
match: match,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return match;
|
|
118
138
|
};
|
|
119
|
-
exports.
|
|
139
|
+
exports.isErrorMessageExcluded = isErrorMessageExcluded;
|
|
120
140
|
var callToString = function (calls) {
|
|
121
141
|
return calls
|
|
122
142
|
.reduce(function (previousValue, currentValue) {
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return previousValue
|
|
143
|
+
var _a;
|
|
144
|
+
var _value = (_a = currentValue === null || currentValue === void 0 ? void 0 : currentValue.stack) !== null && _a !== void 0 ? _a : currentValue;
|
|
145
|
+
var _currentValue = typeof _value !== 'string' ? JSON.stringify(_value) : _value;
|
|
146
|
+
return "".concat(previousValue, " ").concat(_currentValue);
|
|
127
147
|
}, '')
|
|
128
148
|
.trim();
|
|
129
149
|
};
|
|
130
150
|
exports.callToString = callToString;
|
|
151
|
+
var cypressLogger = function (name, message) {
|
|
152
|
+
Cypress.log({
|
|
153
|
+
name: name,
|
|
154
|
+
displayName: name,
|
|
155
|
+
message: JSON.stringify(message),
|
|
156
|
+
consoleProps: function () { return message; },
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
exports.cypressLogger = cypressLogger;
|
|
131
160
|
exports.consoleType = ConsoleType_1.ConsoleType;
|
package/dist/types/Config.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cypress-fail-on-console-error",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "fail cypress test on console error",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"dist/**/*"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "
|
|
12
|
-
"prettier": "prettier --write
|
|
11
|
+
"build": "npx rimraf dist/ && tsc",
|
|
12
|
+
"prettier": "prettier --write \"**/*\"",
|
|
13
13
|
"test": "npm run test:ut && npm run test:it",
|
|
14
14
|
"test:ut": "ts-mocha test/unitTest.ts",
|
|
15
15
|
"test:ut:debug": "ts-mocha --inspect-brk test/unitTest.ts",
|
|
16
16
|
"test:it": "ts-mocha test/integrationTest.ts --timeout 60000",
|
|
17
17
|
"test:it:debug": "cypress open",
|
|
18
|
-
"verify": "npm run build && npm run prettier && npm run test",
|
|
19
|
-
"ci:prettier": "prettier --check
|
|
18
|
+
"verify": "npm run build && npm run ci:prettier && npm run test",
|
|
19
|
+
"ci:prettier": "prettier --check \"**/*\""
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
@@ -35,20 +35,22 @@
|
|
|
35
35
|
"homepage": "https://github.com/nils-hoyer/cypress-fail-on-console-error#readme",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"chai": "^4.3.4",
|
|
38
|
-
"sinon": "^
|
|
38
|
+
"sinon": "^14.0.0",
|
|
39
39
|
"sinon-chai": "^3.7.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/chai": "4.
|
|
42
|
+
"@types/chai": "4.3.1",
|
|
43
43
|
"@types/expect": "24.3.0",
|
|
44
|
-
"@types/mocha": "9.
|
|
45
|
-
"@types/sinon": "10.0.
|
|
46
|
-
"@types/sinon-chai": "3.2.
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"prettier
|
|
51
|
-
"
|
|
52
|
-
"
|
|
44
|
+
"@types/mocha": "9.1.1",
|
|
45
|
+
"@types/sinon": "10.0.12",
|
|
46
|
+
"@types/sinon-chai": "3.2.8",
|
|
47
|
+
"@types/type-detect": "^4.0.1",
|
|
48
|
+
"cypress": "10.3.0",
|
|
49
|
+
"mocha": "10.0.0",
|
|
50
|
+
"prettier": "2.7.1",
|
|
51
|
+
"prettier-plugin-organize-imports": "3.0.0",
|
|
52
|
+
"rimraf": "3.0.2",
|
|
53
|
+
"ts-mocha": "10.0.0",
|
|
54
|
+
"typescript": "4.7.4"
|
|
53
55
|
}
|
|
54
56
|
}
|