cypress-fail-on-console-error 3.1.0 → 3.2.2
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 +17 -9
- package/dist/index.d.ts +8 -6
- package/dist/index.js +20 -11
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install cypress-fail-on-console-error --save-dev
|
|
|
10
10
|
|
|
11
11
|
### Usage
|
|
12
12
|
|
|
13
|
-
`cypress/support/
|
|
13
|
+
`cypress/support/e2e.js`
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
16
|
import failOnConsoleError from 'cypress-fail-on-console-error';
|
|
@@ -20,19 +20,18 @@ failOnConsoleError();
|
|
|
20
20
|
|
|
21
21
|
### Config (optional)
|
|
22
22
|
|
|
23
|
-
| Parameter | Default | Description
|
|
24
|
-
|
|
|
25
|
-
| `excludeMessages` | `undefined`
|
|
26
|
-
| `includeConsoleTypes` | `[consoleType.ERROR]` |
|
|
27
|
-
| `cypressLog` | `false` |
|
|
23
|
+
| Parameter | Default | <div style="width:300px">Description</div> |
|
|
24
|
+
|--- |--- |--- |
|
|
25
|
+
| `excludeMessages` | `undefined` | 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
|
+
| `includeConsoleTypes` | `[consoleType.ERROR]` | Define console types for observation
|
|
27
|
+
| `cypressLog` | `false` | Enable debug logs for errorMessage_excludeMessage_match and errorMessage_excluded to cypress runner
|
|
28
28
|
|
|
29
29
|
<br/>
|
|
30
30
|
|
|
31
|
-
<!-- prettier-ignore -->
|
|
32
31
|
```js
|
|
33
|
-
import failOnConsoleError, { consoleType } from 'cypress-fail-on-console-error';
|
|
32
|
+
import failOnConsoleError, { consoleType, Config } from 'cypress-fail-on-console-error';
|
|
34
33
|
|
|
35
|
-
const config = {
|
|
34
|
+
const config: Config = {
|
|
36
35
|
excludeMessages: ['foo', /^some bar-regex.*/],
|
|
37
36
|
includeConsoleTypes: [
|
|
38
37
|
consoleType.ERROR,
|
|
@@ -47,6 +46,7 @@ failOnConsoleError(config);
|
|
|
47
46
|
// excludeMessages[0] matches example console message 'this is a foo message'
|
|
48
47
|
// excludeMessages[1] matches example console message 'some bar-regex message'
|
|
49
48
|
// includeConsoleTypes observe console types ERROR, WARN and INFO
|
|
49
|
+
//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
|
|
@@ -60,3 +60,11 @@ failOnConsoleError({
|
|
|
60
60
|
// 1 = WARN
|
|
61
61
|
// 2 = ERROR
|
|
62
62
|
```
|
|
63
|
+
|
|
64
|
+
### Debugging
|
|
65
|
+
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
|
+

|
|
67
|
+
|
|
68
|
+
### Contributing
|
|
69
|
+
1. Create an project issue with proper description and expected behaviour
|
|
70
|
+
2. Provide a PR with implementation and tests. Command `npm run verify` have to pass locally
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
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(
|
|
4
|
+
export default function failOnConsoleError(_config?: Config): void;
|
|
5
5
|
export declare const validateConfig: (config: Config) => void;
|
|
6
|
-
export declare const createConfig: (config: Config) => Config
|
|
7
|
-
export declare const createSpies: (config: Config
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
6
|
+
export declare const createConfig: (config: Config) => Required<Config>;
|
|
7
|
+
export declare const createSpies: (config: Required<Config>, console: Console) => Map<ConsoleType, sinon.SinonSpy>;
|
|
8
|
+
export declare const resetSpies: (spies: Map<ConsoleType, sinon.SinonSpy>) => Map<ConsoleType, sinon.SinonSpy>;
|
|
9
|
+
export declare const getIncludedCall: (spies: Map<ConsoleType, sinon.SinonSpy>, config: Required<Config>) => string | undefined;
|
|
10
|
+
export declare const findIncludedCall: (spy: sinon.SinonSpy, config: Required<Config>) => string | undefined;
|
|
10
11
|
export declare const isErrorMessageExcluded: (errorMessage: string, excludeMessage: string, cypressLog: boolean) => boolean;
|
|
11
12
|
export declare const callToString: (calls: any[]) => string;
|
|
12
13
|
export declare const cypressLogger: (name: string, message: any) => void;
|
|
13
|
-
export
|
|
14
|
+
export { Config } from './types/Config';
|
|
15
|
+
export { ConsoleType as consoleType } from './types/ConsoleType';
|
package/dist/index.js
CHANGED
|
@@ -26,19 +26,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.consoleType = exports.cypressLogger = exports.callToString = exports.isErrorMessageExcluded = exports.findIncludedCall = exports.getIncludedCall = exports.createSpies = exports.createConfig = exports.validateConfig = void 0;
|
|
29
|
+
exports.consoleType = exports.cypressLogger = exports.callToString = exports.isErrorMessageExcluded = exports.findIncludedCall = exports.getIncludedCall = exports.resetSpies = exports.createSpies = exports.createConfig = exports.validateConfig = void 0;
|
|
30
30
|
var chai = __importStar(require("chai"));
|
|
31
|
+
var chai_1 = require("chai");
|
|
32
|
+
var os_1 = require("os");
|
|
31
33
|
var sinon = __importStar(require("sinon"));
|
|
32
34
|
var sinon_chai_1 = __importDefault(require("sinon-chai"));
|
|
33
35
|
var type_detect_1 = __importDefault(require("type-detect"));
|
|
34
36
|
var ConsoleType_1 = require("./types/ConsoleType");
|
|
35
37
|
chai.should();
|
|
36
38
|
chai.use(sinon_chai_1.default);
|
|
37
|
-
function failOnConsoleError(
|
|
38
|
-
if (
|
|
39
|
+
function failOnConsoleError(_config) {
|
|
40
|
+
if (_config === void 0) { _config = {}; }
|
|
39
41
|
var spies;
|
|
40
|
-
(0, exports.validateConfig)(
|
|
41
|
-
config = (0, exports.createConfig)(
|
|
42
|
+
(0, exports.validateConfig)(_config);
|
|
43
|
+
var config = (0, exports.createConfig)(_config);
|
|
42
44
|
Cypress.on('window:before:load', function (window) {
|
|
43
45
|
spies = (0, exports.createSpies)(config, window.console);
|
|
44
46
|
});
|
|
@@ -46,8 +48,9 @@ function failOnConsoleError(config) {
|
|
|
46
48
|
if (!spies)
|
|
47
49
|
return;
|
|
48
50
|
var errorMessage = (0, exports.getIncludedCall)(spies, config);
|
|
51
|
+
spies = (0, exports.resetSpies)(spies);
|
|
49
52
|
if (errorMessage) {
|
|
50
|
-
|
|
53
|
+
throw new chai_1.AssertionError("cypress-fail-on-console-error: ".concat(os_1.EOL, " ").concat(errorMessage));
|
|
51
54
|
}
|
|
52
55
|
});
|
|
53
56
|
}
|
|
@@ -72,13 +75,13 @@ var validateConfig = function (config) {
|
|
|
72
75
|
};
|
|
73
76
|
exports.validateConfig = validateConfig;
|
|
74
77
|
var createConfig = function (config) {
|
|
75
|
-
var _a, _b;
|
|
78
|
+
var _a, _b, _c;
|
|
76
79
|
return ({
|
|
77
|
-
excludeMessages: config.excludeMessages,
|
|
78
|
-
includeConsoleTypes: ((
|
|
80
|
+
excludeMessages: (_a = config.excludeMessages) !== null && _a !== void 0 ? _a : [],
|
|
81
|
+
includeConsoleTypes: ((_b = config.includeConsoleTypes) === null || _b === void 0 ? void 0 : _b.length)
|
|
79
82
|
? config.includeConsoleTypes
|
|
80
83
|
: [ConsoleType_1.ConsoleType.ERROR],
|
|
81
|
-
cypressLog: (
|
|
84
|
+
cypressLog: (_c = config.cypressLog) !== null && _c !== void 0 ? _c : false,
|
|
82
85
|
});
|
|
83
86
|
};
|
|
84
87
|
exports.createConfig = createConfig;
|
|
@@ -92,6 +95,11 @@ var createSpies = function (config, console) {
|
|
|
92
95
|
return spies;
|
|
93
96
|
};
|
|
94
97
|
exports.createSpies = createSpies;
|
|
98
|
+
var resetSpies = function (spies) {
|
|
99
|
+
spies.forEach(function (_spy) { return _spy.resetHistory(); });
|
|
100
|
+
return spies;
|
|
101
|
+
};
|
|
102
|
+
exports.resetSpies = resetSpies;
|
|
95
103
|
var getIncludedCall = function (spies, config) {
|
|
96
104
|
var errorMessage;
|
|
97
105
|
Array.from(spies.values()).forEach(function (spy) {
|
|
@@ -157,4 +165,5 @@ var cypressLogger = function (name, message) {
|
|
|
157
165
|
});
|
|
158
166
|
};
|
|
159
167
|
exports.cypressLogger = cypressLogger;
|
|
160
|
-
|
|
168
|
+
var ConsoleType_2 = require("./types/ConsoleType");
|
|
169
|
+
Object.defineProperty(exports, "consoleType", { enumerable: true, get: function () { return ConsoleType_2.ConsoleType; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cypress-fail-on-console-error",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.2",
|
|
4
4
|
"description": "fail cypress test on console error",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"sinon-chai": "^3.7.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/chai": "4.3.
|
|
42
|
+
"@types/chai": "4.3.3",
|
|
43
43
|
"@types/expect": "24.3.0",
|
|
44
44
|
"@types/mocha": "9.1.1",
|
|
45
|
-
"@types/sinon": "10.0.
|
|
45
|
+
"@types/sinon": "10.0.13",
|
|
46
46
|
"@types/sinon-chai": "3.2.8",
|
|
47
|
-
"@types/type-detect": "
|
|
48
|
-
"cypress": "10.
|
|
47
|
+
"@types/type-detect": "4.0.1",
|
|
48
|
+
"cypress": "10.7.0",
|
|
49
49
|
"mocha": "10.0.0",
|
|
50
50
|
"prettier": "2.7.1",
|
|
51
|
-
"prettier-plugin-organize-imports": "3.
|
|
51
|
+
"prettier-plugin-organize-imports": "3.1.1",
|
|
52
52
|
"rimraf": "3.0.2",
|
|
53
53
|
"ts-mocha": "10.0.0",
|
|
54
|
-
"typescript": "4.
|
|
54
|
+
"typescript": "4.8.3"
|
|
55
55
|
}
|
|
56
56
|
}
|