cypress-fail-on-console-error 2.0.6 → 2.1.3
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 +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -16
- package/package.json +21 -18
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). It will automatically fail the executed cypress test as soon as the error function is executed once.
|
|
4
4
|
|
|
5
5
|
### Installation
|
|
6
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ export declare const someSpyCalled: (spies: Map<ConsoleType, sinon.SinonSpy>) =>
|
|
|
10
10
|
export declare const getIncludedSpy: (spies: Map<ConsoleType, sinon.SinonSpy>, config: Config) => sinon.SinonSpy | undefined;
|
|
11
11
|
export declare const someIncludedCall: (spy: sinon.SinonSpy, config: Config) => boolean;
|
|
12
12
|
export declare const isExcludedMessage: (excludeMessages: string[], message: string) => boolean;
|
|
13
|
+
export declare const callToString: (calls: any[]) => string;
|
|
13
14
|
export declare const consoleType: typeof ConsoleType;
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.consoleType = exports.isExcludedMessage = exports.someIncludedCall = exports.getIncludedSpy = exports.someSpyCalled = exports.resetSpies = exports.createSpies = exports.createConfig = exports.validateConfig = void 0;
|
|
25
|
+
exports.consoleType = exports.callToString = exports.isExcludedMessage = exports.someIncludedCall = exports.getIncludedSpy = exports.someSpyCalled = exports.resetSpies = exports.createSpies = exports.createConfig = exports.validateConfig = void 0;
|
|
26
26
|
var chai = __importStar(require("chai"));
|
|
27
27
|
var sinon = __importStar(require("sinon"));
|
|
28
28
|
var sinon_chai_1 = __importDefault(require("sinon-chai"));
|
|
@@ -32,21 +32,21 @@ chai.use(sinon_chai_1.default);
|
|
|
32
32
|
function failOnConsoleError(config) {
|
|
33
33
|
if (config === void 0) { config = {}; }
|
|
34
34
|
var spies;
|
|
35
|
-
exports.validateConfig(config);
|
|
36
|
-
config = exports.createConfig(config);
|
|
35
|
+
(0, exports.validateConfig)(config);
|
|
36
|
+
config = (0, exports.createConfig)(config);
|
|
37
37
|
Cypress.on('window:before:load', function (win) {
|
|
38
|
-
spies = exports.createSpies(config, win.console);
|
|
38
|
+
spies = (0, exports.createSpies)(config, win.console);
|
|
39
39
|
});
|
|
40
40
|
Cypress.on('command:enqueued', function () {
|
|
41
41
|
if (spies) {
|
|
42
|
-
spies = exports.resetSpies(spies);
|
|
42
|
+
spies = (0, exports.resetSpies)(spies);
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
Cypress.on('command:end', function () {
|
|
46
|
-
if (!spies || !exports.someSpyCalled(spies)) {
|
|
46
|
+
if (!spies || !(0, exports.someSpyCalled)(spies)) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
var spy = exports.getIncludedSpy(spies, config);
|
|
49
|
+
var spy = (0, exports.getIncludedSpy)(spies, config);
|
|
50
50
|
if (spy) {
|
|
51
51
|
chai.expect(spy).to.have.callCount(0);
|
|
52
52
|
}
|
|
@@ -64,18 +64,19 @@ var validateConfig = function (config) {
|
|
|
64
64
|
if (config.includeConsoleTypes) {
|
|
65
65
|
chai.expect(config.includeConsoleTypes).not.to.be.empty;
|
|
66
66
|
config.includeConsoleTypes.forEach(function (_includeConsoleType) {
|
|
67
|
-
chai.expect(ConsoleType_1.someConsoleType(_includeConsoleType), "includeConsoleTypes '" + _includeConsoleType + "' is an unknown ConsoleType").to.be.true;
|
|
67
|
+
return chai.expect((0, ConsoleType_1.someConsoleType)(_includeConsoleType), "includeConsoleTypes '" + _includeConsoleType + "' is an unknown ConsoleType").to.be.true;
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
exports.validateConfig = validateConfig;
|
|
72
72
|
var createConfig = function (config) {
|
|
73
73
|
var _a;
|
|
74
|
-
return {
|
|
74
|
+
return ({
|
|
75
75
|
excludeMessages: config.excludeMessages,
|
|
76
|
-
includeConsoleTypes: ((_a = config.includeConsoleTypes) === null || _a === void 0 ? void 0 : _a.length)
|
|
76
|
+
includeConsoleTypes: ((_a = config.includeConsoleTypes) === null || _a === void 0 ? void 0 : _a.length)
|
|
77
|
+
? config.includeConsoleTypes
|
|
77
78
|
: [ConsoleType_1.ConsoleType.ERROR],
|
|
78
|
-
};
|
|
79
|
+
});
|
|
79
80
|
};
|
|
80
81
|
exports.createConfig = createConfig;
|
|
81
82
|
var createSpies = function (config, console) {
|
|
@@ -93,12 +94,10 @@ var resetSpies = function (spies) {
|
|
|
93
94
|
return spies;
|
|
94
95
|
};
|
|
95
96
|
exports.resetSpies = resetSpies;
|
|
96
|
-
var someSpyCalled = function (spies) {
|
|
97
|
-
return Array.from(spies.values()).some(function (value) { return value.called; });
|
|
98
|
-
};
|
|
97
|
+
var someSpyCalled = function (spies) { return Array.from(spies.values()).some(function (value) { return value.called; }); };
|
|
99
98
|
exports.someSpyCalled = someSpyCalled;
|
|
100
99
|
var getIncludedSpy = function (spies, config) {
|
|
101
|
-
return Array.from(spies.values()).find(function (spy) { return spy.called && exports.someIncludedCall(spy, config); });
|
|
100
|
+
return Array.from(spies.values()).find(function (spy) { return spy.called && (0, exports.someIncludedCall)(spy, config); });
|
|
102
101
|
};
|
|
103
102
|
exports.getIncludedSpy = getIncludedSpy;
|
|
104
103
|
var someIncludedCall = function (spy, config) {
|
|
@@ -106,7 +105,7 @@ var someIncludedCall = function (spy, config) {
|
|
|
106
105
|
return true;
|
|
107
106
|
}
|
|
108
107
|
return spy.args.some(function (call) {
|
|
109
|
-
return !exports.isExcludedMessage(config.excludeMessages,
|
|
108
|
+
return !(0, exports.isExcludedMessage)(config.excludeMessages, (0, exports.callToString)(call));
|
|
110
109
|
});
|
|
111
110
|
};
|
|
112
111
|
exports.someIncludedCall = someIncludedCall;
|
|
@@ -118,4 +117,15 @@ var isExcludedMessage = function (excludeMessages, message) {
|
|
|
118
117
|
});
|
|
119
118
|
};
|
|
120
119
|
exports.isExcludedMessage = isExcludedMessage;
|
|
120
|
+
var callToString = function (calls) {
|
|
121
|
+
return calls
|
|
122
|
+
.reduce(function (previousValue, currentValue) {
|
|
123
|
+
var _currentValue = typeof currentValue === 'string'
|
|
124
|
+
? currentValue
|
|
125
|
+
: (currentValue === null || currentValue === void 0 ? void 0 : currentValue.message) || JSON.stringify(currentValue);
|
|
126
|
+
return previousValue + " " + _currentValue;
|
|
127
|
+
}, '')
|
|
128
|
+
.trim();
|
|
129
|
+
};
|
|
130
|
+
exports.callToString = callToString;
|
|
121
131
|
exports.consoleType = ConsoleType_1.ConsoleType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cypress-fail-on-console-error",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "fail cypress test on console error",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,10 +10,13 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "rm -rf dist/ && tsc",
|
|
12
12
|
"prettier": "prettier --write '**/*'",
|
|
13
|
-
"test": "
|
|
13
|
+
"test": "npm run test:ut && npm run test:it",
|
|
14
|
+
"test:ut": "ts-mocha test/unitTest.ts",
|
|
15
|
+
"test:ut:debug": "ts-mocha --inspect-brk test/unitTest.ts",
|
|
16
|
+
"test:it": "ts-mocha test/integrationTest.ts --timeout 60000",
|
|
17
|
+
"test:it:debug": "cypress open",
|
|
14
18
|
"verify": "npm run build && npm run prettier && npm run test",
|
|
15
|
-
"
|
|
16
|
-
"debug:it": "cypress open"
|
|
19
|
+
"ci:prettier": "prettier --check '**/*'"
|
|
17
20
|
},
|
|
18
21
|
"repository": {
|
|
19
22
|
"type": "git",
|
|
@@ -31,21 +34,21 @@
|
|
|
31
34
|
},
|
|
32
35
|
"homepage": "https://github.com/nils-hoyer/cypress-fail-on-console-error#readme",
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"chai": "^4.3.
|
|
35
|
-
"sinon": "^
|
|
36
|
-
"sinon-chai": "^3.
|
|
37
|
+
"chai": "^4.3.4",
|
|
38
|
+
"sinon": "^12.0.0",
|
|
39
|
+
"sinon-chai": "^3.7.0"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
|
-
"@types/chai": "
|
|
40
|
-
"@types/expect": "
|
|
41
|
-
"@types/mocha": "
|
|
42
|
-
"@types/sinon": "
|
|
43
|
-
"@types/sinon-chai": "
|
|
44
|
-
"cypress": "
|
|
45
|
-
"mocha": "
|
|
46
|
-
"prettier": "
|
|
47
|
-
"prettier-plugin-organize-imports": "
|
|
48
|
-
"ts-mocha": "
|
|
49
|
-
"typescript": "
|
|
42
|
+
"@types/chai": "4.2.22",
|
|
43
|
+
"@types/expect": "24.3.0",
|
|
44
|
+
"@types/mocha": "9.0.0",
|
|
45
|
+
"@types/sinon": "10.0.6",
|
|
46
|
+
"@types/sinon-chai": "3.2.6",
|
|
47
|
+
"cypress": "9.1.0",
|
|
48
|
+
"mocha": "9.1.3",
|
|
49
|
+
"prettier": "2.5.0",
|
|
50
|
+
"prettier-plugin-organize-imports": "2.3.4",
|
|
51
|
+
"ts-mocha": "8.0.0",
|
|
52
|
+
"typescript": "4.5.2"
|
|
50
53
|
}
|
|
51
54
|
}
|