cypress-fail-on-console-error 4.0.2 → 5.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/dist/index.d.ts +8 -4
- package/dist/index.js +68 -120
- package/package.json +25 -18
- package/dist/types/Config.d.ts +0 -6
- package/dist/types/Config.js +0 -2
- package/dist/types/ConsoleType.d.ts +0 -1
- package/dist/types/ConsoleType.js +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import * as sinon from 'sinon';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type ConsoleType = 'error' | 'warn' | 'info';
|
|
3
|
+
interface Config {
|
|
4
|
+
consoleMessages?: (string | RegExp)[];
|
|
5
|
+
consoleTypes?: ConsoleType[];
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export { Config };
|
|
9
|
+
export { ConsoleType };
|
|
4
10
|
export default function failOnConsoleError(_config?: Config): {
|
|
5
11
|
getConfig: () => Required<Config> | undefined;
|
|
6
12
|
setConfig: (_config: Config) => void;
|
|
@@ -14,5 +20,3 @@ export declare const findConsoleMessageIncluded: (spy: sinon.SinonSpy, config: R
|
|
|
14
20
|
export declare const isConsoleMessageExcluded: (consoleMessage: string, configConsoleMessage: string | RegExp, debug: boolean) => boolean;
|
|
15
21
|
export declare const callToString: (calls: any[]) => string;
|
|
16
22
|
export declare const cypressLogger: (name: string, message: any) => void;
|
|
17
|
-
export { Config } from './types/Config';
|
|
18
|
-
export { ConsoleType } from './types/ConsoleType';
|
package/dist/index.js
CHANGED
|
@@ -1,91 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.cypressLogger = exports.callToString = exports.isConsoleMessageExcluded = exports.findConsoleMessageIncluded = exports.getConsoleMessageIncluded = exports.resetSpies = exports.createSpies = exports.createConfig = exports.validateConfig = void 0;
|
|
41
|
-
var chai = __importStar(require("chai"));
|
|
42
|
-
var chai_1 = require("chai");
|
|
43
|
-
var os_1 = require("os");
|
|
44
|
-
var sinon = __importStar(require("sinon"));
|
|
45
|
-
var sinon_chai_1 = __importDefault(require("sinon-chai"));
|
|
46
|
-
var type_detect_1 = __importDefault(require("type-detect"));
|
|
1
|
+
import * as chai from 'chai';
|
|
2
|
+
import { AssertionError } from 'chai';
|
|
3
|
+
import * as sinon from 'sinon';
|
|
4
|
+
import sinonChai from 'sinon-chai';
|
|
5
|
+
import typeDetect from 'type-detect';
|
|
47
6
|
chai.should();
|
|
48
|
-
chai.use(
|
|
49
|
-
function failOnConsoleError(_config) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
originConfig = originConfig !== null && originConfig !== void 0 ? originConfig : __assign({}, config);
|
|
7
|
+
chai.use(sinonChai);
|
|
8
|
+
export default function failOnConsoleError(_config = {}) {
|
|
9
|
+
let originConfig;
|
|
10
|
+
let config;
|
|
11
|
+
let spies;
|
|
12
|
+
const getConfig = () => config;
|
|
13
|
+
const setConfig = (_config) => {
|
|
14
|
+
validateConfig(_config);
|
|
15
|
+
config = createConfig(_config);
|
|
16
|
+
originConfig = originConfig !== null && originConfig !== void 0 ? originConfig : Object.assign({}, config);
|
|
59
17
|
};
|
|
60
18
|
setConfig(_config);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
19
|
+
const setSpies = (window) => (spies = createSpies(config, window.console));
|
|
20
|
+
if (Cypress.testingType === 'component') {
|
|
21
|
+
before(() => cy.window().then(setSpies));
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
Cypress.on('window:before:load', setSpies);
|
|
25
|
+
}
|
|
26
|
+
Cypress.on('command:end', () => {
|
|
65
27
|
if (!spies)
|
|
66
28
|
return;
|
|
67
|
-
|
|
68
|
-
spies =
|
|
29
|
+
const consoleMessage = getConsoleMessageIncluded(spies, config);
|
|
30
|
+
spies = resetSpies(spies);
|
|
69
31
|
if (!consoleMessage)
|
|
70
32
|
return;
|
|
71
|
-
throw new
|
|
33
|
+
throw new AssertionError(`cypress-fail-on-console-error:\n${consoleMessage}`);
|
|
72
34
|
});
|
|
73
|
-
Cypress.on('test:after:run',
|
|
35
|
+
Cypress.on('test:after:run', () => {
|
|
74
36
|
if (spies) {
|
|
75
|
-
spies =
|
|
37
|
+
spies = resetSpies(spies);
|
|
76
38
|
}
|
|
77
39
|
setConfig(originConfig);
|
|
78
40
|
});
|
|
79
41
|
return {
|
|
80
|
-
getConfig
|
|
81
|
-
setConfig
|
|
42
|
+
getConfig,
|
|
43
|
+
setConfig,
|
|
82
44
|
};
|
|
83
45
|
}
|
|
84
|
-
|
|
85
|
-
var validateConfig = function (config) {
|
|
46
|
+
export const validateConfig = (config) => {
|
|
86
47
|
if (config.consoleMessages) {
|
|
87
|
-
config.consoleMessages.forEach(
|
|
88
|
-
chai.expect((
|
|
48
|
+
config.consoleMessages.forEach((consoleMessage) => {
|
|
49
|
+
chai.expect(typeDetect(consoleMessage)).to.be.oneOf([
|
|
89
50
|
'string',
|
|
90
51
|
'RegExp',
|
|
91
52
|
]);
|
|
@@ -94,13 +55,12 @@ var validateConfig = function (config) {
|
|
|
94
55
|
}
|
|
95
56
|
if (config.consoleTypes) {
|
|
96
57
|
chai.expect(config.consoleTypes).not.to.be.empty;
|
|
97
|
-
config.consoleTypes.forEach(
|
|
58
|
+
config.consoleTypes.forEach((consoleType) => {
|
|
98
59
|
chai.expect(['error', 'warn', 'info']).contains(consoleType);
|
|
99
60
|
});
|
|
100
61
|
}
|
|
101
62
|
};
|
|
102
|
-
|
|
103
|
-
var createConfig = function (config) {
|
|
63
|
+
export const createConfig = (config) => {
|
|
104
64
|
var _a, _b, _c;
|
|
105
65
|
return ({
|
|
106
66
|
consoleMessages: (_a = config.consoleMessages) !== null && _a !== void 0 ? _a : [],
|
|
@@ -108,83 +68,71 @@ var createConfig = function (config) {
|
|
|
108
68
|
debug: (_c = config.debug) !== null && _c !== void 0 ? _c : false,
|
|
109
69
|
});
|
|
110
70
|
};
|
|
111
|
-
|
|
112
|
-
var createSpies = function (config, console) {
|
|
71
|
+
export const createSpies = (config, console) => {
|
|
113
72
|
var _a;
|
|
114
|
-
|
|
115
|
-
(_a = config.consoleTypes) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
73
|
+
let spies = new Map();
|
|
74
|
+
(_a = config.consoleTypes) === null || _a === void 0 ? void 0 : _a.forEach((consoleType) => {
|
|
116
75
|
spies.set(consoleType, sinon.spy(console, consoleType));
|
|
117
76
|
});
|
|
118
77
|
return spies;
|
|
119
78
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
spies.forEach(function (spy) { return spy.resetHistory(); });
|
|
79
|
+
export const resetSpies = (spies) => {
|
|
80
|
+
spies.forEach((spy) => spy.resetHistory());
|
|
123
81
|
return spies;
|
|
124
82
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
Array.from(spies.values()).find(function (spy) {
|
|
83
|
+
export const getConsoleMessageIncluded = (spies, config) => {
|
|
84
|
+
let includedConsoleMessage;
|
|
85
|
+
Array.from(spies.values()).find((spy) => {
|
|
129
86
|
if (!spy.called)
|
|
130
87
|
return false;
|
|
131
|
-
includedConsoleMessage =
|
|
88
|
+
includedConsoleMessage = findConsoleMessageIncluded(spy, config);
|
|
132
89
|
return includedConsoleMessage !== undefined;
|
|
133
90
|
});
|
|
134
91
|
return includedConsoleMessage;
|
|
135
92
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
var consoleMessages = spy.args.map(function (call) { return (0, exports.callToString)(call); });
|
|
93
|
+
export const findConsoleMessageIncluded = (spy, config) => {
|
|
94
|
+
const consoleMessages = spy.args.map((call) => callToString(call));
|
|
139
95
|
if (config.consoleMessages.length === 0) {
|
|
140
96
|
return consoleMessages[0];
|
|
141
97
|
}
|
|
142
|
-
return consoleMessages.find(
|
|
143
|
-
|
|
144
|
-
return (0, exports.isConsoleMessageExcluded)(consoleMessage, configConsoleMessage, config.debug);
|
|
145
|
-
});
|
|
98
|
+
return consoleMessages.find((consoleMessage) => {
|
|
99
|
+
const someConsoleMessagesExcluded = config.consoleMessages.some((configConsoleMessage) => isConsoleMessageExcluded(consoleMessage, configConsoleMessage, config.debug));
|
|
146
100
|
if (config.debug) {
|
|
147
|
-
|
|
148
|
-
consoleMessage
|
|
149
|
-
someConsoleMessagesExcluded
|
|
101
|
+
cypressLogger('consoleMessage_excluded', {
|
|
102
|
+
consoleMessage,
|
|
103
|
+
someConsoleMessagesExcluded,
|
|
150
104
|
});
|
|
151
105
|
}
|
|
152
106
|
return !someConsoleMessagesExcluded;
|
|
153
107
|
});
|
|
154
108
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var configConsoleMessageRegExp = configConsoleMessage instanceof RegExp
|
|
109
|
+
export const isConsoleMessageExcluded = (consoleMessage, configConsoleMessage, debug) => {
|
|
110
|
+
const configConsoleMessageRegExp = configConsoleMessage instanceof RegExp
|
|
158
111
|
? configConsoleMessage
|
|
159
112
|
: new RegExp(configConsoleMessage);
|
|
160
|
-
|
|
113
|
+
const consoleMessageExcluded = configConsoleMessageRegExp.test(consoleMessage);
|
|
161
114
|
if (debug) {
|
|
162
|
-
|
|
163
|
-
consoleMessage
|
|
164
|
-
configConsoleMessage
|
|
165
|
-
consoleMessageExcluded
|
|
115
|
+
cypressLogger('consoleMessage_configConsoleMessage_match', {
|
|
116
|
+
consoleMessage,
|
|
117
|
+
configConsoleMessage,
|
|
118
|
+
consoleMessageExcluded,
|
|
166
119
|
});
|
|
167
120
|
}
|
|
168
121
|
return consoleMessageExcluded;
|
|
169
122
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
.trim();
|
|
180
|
-
};
|
|
181
|
-
exports.callToString = callToString;
|
|
182
|
-
var cypressLogger = function (name, message) {
|
|
123
|
+
export const callToString = (calls) => calls
|
|
124
|
+
.reduce((previousValue, currentValue) => {
|
|
125
|
+
var _a;
|
|
126
|
+
const _value = (_a = currentValue === null || currentValue === void 0 ? void 0 : currentValue.stack) !== null && _a !== void 0 ? _a : currentValue;
|
|
127
|
+
const _currentValue = typeof _value !== 'string' ? JSON.stringify(_value) : _value;
|
|
128
|
+
return `${previousValue} ${_currentValue}`;
|
|
129
|
+
}, '')
|
|
130
|
+
.trim();
|
|
131
|
+
export const cypressLogger = (name, message) => {
|
|
183
132
|
Cypress.log({
|
|
184
133
|
name: name,
|
|
185
134
|
displayName: name,
|
|
186
135
|
message: JSON.stringify(message),
|
|
187
|
-
consoleProps:
|
|
136
|
+
consoleProps: () => message,
|
|
188
137
|
});
|
|
189
138
|
};
|
|
190
|
-
exports.cypressLogger = cypressLogger;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cypress-fail-on-console-error",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "fail cypress test on console error",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
@@ -11,9 +12,10 @@
|
|
|
11
12
|
"build": "npx rimraf dist/ && tsc",
|
|
12
13
|
"prettier": "prettier --write \"**/*\"",
|
|
13
14
|
"lint": "tsc --noEmit && tsc -p ./test/tsconfig.json && tsc -p ./cypress/tsconfig.json",
|
|
14
|
-
"test": "npm run test:ut && npm run test:
|
|
15
|
-
"test:ut": "
|
|
16
|
-
"test:
|
|
15
|
+
"test": "npm run test:ut && npm run test:e2e && npm run test:cmp",
|
|
16
|
+
"test:ut": "vitest run unit.test.ts",
|
|
17
|
+
"test:e2e": "vitest run e2e.test.ts --test-timeout 60000",
|
|
18
|
+
"test:cmp": "vitest run component.test.ts --test-timeout 60000",
|
|
17
19
|
"verify": "npm run build && npm run lint && npm run ci:prettier && npm run test",
|
|
18
20
|
"ci:prettier": "prettier --check \"**/*\""
|
|
19
21
|
},
|
|
@@ -24,7 +26,9 @@
|
|
|
24
26
|
"keywords": [
|
|
25
27
|
"cypress",
|
|
26
28
|
"testing",
|
|
27
|
-
"console"
|
|
29
|
+
"console",
|
|
30
|
+
"e2e",
|
|
31
|
+
"component"
|
|
28
32
|
],
|
|
29
33
|
"author": "nils-hoyer",
|
|
30
34
|
"license": "MIT",
|
|
@@ -34,22 +38,25 @@
|
|
|
34
38
|
"homepage": "https://github.com/nils-hoyer/cypress-fail-on-console-error#readme",
|
|
35
39
|
"dependencies": {
|
|
36
40
|
"chai": "^4.3.4",
|
|
37
|
-
"sinon": "^
|
|
38
|
-
"sinon-chai": "^3.7.0"
|
|
41
|
+
"sinon": "^15.0.0",
|
|
42
|
+
"sinon-chai": "^3.7.0",
|
|
43
|
+
"type-detect": "^4.0.8"
|
|
39
44
|
},
|
|
40
45
|
"devDependencies": {
|
|
41
|
-
"@
|
|
46
|
+
"@cypress/mount-utils": "^4.0.0",
|
|
47
|
+
"@types/chai": "4.3.5",
|
|
42
48
|
"@types/expect": "24.3.0",
|
|
43
|
-
"@types/mocha": "10.0.
|
|
44
|
-
"@types/sinon": "10.0.
|
|
45
|
-
"@types/sinon-chai": "3.2.
|
|
49
|
+
"@types/mocha": "10.0.1",
|
|
50
|
+
"@types/sinon": "10.0.16",
|
|
51
|
+
"@types/sinon-chai": "3.2.9",
|
|
46
52
|
"@types/type-detect": "4.0.1",
|
|
47
|
-
"cypress": "
|
|
48
|
-
"mocha": "10.
|
|
49
|
-
"prettier": "
|
|
50
|
-
"prettier-plugin-organize-imports": "3.
|
|
51
|
-
"rimraf": "
|
|
52
|
-
"
|
|
53
|
-
"
|
|
53
|
+
"cypress": "12.17.3",
|
|
54
|
+
"mocha": "10.2.0",
|
|
55
|
+
"prettier": "3.0.1",
|
|
56
|
+
"prettier-plugin-organize-imports": "3.2.3",
|
|
57
|
+
"rimraf": "5.0.1",
|
|
58
|
+
"typescript": "5.1.6",
|
|
59
|
+
"vite": "^4.4.6",
|
|
60
|
+
"vitest": "^0.33.0"
|
|
54
61
|
}
|
|
55
62
|
}
|
package/dist/types/Config.d.ts
DELETED
package/dist/types/Config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare type ConsoleType = 'error' | 'warn' | 'info';
|