Skip to content

Commit

Permalink
feature: improve error collection
Browse files Browse the repository at this point in the history
The error stack trace contains more useful debugging information: browser, code, etc.
  • Loading branch information
gibiw committed Aug 29, 2024
1 parent ffa8e49 commit 328c168
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
6 changes: 6 additions & 0 deletions qase-testcafe/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# qase-testcafe@2.0.2

## What's new

Improved error collection. The error stack trace contains more useful debugging information: browser, code, etc.

# qase-testcafe@2.0.1

## What's new
Expand Down
2 changes: 1 addition & 1 deletion qase-testcafe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testcafe-reporter-qase",
"version": "2.0.1",
"version": "2.0.2",
"description": "Qase TMS TestCafe Reporter",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
16 changes: 14 additions & 2 deletions qase-testcafe/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ export const factory = (options: TestcafeQaseOptionsType) => {
reportFixtureStart: () => {
/* empty */
},
reportTestDone: async (name: string, testRunInfo: TestRunInfoType, meta: Record<string, string>) => {
await reporter.reportTestDone(name, testRunInfo, meta);
async reportTestDone(
name: string,
testRunInfo: TestRunInfoType,
meta: Record<string, string>
): Promise<void> {
return reporter.reportTestDone(
name,
testRunInfo,
meta,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error Inject testrail error formatting method with bound context
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
this.formatError.bind(this)
);
},
reportTaskDone: async () => {
await reporter.reportTaskDone();
Expand Down
44 changes: 14 additions & 30 deletions qase-testcafe/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ interface TestRunErrorFormattableAdapterType {
screenshotPath: string;
testRunId: string;
testRunPhase: string;
type: string;
code?: string;
isTestCafeError?: boolean;
callsite?: CallsiteRecordType;
errMsg?: string;
errMsg: string;
diff?: boolean;
id?: string;
}
Expand Down Expand Up @@ -96,32 +97,6 @@ export class TestcafeQaseReporter {
return TestStatusEnum.passed;
}

/**
* @param {TestRunErrorFormattableAdapterType[]} errors
* @returns {Error}
* @private
*/
private static transformErrors(errors: TestRunErrorFormattableAdapterType[]): Error {
const [errorMessages, errorStacks] = errors.reduce<[string[], string[]]>(
([messages, stacks], error) => {
const stack =
error.callsite?.stackFrames?.map((line) => String(line)) ?? [];

messages.push(error.errMsg ?? 'Error');
stacks.push(stack.join('\n'));

return [messages, stacks];
},
[[], []],
);

const error = new Error(errorMessages.join('\n\n'));

error.stack = errorStacks.join('\n\n');

return error;
}

/**
* @param {ScreenshotType[]} screenshots
* @returns {Attachment[]}
Expand Down Expand Up @@ -179,13 +154,22 @@ export class TestcafeQaseReporter {
* @param {string} title
* @param {TestRunInfoType} testRunInfo
* @param {Record<string, string>} meta
* @param formatError
*/
public reportTestDone = async (
title: string,
testRunInfo: TestRunInfoType,
meta: Record<string, string>,
formatError: (error: any, prefix: string) => string,

Check warning on line 163 in qase-testcafe/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-testcafe - Node 16

Unexpected any. Specify a different type

Check warning on line 163 in qase-testcafe/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-testcafe - Node 16

Unexpected any. Specify a different type

Check warning on line 163 in qase-testcafe/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-testcafe - Node 18

Unexpected any. Specify a different type

Check warning on line 163 in qase-testcafe/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-testcafe - Node 18

Unexpected any. Specify a different type
) => {
const error = TestcafeQaseReporter.transformErrors(testRunInfo.errs);
const errorLog = testRunInfo.errs
.map((error, index) => formatError(error, `${index + 1} `).replace(
// eslint-disable-next-line no-control-regex
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
'',
))
.join('\n');

const metadata = this.getMeta(meta);
await this.reporter.addTestResult({
author: null,
Expand All @@ -194,11 +178,11 @@ export class TestcafeQaseReporter {
start_time: null,
end_time: null,
duration: testRunInfo.durationMs,
stacktrace: error.stack ?? null,
stacktrace: errorLog,
thread: null,
},
fields: metadata[metadataEnum.fields],
message: error.message,
message: errorLog ? errorLog.split('\n')[0] ?? '' : '',
muted: false,
params: metadata[metadataEnum.parameters],
group_params: metadata[metadataEnum.groupParameters],
Expand Down

0 comments on commit 328c168

Please sign in to comment.