cypress-fail-on-console-error 3.2.2 → 3.3.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 +25 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +27 -3
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ failOnConsoleError();
|
|
|
22
22
|
|
|
23
23
|
| Parameter | Default | <div style="width:300px">Description</div> |
|
|
24
24
|
|--- |--- |--- |
|
|
25
|
-
| `excludeMessages` | `
|
|
25
|
+
| `excludeMessages` | `[]` | Exclude console messages from throwing `AssertionError`. Regular expression parameters are acceptable. String parameters will be interpreted as regular expression. [String.match()](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/String/match) will be used for evaluation. Be sure to [escape the string regular expression](https://javascript.info/regexp-escaping) for special characters. When console message property `stacktrace` exists, then the whole stacktrace can be matched. |
|
|
26
26
|
| `includeConsoleTypes` | `[consoleType.ERROR]` | Define console types for observation
|
|
27
27
|
| `cypressLog` | `false` | Enable debug logs for errorMessage_excludeMessage_match and errorMessage_excluded to cypress runner
|
|
28
28
|
|
|
@@ -46,7 +46,7 @@ failOnConsoleError(config);
|
|
|
46
46
|
// excludeMessages[0] matches example console message 'this is a foo message'
|
|
47
47
|
// excludeMessages[1] matches example console message 'some bar-regex message'
|
|
48
48
|
// includeConsoleTypes observe console types ERROR, WARN and INFO
|
|
49
|
-
//debug information will be printed to the cypress runner
|
|
49
|
+
// cypressLog debug information will be printed to the cypress runner
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
Using Javascript, consoleType Enum can be parsed as number values
|
|
@@ -61,6 +61,29 @@ failOnConsoleError({
|
|
|
61
61
|
// 2 = ERROR
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
### Set config from cypress test
|
|
65
|
+
Use `failOnConsoleError` functions `getConfig()` and `setConfig()` with your own requirements. Detailed example implementation [cypress comands](https://github.com/nils-hoyer/cypress-fail-on-console-error/blob/56753cf3ff9222bb2c452304589ae0cfd5f85b46/cypress/support/e2e.ts#L14-L64) & [cypress test](https://github.com/nils-hoyer/cypress-fail-on-console-error/blob/123e251510045f2eb30c9ec2f6f247b77427d464/cypress/e2e/shouldFailOnConsoleErrorFromSetConfig.cy.ts#L1-L25). Note that the config will be resetted to initial config between tests.
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
const { getConfig, setConfig } = failOnConsoleError(config);
|
|
69
|
+
|
|
70
|
+
Cypress.Commands.addAll({
|
|
71
|
+
getExcludeMessages: () => cy.wrap(getConfig()),
|
|
72
|
+
setExcludeMessages: (excludeMessages: (string | RegExp)[]) =>
|
|
73
|
+
setConfig({ ...getConfig(), excludeMessages );
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
describe('example test', () => {
|
|
78
|
+
it('should set excluded messages', () => {
|
|
79
|
+
cy.setExcludeMessages(['foo', 'bar']).then(() => {
|
|
80
|
+
cy.visit('./cypress/fixtures/consoleError.html');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
|
|
64
87
|
### Debugging
|
|
65
88
|
When Cypress log is activated, debug information about the matching and exclude process are available from the cypress runner. As a plus, the generated error message string can be verified.
|
|
66
89
|

|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as sinon from 'sinon';
|
|
2
2
|
import { Config } from './types/Config';
|
|
3
3
|
import { ConsoleType } from './types/ConsoleType';
|
|
4
|
-
export default function failOnConsoleError(_config?: Config):
|
|
4
|
+
export default function failOnConsoleError(_config?: Config): {
|
|
5
|
+
getConfig: () => Required<Config> | undefined;
|
|
6
|
+
setConfig: (_config: Config) => void;
|
|
7
|
+
};
|
|
5
8
|
export declare const validateConfig: (config: Config) => void;
|
|
6
9
|
export declare const createConfig: (config: Config) => Required<Config>;
|
|
7
10
|
export declare const createSpies: (config: Required<Config>, console: Console) => Map<ConsoleType, sinon.SinonSpy>;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
14
|
if (k2 === undefined) k2 = k;
|
|
4
15
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -38,9 +49,16 @@ chai.should();
|
|
|
38
49
|
chai.use(sinon_chai_1.default);
|
|
39
50
|
function failOnConsoleError(_config) {
|
|
40
51
|
if (_config === void 0) { _config = {}; }
|
|
52
|
+
var originConfig;
|
|
53
|
+
var config;
|
|
41
54
|
var spies;
|
|
42
|
-
|
|
43
|
-
var
|
|
55
|
+
var getConfig = function () { return config; };
|
|
56
|
+
var setConfig = function (_config) {
|
|
57
|
+
(0, exports.validateConfig)(_config);
|
|
58
|
+
config = (0, exports.createConfig)(_config);
|
|
59
|
+
originConfig = originConfig !== null && originConfig !== void 0 ? originConfig : __assign({}, config);
|
|
60
|
+
};
|
|
61
|
+
setConfig(_config);
|
|
44
62
|
Cypress.on('window:before:load', function (window) {
|
|
45
63
|
spies = (0, exports.createSpies)(config, window.console);
|
|
46
64
|
});
|
|
@@ -53,11 +71,17 @@ function failOnConsoleError(_config) {
|
|
|
53
71
|
throw new chai_1.AssertionError("cypress-fail-on-console-error: ".concat(os_1.EOL, " ").concat(errorMessage));
|
|
54
72
|
}
|
|
55
73
|
});
|
|
74
|
+
Cypress.on('test:after:run', function () {
|
|
75
|
+
setConfig(originConfig);
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
getConfig: getConfig,
|
|
79
|
+
setConfig: setConfig,
|
|
80
|
+
};
|
|
56
81
|
}
|
|
57
82
|
exports.default = failOnConsoleError;
|
|
58
83
|
var validateConfig = function (config) {
|
|
59
84
|
if (config.excludeMessages) {
|
|
60
|
-
chai.expect(config.excludeMessages).not.to.be.empty;
|
|
61
85
|
config.excludeMessages.forEach(function (_excludeMessage) {
|
|
62
86
|
chai.expect((0, type_detect_1.default)(_excludeMessage)).to.be.oneOf([
|
|
63
87
|
'string',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cypress-fail-on-console-error",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "fail cypress test on console error",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,12 +10,11 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "npx rimraf dist/ && tsc",
|
|
12
12
|
"prettier": "prettier --write \"**/*\"",
|
|
13
|
+
"lint": "tsc --noEmit && tsc -p ./test/tsconfig.json && tsc -p ./cypress/tsconfig.json",
|
|
13
14
|
"test": "npm run test:ut && npm run test:it",
|
|
14
15
|
"test:ut": "ts-mocha test/unitTest.ts",
|
|
15
|
-
"test:ut:debug": "ts-mocha --inspect-brk test/unitTest.ts",
|
|
16
16
|
"test:it": "ts-mocha test/integrationTest.ts --timeout 60000",
|
|
17
|
-
"
|
|
18
|
-
"verify": "npm run build && npm run ci:prettier && npm run test",
|
|
17
|
+
"verify": "npm run build && npm run lint && npm run ci:prettier && npm run test",
|
|
19
18
|
"ci:prettier": "prettier --check \"**/*\""
|
|
20
19
|
},
|
|
21
20
|
"repository": {
|
|
@@ -45,7 +44,7 @@
|
|
|
45
44
|
"@types/sinon": "10.0.13",
|
|
46
45
|
"@types/sinon-chai": "3.2.8",
|
|
47
46
|
"@types/type-detect": "4.0.1",
|
|
48
|
-
"cypress": "10.
|
|
47
|
+
"cypress": "10.8.0",
|
|
49
48
|
"mocha": "10.0.0",
|
|
50
49
|
"prettier": "2.7.1",
|
|
51
50
|
"prettier-plugin-organize-imports": "3.1.1",
|