Skip to content

Commit

Permalink
fix: increase error resilience (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph authored May 17, 2024
1 parent b12dd62 commit 83dc8e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"dependencies": {
"bunyamin": "^1.5.2",
"funpermaproxy": "^1.1.0",
"jest-environment-emit": "^1.0.6",
"jest-environment-emit": "^1.0.8",
"lodash.merge": "^4.6.2",
"lodash.snakecase": "^4.1.1",
"node-ipc": "9.2.1",
Expand Down
57 changes: 41 additions & 16 deletions src/jest-reporter/ReporterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,24 @@ export class ReporterServer {
}

async onRunStart(): Promise<void> {
await this.#ipc.start();
this.#log.debug.begin(__REPORTER(''), 'test run');

try {
await this.#ipc.start();
} catch (error) {
this.#log.error(error, 'Caught unhandled error in onRunStart');
}
}

onTestFileStart(testPath: string): void {
this.#log.debug.begin(__REPORTER(testPath), __FILE(this.#rootDir, testPath));
const testFileMetadata = this.#fallbackAPI.reportTestFile(testPath);
this.#associate.filePath(testPath, testFileMetadata);

try {
const testFileMetadata = this.#fallbackAPI.reportTestFile(testPath);
this.#associate.filePath(testPath, testFileMetadata);
} catch (error) {
this.#log.error(error, 'Caught unhandled error in onTestFileStart');
}
}

onTestCaseStart(testPath: string, testCaseStartInfo: unknown): void {
Expand All @@ -92,26 +103,40 @@ export class ReporterServer {
onTestCaseResult(testPath: string, testCaseResult: TestCaseResult): void {
this.#log.debug(__REPORTER(testPath), 'onTestCaseResult');

const lastTestEntry = this.#fallbackAPI.reportTestCase(testPath, testCaseResult);
this.#associate.testCaseResult(testCaseResult, lastTestEntry);
try {
const lastTestEntry = this.#fallbackAPI.reportTestCase(testPath, testCaseResult);
this.#associate.testCaseResult(testCaseResult, lastTestEntry);
} catch (error: unknown) {
this.#log.error(error, 'Caught unhandled error in onTestCaseResult');
}
}

onTestFileResult(testPath: string, testResult: TestResult): void {
const allTestEntries = this.#fallbackAPI.reportTestFileResult(testResult);
const testResults = testResult.testResults;
for (let i = 0; i < testResults.length; i++) {
this.#associate.testCaseResult(testResults[i], allTestEntries[i]);
try {
const allTestEntries = this.#fallbackAPI.reportTestFileResult(testResult);
const testResults = testResult.testResults;
for (let i = 0; i < testResults.length; i++) {
this.#associate.testCaseResult(testResults[i], allTestEntries[i]);
}
} catch (error: unknown) {
this.#log.error(error, 'Caught unhandled error in onTestFileResult');
} finally {
this.#log.debug.end(__REPORTER(testPath));
}

this.#log.debug.end(__REPORTER(testPath));
}

async onRunComplete(): Promise<void> {
await this.#ipc.stop();

if (process.env.JEST_BUNYAMIN_DIR) {
await new Promise((resolve) => setTimeout(resolve, 1000));
await aggregateLogs();
try {
await this.#ipc.stop();
} catch (error: unknown) {
this.#log.error(error, 'Caught unhandled error in onRunComplete');
} finally {
this.#log.debug.end(__REPORTER(''));

if (process.env.JEST_BUNYAMIN_DIR) {
await new Promise((resolve) => setTimeout(resolve, 1000));
await aggregateLogs();
}
}
}
}

0 comments on commit 83dc8e0

Please sign in to comment.