cypress-fail-on-console-error 2.1.2 → 3.0.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 +8 -6
- package/dist/index.d.ts +4 -5
- package/dist/index.js +70 -45
- package/dist/types/Config.d.ts +1 -0
- package/package.json +17 -16
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# cypress-fail-on-console-error
|
|
2
2
|
|
|
3
|
-
|
|
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 /> String parameter will be interpreted as regular expression |
|
|
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
|
|
|
@@ -38,6 +39,7 @@ const config = {
|
|
|
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,7 +26,7 @@ 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"));
|
|
@@ -32,23 +36,17 @@ chai.use(sinon_chai_1.default);
|
|
|
32
36
|
function failOnConsoleError(config) {
|
|
33
37
|
if (config === void 0) { config = {}; }
|
|
34
38
|
var spies;
|
|
35
|
-
exports.validateConfig(config);
|
|
36
|
-
config = exports.createConfig(config);
|
|
37
|
-
Cypress.on('window:before:load', function (
|
|
38
|
-
spies = exports.createSpies(config,
|
|
39
|
-
});
|
|
40
|
-
Cypress.on('command:enqueued', function () {
|
|
41
|
-
if (spies) {
|
|
42
|
-
spies = exports.resetSpies(spies);
|
|
43
|
-
}
|
|
39
|
+
(0, exports.validateConfig)(config);
|
|
40
|
+
config = (0, exports.createConfig)(config);
|
|
41
|
+
Cypress.on('window:before:load', function (window) {
|
|
42
|
+
spies = (0, exports.createSpies)(config, window.console);
|
|
44
43
|
});
|
|
45
44
|
Cypress.on('command:end', function () {
|
|
46
|
-
if (!spies
|
|
45
|
+
if (!spies)
|
|
47
46
|
return;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
chai.expect(spy).to.have.callCount(0);
|
|
47
|
+
var errorMessage = (0, exports.getIncludedCall)(spies, config);
|
|
48
|
+
if (errorMessage) {
|
|
49
|
+
chai.expect(errorMessage, 'console match found').to.be.undefined;
|
|
52
50
|
}
|
|
53
51
|
});
|
|
54
52
|
}
|
|
@@ -64,18 +62,19 @@ var validateConfig = function (config) {
|
|
|
64
62
|
if (config.includeConsoleTypes) {
|
|
65
63
|
chai.expect(config.includeConsoleTypes).not.to.be.empty;
|
|
66
64
|
config.includeConsoleTypes.forEach(function (_includeConsoleType) {
|
|
67
|
-
|
|
65
|
+
chai.expect((0, ConsoleType_1.someConsoleType)(_includeConsoleType), "includeConsoleTypes '".concat(_includeConsoleType, "' is an unknown ConsoleType")).to.be.true;
|
|
68
66
|
});
|
|
69
67
|
}
|
|
70
68
|
};
|
|
71
69
|
exports.validateConfig = validateConfig;
|
|
72
70
|
var createConfig = function (config) {
|
|
73
|
-
var _a;
|
|
71
|
+
var _a, _b;
|
|
74
72
|
return ({
|
|
75
73
|
excludeMessages: config.excludeMessages,
|
|
76
74
|
includeConsoleTypes: ((_a = config.includeConsoleTypes) === null || _a === void 0 ? void 0 : _a.length)
|
|
77
75
|
? config.includeConsoleTypes
|
|
78
76
|
: [ConsoleType_1.ConsoleType.ERROR],
|
|
77
|
+
cypressLog: (_b = config.cypressLog) !== null && _b !== void 0 ? _b : false,
|
|
79
78
|
});
|
|
80
79
|
};
|
|
81
80
|
exports.createConfig = createConfig;
|
|
@@ -89,43 +88,69 @@ var createSpies = function (config, console) {
|
|
|
89
88
|
return spies;
|
|
90
89
|
};
|
|
91
90
|
exports.createSpies = createSpies;
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
var getIncludedCall = function (spies, config) {
|
|
92
|
+
var errorMessage;
|
|
93
|
+
Array.from(spies.values()).forEach(function (spy) {
|
|
94
|
+
if (!spy.called)
|
|
95
|
+
return;
|
|
96
|
+
var includedCall = (0, exports.findIncludedCall)(spy, config);
|
|
97
|
+
if (includedCall !== undefined) {
|
|
98
|
+
errorMessage = includedCall;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return errorMessage;
|
|
101
102
|
};
|
|
102
|
-
exports.
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
exports.getIncludedCall = getIncludedCall;
|
|
104
|
+
var findIncludedCall = function (spy, config) {
|
|
105
|
+
var errorMessages = spy.args.map(function (call) { return (0, exports.callToString)(call); });
|
|
106
|
+
if (config.excludeMessages === undefined) {
|
|
107
|
+
return errorMessages[0];
|
|
106
108
|
}
|
|
107
|
-
return
|
|
108
|
-
|
|
109
|
+
return errorMessages.find(function (_errorMessage) {
|
|
110
|
+
var _isErrorMessageExcluded = config.excludeMessages.some(function (_excludeMessage) {
|
|
111
|
+
return (0, exports.isErrorMessageExcluded)(_errorMessage, _excludeMessage, config.cypressLog);
|
|
112
|
+
});
|
|
113
|
+
if (config.cypressLog === true) {
|
|
114
|
+
(0, exports.cypressLogger)('errorMessage_excluded', {
|
|
115
|
+
_errorMessage: _errorMessage,
|
|
116
|
+
_isErrorMessageExcluded: _isErrorMessageExcluded,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return !_isErrorMessageExcluded;
|
|
109
120
|
});
|
|
110
121
|
};
|
|
111
|
-
exports.
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
exports.findIncludedCall = findIncludedCall;
|
|
123
|
+
var isErrorMessageExcluded = function (errorMessage, excludeMessage, cypressLog) {
|
|
124
|
+
var _a;
|
|
125
|
+
var match = (((_a = errorMessage.match(excludeMessage)) === null || _a === void 0 ? void 0 : _a.length) || 0) > 0;
|
|
126
|
+
if (cypressLog) {
|
|
127
|
+
(0, exports.cypressLogger)('errorMessage_excludeMessage_match', {
|
|
128
|
+
errorMessage: errorMessage,
|
|
129
|
+
excludeMessage: excludeMessage,
|
|
130
|
+
match: match,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return match;
|
|
118
134
|
};
|
|
119
|
-
exports.
|
|
135
|
+
exports.isErrorMessageExcluded = isErrorMessageExcluded;
|
|
120
136
|
var callToString = function (calls) {
|
|
121
137
|
return calls
|
|
122
138
|
.reduce(function (previousValue, currentValue) {
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return previousValue
|
|
139
|
+
var _a;
|
|
140
|
+
var _value = (_a = currentValue === null || currentValue === void 0 ? void 0 : currentValue.stack) !== null && _a !== void 0 ? _a : currentValue;
|
|
141
|
+
var _currentValue = typeof _value !== 'string' ? JSON.stringify(_value) : _value;
|
|
142
|
+
return "".concat(previousValue, " ").concat(_currentValue);
|
|
127
143
|
}, '')
|
|
128
144
|
.trim();
|
|
129
145
|
};
|
|
130
146
|
exports.callToString = callToString;
|
|
147
|
+
var cypressLogger = function (name, message) {
|
|
148
|
+
Cypress.log({
|
|
149
|
+
name: name,
|
|
150
|
+
displayName: name,
|
|
151
|
+
message: JSON.stringify(message),
|
|
152
|
+
consoleProps: function () { return message; },
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
exports.cypressLogger = cypressLogger;
|
|
131
156
|
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.0.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
18
|
"verify": "npm run build && npm run prettier && npm run test",
|
|
19
|
-
"ci:prettier": "prettier --check
|
|
19
|
+
"ci:prettier": "prettier --check \"**/*\""
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
@@ -35,20 +35,21 @@
|
|
|
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": "
|
|
43
|
-
"@types/expect": "
|
|
44
|
-
"@types/mocha": "
|
|
45
|
-
"@types/sinon": "
|
|
46
|
-
"@types/sinon-chai": "
|
|
47
|
-
"cypress": "
|
|
48
|
-
"mocha": "
|
|
49
|
-
"prettier": "
|
|
50
|
-
"prettier-plugin-organize-imports": "
|
|
51
|
-
"ts-mocha": "
|
|
52
|
-
"typescript": "
|
|
42
|
+
"@types/chai": "4.3.1",
|
|
43
|
+
"@types/expect": "24.3.0",
|
|
44
|
+
"@types/mocha": "9.1.1",
|
|
45
|
+
"@types/sinon": "10.0.11",
|
|
46
|
+
"@types/sinon-chai": "3.2.8",
|
|
47
|
+
"cypress": "9.7.0",
|
|
48
|
+
"mocha": "10.0.0",
|
|
49
|
+
"prettier": "2.6.2",
|
|
50
|
+
"prettier-plugin-organize-imports": "2.3.4",
|
|
51
|
+
"ts-mocha": "10.0.0",
|
|
52
|
+
"typescript": "4.7.3",
|
|
53
|
+
"rimraf": "3.0.2"
|
|
53
54
|
}
|
|
54
55
|
}
|