From 84aef74de096ed39ef65a0c51d4f6939b499d6b9 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Fri, 25 Oct 2024 15:34:15 +0200 Subject: [PATCH 1/4] Escape XML when converting ANSI to HTML in test errors --- code/addons/test/src/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/code/addons/test/src/utils.ts b/code/addons/test/src/utils.ts index d80d9f4cdbee..6139bd738605 100644 --- a/code/addons/test/src/utils.ts +++ b/code/addons/test/src/utils.ts @@ -28,6 +28,7 @@ export function isJestError(error: unknown) { export function createAnsiToHtmlFilter(theme: StorybookTheme) { return new Filter({ + escapeXML: true, fg: theme.color.defaultText, bg: theme.background.content, }); From 4eba200866e207aca11ddcd9dd7ca5710bf779c5 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Fri, 25 Oct 2024 21:16:09 +0200 Subject: [PATCH 2/4] Show checkmark icon in story status dropdown --- code/core/src/manager/components/sidebar/Tree.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/core/src/manager/components/sidebar/Tree.tsx b/code/core/src/manager/components/sidebar/Tree.tsx index 2cb99d61cdc2..49110a95a721 100644 --- a/code/core/src/manager/components/sidebar/Tree.tsx +++ b/code/core/src/manager/components/sidebar/Tree.tsx @@ -7,6 +7,7 @@ import { CollapseIcon as CollapseIconSvg, ExpandAltIcon, StatusFailIcon, + StatusPassIcon, StatusWarnIcon, SyncIcon, } from '@storybook/icons'; @@ -224,7 +225,7 @@ const Node = React.memo(function Node({ description: value.description, 'aria-label': `Test status for ${value.title}: ${value.status}`, icon: { - success: null, // We don't show a checkmark, to avoid clutter + success: , error: , warn: , pending: , From 8b08b4e10c0d580271494fbd000acdde9e35f78d Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Fri, 25 Oct 2024 21:20:03 +0200 Subject: [PATCH 3/4] Update story status label for consistency --- code/addons/test/src/manager.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/addons/test/src/manager.tsx b/code/addons/test/src/manager.tsx index 50c2180fa18d..aeb71ab4aaa0 100644 --- a/code/addons/test/src/manager.tsx +++ b/code/addons/test/src/manager.tsx @@ -152,7 +152,7 @@ addons.register(ADDON_ID, (api) => { .map(({ storyId, status, testRunId, ...rest }) => { if (storyId) { const statusObject: API_StatusObject = { - title: 'Vitest', + title: 'Component tests', status: statusMap[status], description: 'failureMessages' in rest && rest.failureMessages?.length From ab45e76bf9853804013fc4d1aea082f9f7cbb526 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Sun, 27 Oct 2024 21:00:01 +0100 Subject: [PATCH 4/4] Fix hidden stacktrace for assertion errors in test panel --- code/addons/test/package.json | 1 + code/addons/test/src/utils.ts | 3 ++- code/yarn.lock | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/code/addons/test/package.json b/code/addons/test/package.json index ebae8b47baa4..0eee7c81a161 100644 --- a/code/addons/test/package.json +++ b/code/addons/test/package.json @@ -103,6 +103,7 @@ "react-dom": "^18.2.0", "semver": "^7.6.3", "slash": "^5.0.0", + "strip-ansi": "^7.1.0", "ts-dedent": "^2.2.0", "typescript": "^5.3.2", "vitest": "^2.1.3" diff --git a/code/addons/test/src/utils.ts b/code/addons/test/src/utils.ts index d80d9f4cdbee..b2829cea15cd 100644 --- a/code/addons/test/src/utils.ts +++ b/code/addons/test/src/utils.ts @@ -1,6 +1,7 @@ import { type StorybookTheme, useTheme } from 'storybook/internal/theming'; import Filter from 'ansi-to-html'; +import stripAnsi from 'strip-ansi'; export function isTestAssertionError(error: unknown) { return isChaiError(error) || isJestError(error); @@ -22,7 +23,7 @@ export function isJestError(error: unknown) { typeof error === 'object' && 'message' in error && typeof error.message === 'string' && - error.message.startsWith('expect(') + stripAnsi(error.message).startsWith('expect(') ); } diff --git a/code/yarn.lock b/code/yarn.lock index f871eb976889..a07803bc641e 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -6253,6 +6253,7 @@ __metadata: react-dom: "npm:^18.2.0" semver: "npm:^7.6.3" slash: "npm:^5.0.0" + strip-ansi: "npm:^7.1.0" ts-dedent: "npm:^2.2.0" typescript: "npm:^5.3.2" vitest: "npm:^2.1.3"