diff --git a/src/jest-reporter/FallbackAPI.ts b/src/jest-reporter/FallbackAPI.ts index 4fcf487..a1d12b1 100644 --- a/src/jest-reporter/FallbackAPI.ts +++ b/src/jest-reporter/FallbackAPI.ts @@ -3,6 +3,7 @@ import { JestMetadataError } from '../errors'; import type { GlobalMetadata, MetadataEventEmitter, + TestFileMetadata, TestDoneEvent, TestEntryMetadata, TestSkipEvent, @@ -24,7 +25,7 @@ export type AggregatedResultArg = { }; export class FallbackAPI { - private _fallbackMode: boolean | undefined = undefined; + private _fallbackModes = new Map(); private _cache = new Map>(); constructor( @@ -33,7 +34,7 @@ export class FallbackAPI { ) {} public get enabled() { - return this._fallbackMode ?? true; + return this._fallbackModes.size > 0 ? this._fallbackModes.values().next().value : true; } reportTestFile(testFilePath: string) { @@ -47,11 +48,8 @@ export class FallbackAPI { reportTestCase(testFilePath: string, testCaseResult: TestCaseResultArg): TestEntryMetadata { const file = this.globalMetadata.getTestFileMetadata(testFilePath); - if (this._fallbackMode === undefined) { - this._fallbackMode = !file.rootDescribeBlock; - } - - if (!this._fallbackMode) { + const fallbackMode = this._determineFallbackModeStatus(testFilePath, file); + if (!fallbackMode) { return file.lastTestEntry!; } @@ -140,10 +138,7 @@ export class FallbackAPI { reportTestFileResult(testFileResult: TestFileResultArg): TestEntryMetadata[] { const { testFilePath, testResults } = testFileResult; const file = this.globalMetadata.getTestFileMetadata(testFilePath); - - if (this._fallbackMode === undefined) { - this._fallbackMode = !file.rootDescribeBlock; - } + const fallbackMode = this._determineFallbackModeStatus(testFilePath, file); if (!file.rootDescribeBlock) { this.eventEmitter.emit({ @@ -154,7 +149,7 @@ export class FallbackAPI { } const rootDescribeBlock = file.rootDescribeBlock!; - if (!this._fallbackMode) { + if (!fallbackMode) { return [...rootDescribeBlock.allTestEntries()]; } @@ -223,6 +218,14 @@ export class FallbackAPI { } } } + + private _determineFallbackModeStatus(testFilePath: string, file: TestFileMetadata): boolean { + if (!this._fallbackModes.has(testFilePath)) { + this._fallbackModes.set(testFilePath, !file.rootDescribeBlock); + } + + return this._fallbackModes.get(testFilePath)!; + } } type TestEntryInfo = { diff --git a/src/utils/jestUtils.ts b/src/utils/jestUtils.ts index 9126f6a..bfc1ffe 100644 --- a/src/utils/jestUtils.ts +++ b/src/utils/jestUtils.ts @@ -6,6 +6,6 @@ export function isSingleWorker(config: Config.GlobalConfig) { export function isInsideIDE(config: Config.GlobalConfig) { const isSingleReporter = config.reporters && config.reporters.length === 1; - const singleReporter = isSingleReporter ? config.reporters?.[0]?.[0] ?? '' : ''; + const singleReporter = isSingleReporter ? (config.reporters?.[0]?.[0] ?? '') : ''; return /jest-intellij/i.test(singleReporter); }