Skip to content

Commit

Permalink
fix: handle issues with initializing the report builder (QE-251) (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
devpow112 authored Jul 25, 2024
1 parent f9707c3 commit fca35aa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/reporters/mocha.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ class TestReportingMochaReporter extends Spec {
const { reporterOptions = {} } = options;

this._logger = new MochaLogger();
this._report = new ReportBuilder('mocha', this._logger, reporterOptions);

try {
const report = new ReportBuilder('mocha', this._logger, reporterOptions);

this._report = report;
} catch ({ message }) {
this._logger.error('Failed to initialize D2L test report builder, report will not be generated');
this._logger.error(message);

return;
}

runner
.once(EVENT_RUN_BEGIN, () => this._onRunBegin(stats))
Expand Down
18 changes: 15 additions & 3 deletions src/reporters/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,26 @@ export default class Reporter {
}

this._logger = new PlaywrightLogger();
this._report = new ReportBuilder('playwright', this._logger, this._options);

try {
this._report = new ReportBuilder('playwright', this._logger, this._options);
} catch ({ message }) {
this._logger.error('Failed to initialize D2L test report builder, report will not be generated');
this._logger.error(message);

return;
}

this._report
.getSummary()
.addContext();
}

onTestEnd(test, result) {
if (!this._report || !this._hasTests) {
return;
}

const { timeout, location: { file, line, column } } = test;

if (this._report.ignoreFilePath(file)) {
Expand Down Expand Up @@ -103,7 +115,7 @@ export default class Reporter {
}

onEnd(result) {
if (!this._hasTests) {
if (!this._report || !this._hasTests) {
return;
}

Expand All @@ -123,7 +135,7 @@ export default class Reporter {
}

async onExit() {
if (!this._hasTests) {
if (!this._report || !this._hasTests) {
return;
}

Expand Down
17 changes: 16 additions & 1 deletion src/reporters/web-test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,27 @@ const makeDetailId = (sessionId, file, name) => {
return `${sessionId}/${file}/${name}`;
};

const nullReporter = {
start() {},
stop() {}
};

export function reporter(options = {}) {
let overallStarted;
let testConfig;
const sessionStarts = new Map();
const logger = new WebTestRunnerLogger();
const report = new ReportBuilder('@web/test-runner', logger, options);
let report;

try {
report = new ReportBuilder('@web/test-runner', logger, options);
} catch ({ message }) {
logger.error('Failed to initialize D2L test report builder, report will not be generated');
logger.error(message);

return nullReporter;
}

const summary = report
.getSummary()
.addContext();
Expand Down

0 comments on commit fca35aa

Please sign in to comment.