cypress-fail-on-console-error 3.2.1 → 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 CHANGED
@@ -22,16 +22,16 @@ failOnConsoleError();
22
22
 
23
23
  | Parameter | Default | <div style="width:300px">Description</div> |
24
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. |
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
 
29
29
  <br/>
30
30
 
31
31
  ```js
32
- import failOnConsoleError, { consoleType } from 'cypress-fail-on-console-error';
32
+ import failOnConsoleError, { consoleType, Config } from 'cypress-fail-on-console-error';
33
33
 
34
- const config = {
34
+ const config: Config = {
35
35
  excludeMessages: ['foo', /^some bar-regex.*/],
36
36
  includeConsoleTypes: [
37
37
  consoleType.ERROR,
@@ -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,10 +61,33 @@ 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
  ![image info](./docs/cypressLogTrue.png)
67
90
 
68
91
  ### Contributing
69
92
  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
93
+ 2. Provide a PR with implementation and tests. Command `npm run verify` have to pass locally
package/dist/index.d.ts CHANGED
@@ -1,14 +1,18 @@
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): void;
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
- export declare const createConfig: (config: Config) => Config;
7
- export declare const createSpies: (config: Config, console: Console) => Map<ConsoleType, sinon.SinonSpy>;
9
+ export declare const createConfig: (config: Config) => Required<Config>;
10
+ export declare const createSpies: (config: Required<Config>, console: Console) => Map<ConsoleType, sinon.SinonSpy>;
8
11
  export declare const resetSpies: (spies: Map<ConsoleType, sinon.SinonSpy>) => Map<ConsoleType, sinon.SinonSpy>;
9
- export declare const getIncludedCall: (spies: Map<ConsoleType, sinon.SinonSpy>, config: Config) => string | undefined;
10
- export declare const findIncludedCall: (spy: sinon.SinonSpy, config: Config) => string | undefined;
12
+ export declare const getIncludedCall: (spies: Map<ConsoleType, sinon.SinonSpy>, config: Required<Config>) => string | undefined;
13
+ export declare const findIncludedCall: (spy: sinon.SinonSpy, config: Required<Config>) => string | undefined;
11
14
  export declare const isErrorMessageExcluded: (errorMessage: string, excludeMessage: string, cypressLog: boolean) => boolean;
12
15
  export declare const callToString: (calls: any[]) => string;
13
16
  export declare const cypressLogger: (name: string, message: any) => void;
14
- export declare const consoleType: typeof ConsoleType;
17
+ export { Config } from './types/Config';
18
+ export { ConsoleType as consoleType } from './types/ConsoleType';
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);
@@ -36,11 +47,18 @@ var type_detect_1 = __importDefault(require("type-detect"));
36
47
  var ConsoleType_1 = require("./types/ConsoleType");
37
48
  chai.should();
38
49
  chai.use(sinon_chai_1.default);
39
- function failOnConsoleError(config) {
40
- if (config === void 0) { config = {}; }
50
+ function failOnConsoleError(_config) {
51
+ if (_config === void 0) { _config = {}; }
52
+ var originConfig;
53
+ var config;
41
54
  var spies;
42
- (0, exports.validateConfig)(config);
43
- config = (0, exports.createConfig)(config);
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',
@@ -75,13 +99,13 @@ var validateConfig = function (config) {
75
99
  };
76
100
  exports.validateConfig = validateConfig;
77
101
  var createConfig = function (config) {
78
- var _a, _b;
102
+ var _a, _b, _c;
79
103
  return ({
80
- excludeMessages: config.excludeMessages,
81
- includeConsoleTypes: ((_a = config.includeConsoleTypes) === null || _a === void 0 ? void 0 : _a.length)
104
+ excludeMessages: (_a = config.excludeMessages) !== null && _a !== void 0 ? _a : [],
105
+ includeConsoleTypes: ((_b = config.includeConsoleTypes) === null || _b === void 0 ? void 0 : _b.length)
82
106
  ? config.includeConsoleTypes
83
107
  : [ConsoleType_1.ConsoleType.ERROR],
84
- cypressLog: (_b = config.cypressLog) !== null && _b !== void 0 ? _b : false,
108
+ cypressLog: (_c = config.cypressLog) !== null && _c !== void 0 ? _c : false,
85
109
  });
86
110
  };
87
111
  exports.createConfig = createConfig;
@@ -165,4 +189,5 @@ var cypressLogger = function (name, message) {
165
189
  });
166
190
  };
167
191
  exports.cypressLogger = cypressLogger;
168
- exports.consoleType = ConsoleType_1.ConsoleType;
192
+ var ConsoleType_2 = require("./types/ConsoleType");
193
+ 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.2.1",
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
- "test:it:debug": "cypress open",
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": {
@@ -39,18 +38,18 @@
39
38
  "sinon-chai": "^3.7.0"
40
39
  },
41
40
  "devDependencies": {
42
- "@types/chai": "4.3.1",
41
+ "@types/chai": "4.3.3",
43
42
  "@types/expect": "24.3.0",
44
43
  "@types/mocha": "9.1.1",
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.3.1",
47
+ "cypress": "10.8.0",
49
48
  "mocha": "10.0.0",
50
49
  "prettier": "2.7.1",
51
- "prettier-plugin-organize-imports": "3.0.0",
50
+ "prettier-plugin-organize-imports": "3.1.1",
52
51
  "rimraf": "3.0.2",
53
52
  "ts-mocha": "10.0.0",
54
- "typescript": "4.7.4"
53
+ "typescript": "4.8.3"
55
54
  }
56
55
  }