Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: increase error resilience #79

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}
}
Loading