From 68e5d5522444855a1eef39ed2dbb94057e25d99f Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Sat, 17 Feb 2024 11:02:24 +0200 Subject: [PATCH] fix: add missing reporter resilience --- src/realms/AllureRealm.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/realms/AllureRealm.ts b/src/realms/AllureRealm.ts index 516d274..6923da0 100644 --- a/src/realms/AllureRealm.ts +++ b/src/realms/AllureRealm.ts @@ -1,3 +1,6 @@ +import path from 'node:path'; +import os from 'node:os'; + import { state } from 'jest-metadata'; import type { AllureGlobalMetadata } from 'jest-allure2-reporter'; @@ -12,15 +15,26 @@ export class AllureRealm { getGlobalMetadata: () => state, getNow: () => Date.now(), getReporterConfig() { - const config = new AllureMetadataProxy(state).get( + let config = new AllureMetadataProxy(state).get( 'config', ); if (!config) { - throw new Error( + console.warn( "Cannot receive jest-allure2-reporter's config from the parent process. Have you set up Jest test environment correctly?", ); } + config ??= { + resultsDir: path.join(os.tmpdir(), 'allure-results'), + overwrite: true, + injectGlobals: true, + attachments: { + subDir: 'attachments', + contentHandler: 'write', + fileHandler: 'ref', + }, + }; + return config as SharedReporterConfig; }, });