Skip to content

Commit

Permalink
fix: correctly parse the test results - result can be nullable (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku authored and zmiklank committed Jan 18, 2024
1 parent 6cb0ef2 commit 6e54f92
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 36 deletions.
7 changes: 5 additions & 2 deletions dist/action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/action.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/schema/testing-farm-api.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions dist/schema/testing-farm-api.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/schema/testing-farm-api.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async function action(pr: PullRequest): Promise<void> {

// Get final state of Testing Farm scheduled request
const state = tfResult.state;
const result = tfResult.result.overall;
const result = tfResult.result ? tfResult.result.overall : 'unknown';
let finalState: Endpoints['POST /repos/{owner}/{repo}/statuses/{sha}']['parameters']['state'] =
'success' as const;
let infraError = '';
Expand Down Expand Up @@ -264,7 +264,13 @@ async function action(pr: PullRequest): Promise<void> {

// Exit with error in case of failure in test
if (finalState === 'failure') {
throw new Error(`Testing Farm test failed - ${tfResult.result.summary}`);
throw new Error(
`Testing Farm test failed - ${
tfResult.result
? tfResult.result.summary ?? 'No summary provided'
: 'No summary provided'
}`
);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/schema/testing-farm-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ export type Request = z.infer<typeof requestSchema>;

export const requestDetailsSchema = z.object({
state: z.string(),
result: z.object({
summary: z.union([z.string(), z.null()]),
overall: z.string(),
}),
result: z
.object({
summary: z.union([z.string(), z.null()]),
overall: z.string(),
})
.nullable(),
});

export type RequestDetails = z.infer<typeof requestDetailsSchema>;
20 changes: 4 additions & 16 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,10 @@ describe('Integration test', () => {
}
);
vi.mocked(mocks.requestDetails)
.mockResolvedValueOnce({
state: 'new',
result: { overall: '', summary: null },
})
.mockResolvedValueOnce({
state: 'queued',
result: { overall: '', summary: null },
})
.mockResolvedValueOnce({
state: 'pending',
result: { overall: '', summary: null },
})
.mockResolvedValueOnce({
state: 'running',
result: { overall: '', summary: null },
})
.mockResolvedValueOnce({ state: 'new', result: null })
.mockResolvedValueOnce({ state: 'queued', result: null })
.mockResolvedValueOnce({ state: 'pending', result: null })
.mockResolvedValueOnce({ state: 'running', result: null })
.mockResolvedValueOnce({
state: 'complete',
result: { overall: 'passed', summary: '\\o/' },
Expand Down

0 comments on commit 6e54f92

Please sign in to comment.