Skip to content

Commit c6a03c0

Browse files
authored
[minor] added env variable to ignore uncaught exceptions (#240)
1 parent 2dd1bc4 commit c6a03c0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,15 @@ That's it! :tada:
170170
| **allureWrapCustomCommands**<br/>_type: true/false/string_<br/>_default: true_ <br/><br/>ex:<br/> - `allureWrapCustomCommands: 'true'`<br/> - `allureWrapCustomCommands:'qaId,login'`<br/> - `allureWrapCustomCommands:'!qaValue'` | will wrap custom commands, so custom command will have child steps in report<br/>When value has string with commands split by comma will wrap only these commands. <br/>To exclude commands specify them starting with `!` - all commands specified in this variable should have either `!` or not have it <br/><br/>For this to work you should register allure plugin in setup files before any new commands are added.<br/><br/>![wrap-cmd](./docs/wrap_cmd.jpg) |
171171
| **allureCleanResults**<br/>_type: boolean_<br/>_default: false_ | Will remove allure results on cypress start (it will be done once, after plugins are loaded) |
172172
| **allureAttachRequests**<br/>_type: boolean_<br/>_default: false_ | Attach request/response body and status as files to request step<br/><br/>Several requests:<br/>![requests](./docs/requests.jpg)<br/>One request: <br/>![request](./docs/request.jpg) |
173-
| **allureAddBodiesToRequests**<br/>_type: string_<br/>_default: undefined_ | Add request/response bodies to request object of `request:started`/ `request:ended` custom events, [see more](#startend-request-events) |
173+
| **allureAddBodiesToRequests**<br/>_type: string_<br/>_default: undefined_ | Add request/response bodies to request object of `request:started`/ `request:ended` custom events, [see more](#startend-request-events) |
174174
| **allureCompactAttachments**<br/>*type: boolea*n<br/>_default: true_ | Stringify requests attachments with spaces or not |
175175
| **allureAddVideoOnPass**<br/>_type: boolean_<br/>_default: false_ | When true - will attach video for all tests (including passed), otherwise will attach videos only for failed, broken, unknown |
176176
| **tmsPrefix** <br/>_type: string_<br/><br/>ex: `http://jira.com` or `http://jira.com/PROJECT-1/*/browse` | You can specify prefix to tms using this. It will be concatenated with value when using cypress interface like `cy.allure().tms('PROJ-01')`. <br/>Also link can be specified with `*` - it will be replaced with id. <br/><br/>Difference between tms and issue - will have different icons: <br/><br/> ![links](./docs/links.jpg) |
177177
| **issuePrefix** <br/>_type: string_<br/><br/>ex: `http://jira.com` or `http://jira.com/PROJECT-1/*/browse` | The same as tmsPrefix - for issue `cy.allure().issue('PROJ-02')` |
178178
| **allureShowDuplicateWarn**<br/>_type: boolean_<br/>_default: false_ | Show console warnings about test duplicates. |
179-
| **allureShowTagsInTitle**<br/>_type: boolean_<br/>_default: undefined_ | Whether to show tags in test title or not. When undefined will keep title as is ([how to add tags?](#adding-meta-information)) |
179+
| **allureShowTagsInTitle**<br/>_type: boolean_<br/>_default: undefined_ | Whether to show tags in test title or not. When undefined will keep title as is ([how to add tags?](#adding-meta-information)) |
180180
| **allureAddNonSpecialTags**<br/>_type: boolean_<br/>_default: true_ | Whether to add non-special tags to tests. ([what are special tags?](#adding-meta-information)) |
181+
| **allureIgnoreUncaughtExceptions**<br/>_type: string_<br/>_default: adds all_ | Whether to add uncaught exception details to steps, value - exception messages split by comma, can use asterisk to replace any symbol |
181182

182183

183184
### tmsPrefix and issuePrefix

src/setup/cypress-events.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,21 @@ export const handleCyLogEvents = (
221221
let state: Status = consoleProps?.error ?? logErr ? failedStatus : passedStatus;
222222
let details: { message?: string; trace?: string } | undefined = undefined;
223223

224-
if (logName.indexOf(UNCAUGHT_EXCEPTION_NAME) !== -1) {
224+
const isIgnoreException = () => {
225+
const ignored = Cypress.env('allureIgnoreUncaughtExceptions');
226+
227+
if (!ignored) {
228+
return false;
229+
}
230+
231+
const exceptions =
232+
ignored.split(',').map((x: string) => new RegExp(`^${x.replace(/\./g, '.').replace(/\*/g, '.*')}$`)) ?? [];
233+
const err = consoleProps?.props?.Error as Error | undefined;
234+
235+
return err?.message && exceptions.some((e: RegExp) => e.test(err.message));
236+
};
237+
238+
if (logName.indexOf(UNCAUGHT_EXCEPTION_NAME) !== -1 && !isIgnoreException()) {
225239
const err = consoleProps?.props?.Error as Error | undefined;
226240
const isCommandFailed = command.state === 'failed';
227241
// when command failed we mark uncaught exception log as error,

0 commit comments

Comments
 (0)