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: fallback mode per file #82

Merged
merged 2 commits into from
Dec 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
27 changes: 15 additions & 12 deletions src/jest-reporter/FallbackAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { JestMetadataError } from '../errors';
import type {
GlobalMetadata,
MetadataEventEmitter,
TestFileMetadata,
TestDoneEvent,
TestEntryMetadata,
TestSkipEvent,
Expand All @@ -24,7 +25,7 @@ export type AggregatedResultArg = {
};

export class FallbackAPI {
private _fallbackMode: boolean | undefined = undefined;
private _fallbackModes = new Map<string, boolean>();
private _cache = new Map<string, Rotator<TestEntryInfo>>();

constructor(
Expand All @@ -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) {
Expand All @@ -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!;
}

Expand Down Expand Up @@ -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({
Expand All @@ -154,7 +149,7 @@ export class FallbackAPI {
}

const rootDescribeBlock = file.rootDescribeBlock!;
if (!this._fallbackMode) {
if (!fallbackMode) {
return [...rootDescribeBlock.allTestEntries()];
}

Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/jestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading