Skip to content

Commit

Permalink
wip: fix fallback API
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Sep 29, 2023
1 parent e8e57e0 commit c3e9c60
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
18 changes: 12 additions & 6 deletions packages/library/src/jest-reporter/AssociateMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class AssociateMetadata {
throw new JestMetadataError('Cannot associate metadata with an empty file path');
}

if (!metadata) {
throw new JestMetadataError(`Cannot associate a non-existent metadata with a file: ${value}`);
}

this._map.set(value, metadata);

if (path.isAbsolute(value)) {
Expand All @@ -24,13 +28,15 @@ export class AssociateMetadata {
}
}

testCaseName(nameIdentifier: string[], metadata: TestEntryMetadata): void {
this._map.set(nameIdentifier.join('\u001F'), metadata);
}

testCaseResult(testCaseResult: TestCaseResult, metadata: TestEntryMetadata): void {
if (testCaseResult == undefined) {
throw new JestMetadataError('Cannot associate metadata with an undefined test case result');
if (!testCaseResult) {
throw new JestMetadataError('Cannot associate metadata with a non-existent test case');
}

if (!metadata) {
throw new JestMetadataError(
`Cannot associate a non-existent metadata with a test case: ${testCaseResult.fullName}`,
);
}

this._map.set(testCaseResult, metadata);
Expand Down
9 changes: 5 additions & 4 deletions packages/library/src/jest-reporter/FallbackAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ export class FallbackAPI {
return [...rootDescribeBlock.allTestEntries()];
}

for (const rotator of this._cache.values()) {
rotator.reset();
}

for (const testCaseResult of testResults) {
const nameId = this._getNameIdentifier(testFilePath, testCaseResult);
const tests = this._cache.get(nameId);
const info = tests
?.reset()
.items.reverse()
.find((t) => t.testCaseResult.status === testCaseResult.status);
const info = tests?.find((t) => t.testCaseResult.status === testCaseResult.status);

if (!info) {
const testId = `test_${rootDescribeBlock.children.length}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class DescribeBlockMetadata extends BaseMetadata {

this.children.push(testEntry);
this.file[symbols.currentMetadata] = testEntry;
this.file[symbols.lastTestEntry] = testEntry;

return testEntry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class TestFileMetadata extends BaseMetadata {

[symbols.start](): void {
this[symbols.currentMetadata] = this;
this[symbols.lastTestEntry] = undefined;
}

[symbols.finish](): void {
Expand Down

0 comments on commit c3e9c60

Please sign in to comment.