This repository was archived by the owner on Jul 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
also collect linked teardown test cases. #329
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { SyncTestCase } from "../sync/types"; | ||
|
|
||
| type LinkedTestCaseId = { | ||
| id: string; | ||
| linkType: "dependency" | "teardown"; | ||
| sourceTestCaseId: string; | ||
| }; | ||
|
|
||
| const getLinkedTestCaseIds = (testCase: SyncTestCase): LinkedTestCaseId[] => { | ||
| const links: LinkedTestCaseId[] = []; | ||
|
|
||
| if (testCase.dependencyId) { | ||
| links.push({ | ||
| id: testCase.dependencyId, | ||
| linkType: "dependency", | ||
| sourceTestCaseId: testCase.id, | ||
| }); | ||
| } | ||
|
|
||
| if (testCase.teardownId) { | ||
| links.push({ | ||
| id: testCase.teardownId, | ||
| linkType: "teardown", | ||
| sourceTestCaseId: testCase.id, | ||
| }); | ||
| } | ||
|
|
||
| return links; | ||
| }; | ||
|
|
||
| const resolveLinkedTestCase = ( | ||
| testCasesById: Record<string, SyncTestCase>, | ||
| link: LinkedTestCaseId, | ||
| ): SyncTestCase => { | ||
| const testCase = testCasesById[link.id]; | ||
|
|
||
| if (!testCase) { | ||
| throw new Error( | ||
| `Could not find ${link.linkType} ${link.id} for ${link.sourceTestCaseId}`, | ||
| ); | ||
| } | ||
|
|
||
| return testCase; | ||
| }; | ||
|
|
||
| export const getRelevantTestCases = ( | ||
| testCasesById: Record<string, SyncTestCase>, | ||
| startTestCase: SyncTestCase, | ||
| ): SyncTestCase[] => { | ||
| const visited = new Set<string>(); | ||
| const result: SyncTestCase[] = []; | ||
| const queue: SyncTestCase[] = [startTestCase]; | ||
|
|
||
| let currentTestCase = queue.shift(); | ||
| while (currentTestCase) { | ||
| if (!visited.has(currentTestCase.id)) { | ||
| visited.add(currentTestCase.id); | ||
| result.push(currentTestCase); | ||
|
|
||
| const links = getLinkedTestCaseIds(currentTestCase); | ||
| for (const link of links) { | ||
| if (!visited.has(link.id)) { | ||
| const linkedTestCase = resolveLinkedTestCase(testCasesById, link); | ||
| queue.push(linkedTestCase); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| currentTestCase = queue.shift(); | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { getRelevantTestCases } from "../../../src/tools/yamlMutations/getRelevantTestCases"; | ||
| import { createMockSyncTestCase } from "../../mocks"; | ||
|
|
||
| describe("getRelevantTestCases", () => { | ||
| describe("dependency chain", () => { | ||
| it("returns only the start test case when it has no links", () => { | ||
| const testCase = createMockSyncTestCase({ id: "test-id" }); | ||
| const testCasesById = { "test-id": testCase }; | ||
|
|
||
| const result = getRelevantTestCases(testCasesById, testCase); | ||
|
|
||
| expect(result).toEqual([testCase]); | ||
| }); | ||
|
|
||
| it("includes the dependency chain", () => { | ||
| const parent = createMockSyncTestCase({ id: "parent-id" }); | ||
| const child = createMockSyncTestCase({ | ||
| id: "child-id", | ||
| dependencyId: "parent-id", | ||
| }); | ||
| const testCasesById = { "parent-id": parent, "child-id": child }; | ||
|
|
||
| const result = getRelevantTestCases(testCasesById, child); | ||
|
|
||
| expect(result).toHaveLength(2); | ||
| expect(result).toContainEqual(child); | ||
| expect(result).toContainEqual(parent); | ||
| }); | ||
|
|
||
| it("includes deeply nested dependency chain", () => { | ||
| const grandparent = createMockSyncTestCase({ id: "grandparent-id" }); | ||
| const parent = createMockSyncTestCase({ | ||
| id: "parent-id", | ||
| dependencyId: "grandparent-id", | ||
| }); | ||
| const child = createMockSyncTestCase({ | ||
| id: "child-id", | ||
| dependencyId: "parent-id", | ||
| }); | ||
| const testCasesById = { | ||
| "grandparent-id": grandparent, | ||
| "parent-id": parent, | ||
| "child-id": child, | ||
| }; | ||
|
|
||
| const result = getRelevantTestCases(testCasesById, child); | ||
|
|
||
| expect(result).toHaveLength(3); | ||
| expect(result).toContainEqual(child); | ||
| expect(result).toContainEqual(parent); | ||
| expect(result).toContainEqual(grandparent); | ||
| }); | ||
|
|
||
| it("throws if dependency is not found", () => { | ||
| const child = createMockSyncTestCase({ | ||
| id: "child-id", | ||
| dependencyId: "missing-parent", | ||
| }); | ||
| const testCasesById = { "child-id": child }; | ||
|
|
||
| expect(() => getRelevantTestCases(testCasesById, child)).toThrow( | ||
| "Could not find dependency missing-parent for child-id", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("teardown chain", () => { | ||
| it("includes the teardown test case", () => { | ||
| const testCase = createMockSyncTestCase({ | ||
| id: "test-id", | ||
| teardownId: "teardown-id", | ||
| }); | ||
| const teardown = createMockSyncTestCase({ id: "teardown-id" }); | ||
| const testCasesById = { "test-id": testCase, "teardown-id": teardown }; | ||
|
|
||
| const result = getRelevantTestCases(testCasesById, testCase); | ||
|
|
||
| expect(result).toHaveLength(2); | ||
| expect(result).toContainEqual(testCase); | ||
| expect(result).toContainEqual(teardown); | ||
| }); | ||
|
|
||
| it("includes teardown's dependencies", () => { | ||
| const testCase = createMockSyncTestCase({ | ||
| id: "test-id", | ||
| teardownId: "teardown-id", | ||
| }); | ||
| const teardownDependency = createMockSyncTestCase({ | ||
| id: "teardown-dependency-id", | ||
| }); | ||
| const teardown = createMockSyncTestCase({ | ||
| id: "teardown-id", | ||
| dependencyId: "teardown-dependency-id", | ||
| }); | ||
| const testCasesById = { | ||
| "test-id": testCase, | ||
| "teardown-id": teardown, | ||
| "teardown-dependency-id": teardownDependency, | ||
| }; | ||
|
|
||
| const result = getRelevantTestCases(testCasesById, testCase); | ||
|
|
||
| expect(result).toHaveLength(3); | ||
| expect(result).toContainEqual(testCase); | ||
| expect(result).toContainEqual(teardown); | ||
| expect(result).toContainEqual(teardownDependency); | ||
| }); | ||
|
|
||
| it("throws if teardown is not found", () => { | ||
| const testCase = createMockSyncTestCase({ | ||
| id: "test-id", | ||
| teardownId: "missing-teardown", | ||
| }); | ||
| const testCasesById = { "test-id": testCase }; | ||
|
|
||
| expect(() => getRelevantTestCases(testCasesById, testCase)).toThrow( | ||
| "Could not find teardown missing-teardown for test-id", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("combined dependency and teardown", () => { | ||
| it("includes both dependency and teardown chains", () => { | ||
| const parent = createMockSyncTestCase({ id: "parent-id" }); | ||
| const teardown = createMockSyncTestCase({ id: "teardown-id" }); | ||
| const testCase = createMockSyncTestCase({ | ||
| id: "test-id", | ||
| dependencyId: "parent-id", | ||
| teardownId: "teardown-id", | ||
| }); | ||
| const testCasesById = { | ||
| "parent-id": parent, | ||
| "test-id": testCase, | ||
| "teardown-id": teardown, | ||
| }; | ||
|
|
||
| const result = getRelevantTestCases(testCasesById, testCase); | ||
|
|
||
| expect(result).toHaveLength(3); | ||
| expect(result).toContainEqual(testCase); | ||
| expect(result).toContainEqual(parent); | ||
| expect(result).toContainEqual(teardown); | ||
| }); | ||
|
|
||
| it("handles shared test cases in dependency and teardown chains", () => { | ||
| const shared = createMockSyncTestCase({ id: "shared-id" }); | ||
| const parent = createMockSyncTestCase({ | ||
| id: "parent-id", | ||
| dependencyId: "shared-id", | ||
| }); | ||
| const teardown = createMockSyncTestCase({ | ||
| id: "teardown-id", | ||
| dependencyId: "shared-id", | ||
| }); | ||
| const testCase = createMockSyncTestCase({ | ||
| id: "test-id", | ||
| dependencyId: "parent-id", | ||
| teardownId: "teardown-id", | ||
| }); | ||
| const testCasesById = { | ||
| "shared-id": shared, | ||
| "parent-id": parent, | ||
| "test-id": testCase, | ||
| "teardown-id": teardown, | ||
| }; | ||
|
|
||
| const result = getRelevantTestCases(testCasesById, testCase); | ||
|
|
||
| expect(result).toHaveLength(4); | ||
| expect(result).toContainEqual(testCase); | ||
| expect(result).toContainEqual(parent); | ||
| expect(result).toContainEqual(teardown); | ||
| expect(result).toContainEqual(shared); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.