cypress-fail-on-console-error 3.0.0 → 3.2.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/README.md +16 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +16 -4
- package/dist/types/Config.d.ts +1 -1
- package/package.json +9 -8
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,20 +20,19 @@ 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
32
|
import failOnConsoleError, { consoleType } from 'cypress-fail-on-console-error';
|
|
34
33
|
|
|
35
34
|
const config = {
|
|
36
|
-
excludeMessages: ['foo',
|
|
35
|
+
excludeMessages: ['foo', /^some bar-regex.*/],
|
|
37
36
|
includeConsoleTypes: [
|
|
38
37
|
consoleType.ERROR,
|
|
39
38
|
consoleType.WARN,
|
|
@@ -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
|
@@ -5,6 +5,7 @@ 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 resetSpies: (spies: Map<ConsoleType, sinon.SinonSpy>) => Map<ConsoleType, sinon.SinonSpy>;
|
|
8
9
|
export declare const getIncludedCall: (spies: Map<ConsoleType, sinon.SinonSpy>, config: Config) => string | undefined;
|
|
9
10
|
export declare const findIncludedCall: (spy: sinon.SinonSpy, config: Config) => string | undefined;
|
|
10
11
|
export declare const isErrorMessageExcluded: (errorMessage: string, excludeMessage: string, cypressLog: boolean) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -26,10 +26,13 @@ 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"));
|
|
35
|
+
var type_detect_1 = __importDefault(require("type-detect"));
|
|
33
36
|
var ConsoleType_1 = require("./types/ConsoleType");
|
|
34
37
|
chai.should();
|
|
35
38
|
chai.use(sinon_chai_1.default);
|
|
@@ -45,8 +48,9 @@ function failOnConsoleError(config) {
|
|
|
45
48
|
if (!spies)
|
|
46
49
|
return;
|
|
47
50
|
var errorMessage = (0, exports.getIncludedCall)(spies, config);
|
|
51
|
+
spies = (0, exports.resetSpies)(spies);
|
|
48
52
|
if (errorMessage) {
|
|
49
|
-
|
|
53
|
+
throw new chai_1.AssertionError("cypress-fail-on-console-error: ".concat(os_1.EOL, " ").concat(errorMessage));
|
|
50
54
|
}
|
|
51
55
|
});
|
|
52
56
|
}
|
|
@@ -55,8 +59,11 @@ var validateConfig = function (config) {
|
|
|
55
59
|
if (config.excludeMessages) {
|
|
56
60
|
chai.expect(config.excludeMessages).not.to.be.empty;
|
|
57
61
|
config.excludeMessages.forEach(function (_excludeMessage) {
|
|
58
|
-
chai.expect(_excludeMessage).to.be.
|
|
59
|
-
|
|
62
|
+
chai.expect((0, type_detect_1.default)(_excludeMessage)).to.be.oneOf([
|
|
63
|
+
'string',
|
|
64
|
+
'RegExp',
|
|
65
|
+
]);
|
|
66
|
+
chai.expect(_excludeMessage.toString()).to.have.length.above(0);
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
if (config.includeConsoleTypes) {
|
|
@@ -88,6 +95,11 @@ var createSpies = function (config, console) {
|
|
|
88
95
|
return spies;
|
|
89
96
|
};
|
|
90
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;
|
|
91
103
|
var getIncludedCall = function (spies, config) {
|
|
92
104
|
var errorMessage;
|
|
93
105
|
Array.from(spies.values()).forEach(function (spy) {
|
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.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "fail cypress test on console error",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
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",
|
|
18
|
+
"verify": "npm run build && npm run ci:prettier && npm run test",
|
|
19
19
|
"ci:prettier": "prettier --check \"**/*\""
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
@@ -42,14 +42,15 @@
|
|
|
42
42
|
"@types/chai": "4.3.1",
|
|
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
|
-
"
|
|
47
|
+
"@types/type-detect": "4.0.1",
|
|
48
|
+
"cypress": "10.3.1",
|
|
48
49
|
"mocha": "10.0.0",
|
|
49
|
-
"prettier": "2.
|
|
50
|
-
"prettier-plugin-organize-imports": "
|
|
50
|
+
"prettier": "2.7.1",
|
|
51
|
+
"prettier-plugin-organize-imports": "3.0.0",
|
|
52
|
+
"rimraf": "3.0.2",
|
|
51
53
|
"ts-mocha": "10.0.0",
|
|
52
|
-
"typescript": "4.7.
|
|
53
|
-
"rimraf": "3.0.2"
|
|
54
|
+
"typescript": "4.7.4"
|
|
54
55
|
}
|
|
55
56
|
}
|