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

Types: Fix typing issues in addon-test #30164

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions code/addons/test/src/components/TestProviderRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ const ItemTitle = styled.span<{ enabled?: boolean }>(
}
);

const statusOrder: TestStatus[] = ['failed', 'warning', 'pending', 'passed', 'skipped'];
const statusOrder: TestStatus[] = ['failed', 'warning', 'pending', 'passed', 'skipped', 'unknown'];
const statusMap: Record<TestStatus, ComponentProps<typeof TestStatusIcon>['status']> = {
failed: 'negative',
warning: 'warning',
passed: 'positive',
skipped: 'unknown',
unknown: 'unknown',
pending: 'pending',
};

Expand Down Expand Up @@ -218,7 +219,11 @@ export const TestProviderRender: FC<TestProviderRenderProps> = ({
storyId ? result.storyId === storyId : result.storyId?.startsWith(`${entryId}-`)
);
})
.sort((a, b) => statusOrder.indexOf(a.status) - statusOrder.indexOf(b.status));
.sort(
(a, b) =>
statusOrder.indexOf(a.status || state.running ? 'pending' : 'unknown') -
statusOrder.indexOf(b.status || state.running ? 'pending' : 'unknown')
Comment on lines +224 to +225
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: operator precedence issue - parentheses needed around ternary to avoid incorrect evaluation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest extracting state.running ? 'pending' : 'unknown' to a variable for clarity and because it's used twice. This would avoid the need for parenthesis.

);

const status = results[0]?.status ?? (state.running ? 'pending' : 'unknown');

Expand Down
3 changes: 2 additions & 1 deletion code/addons/test/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const statusMap: Record<TestStatus, API_StatusValue> = {
pending: 'pending',
warning: 'warn',
skipped: 'unknown',
unknown: 'unknown',
};

addons.register(ADDON_ID, (api) => {
Expand Down Expand Up @@ -100,7 +101,7 @@ addons.register(ADDON_ID, (api) => {
storyId,
{
title: 'Component tests',
status: statusMap[status],
status: status ? statusMap[status] : 'unknown',
description:
'failureMessages' in rest && rest.failureMessages
? rest.failureMessages.join('\n')
Expand Down
4 changes: 2 additions & 2 deletions code/addons/test/src/node/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { throttle } from 'es-toolkit';
import { TEST_PROVIDER_ID } from '../constants';
import type { TestManager } from './test-manager';

export type TestStatus = 'passed' | 'failed' | 'warning' | 'pending' | 'skipped';
export type TestStatus = 'passed' | 'failed' | 'warning' | 'pending' | 'skipped' | 'unknown';

export type TestResultResult =
| {
Expand All @@ -27,7 +27,7 @@ export type TestResultResult =
reports: Report[];
}
| {
status: Extract<TestStatus, 'failed' | 'warning'>;
status: Extract<TestStatus, 'failed' | 'warning'> | undefined;
storyId: string;
duration: number;
testRunId: string;
Expand Down
Loading