From fc2610f44a9f82b282fdbae9eb2ca33d2e78c7d8 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Thu, 9 Jan 2025 14:56:12 +0100 Subject: [PATCH] Fix for windows --- .../addon-a11y-addon-test.test.ts.snap | 104 +++++++++++++++++ .../fixes/addon-a11y-addon-test.test.ts | 109 +++--------------- 2 files changed, 118 insertions(+), 95 deletions(-) diff --git a/code/lib/cli-storybook/src/automigrate/fixes/__snapshots__/addon-a11y-addon-test.test.ts.snap b/code/lib/cli-storybook/src/automigrate/fixes/__snapshots__/addon-a11y-addon-test.test.ts.snap index d28ce40f1ca9..5a567a94671f 100644 --- a/code/lib/cli-storybook/src/automigrate/fixes/__snapshots__/addon-a11y-addon-test.test.ts.snap +++ b/code/lib/cli-storybook/src/automigrate/fixes/__snapshots__/addon-a11y-addon-test.test.ts.snap @@ -94,3 +94,107 @@ export default { For more information, please refer to the accessibility addon documentation: https://storybook.js.org/docs/writing-tests/accessibility-testing#test-addon-integration" `; + +exports[`addonA11yAddonTest > transformPreviewFile > should add a new tags property if it does not exist 1`] = ` +"import type { Preview } from '@storybook/react'; + +const preview: Preview = { + parameters: { + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, + }, + + // a11y-test tag controls whether accessibility tests are run as part of a standalone Vitest test run + // For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing + tags: [/*'a11y-test'*/] +}; + +export default preview;" +`; + +exports[`addonA11yAddonTest > transformPreviewFile > should add a new tags property if it does not exist and a default export does not exist 1`] = ` +"export const parameters = { + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, +} +export const tags = ["a11y-test"];" +`; + +exports[`addonA11yAddonTest > transformPreviewFile > should extend the existing tags property 1`] = ` +"import type { Preview } from "@storybook/react"; + +const preview: Preview = { + // a11y-test tag controls whether accessibility tests are run as part of a standalone Vitest test run + // For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing + tags: ["existingTag"/*, "a11y-test"*/], + parameters: { + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, + }, +}; + +export default preview;" +`; + +exports[`addonA11yAddonTest > transformPreviewFile > should extend the existing tags property without type annotations 1`] = ` +"export default { + // a11y-test tag controls whether accessibility tests are run as part of a standalone Vitest test run + // For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing + tags: ["existingTag"/*, "a11y-test"*/], + parameters: { + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, + }, +};" +`; + +exports[`addonA11yAddonTest > transformPreviewFile > should handle the default export without type annotations 1`] = ` +"export default { + parameters: { + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, + }, + + // a11y-test tag controls whether accessibility tests are run as part of a standalone Vitest test run + // For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing + tags: [/*"a11y-test"*/] +};" +`; + +exports[`addonA11yAddonTest > transformPreviewFile > should not add a11y-test if it already exists in the tags property 1`] = ` +"import type { Preview } from "@storybook/react"; + +const preview: Preview = { + tags: ["a11y-test"], + parameters: { + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, + }, +}; + +export default preview;" +`; diff --git a/code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.test.ts b/code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.test.ts index 1ea47fa33ac0..e4f9906534a9 100644 --- a/code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.test.ts +++ b/code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.test.ts @@ -563,7 +563,7 @@ describe('addonA11yAddonTest', () => { it('should add a new tags property if it does not exist', async () => { const source = dedent` import type { Preview } from '@storybook/react'; - + const preview: Preview = { parameters: { controls: { @@ -574,33 +574,13 @@ describe('addonA11yAddonTest', () => { }, }, }; - + export default preview; `; const transformed = await transformPreviewFile(source, process.cwd()); - const expected = dedent` - import type { Preview } from '@storybook/react'; - - const preview: Preview = { - parameters: { - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/i, - }, - }, - }, - - // a11y-test tag controls whether accessibility tests are run as part of a standalone Vitest test run - // For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing - tags: [/*'a11y-test'*/] - }; - - export default preview; - `; - expect(transformed).toBe(await formatFileContent(process.cwd(), expected)); + expect(transformed).toMatchSnapshot(); }); it('should add a new tags property if it does not exist and a default export does not exist', async () => { @@ -616,25 +596,14 @@ describe('addonA11yAddonTest', () => { `; const transformed = await transformPreviewFile(source, process.cwd()); - const expected = dedent` - export const parameters = { - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/i, - }, - }, - } - export const tags = ["a11y-test"]; - `; - expect(transformed).toBe(await formatFileContent(process.cwd(), expected)); + expect(transformed).toMatchSnapshot(); }); it('should extend the existing tags property', async () => { const source = dedent` import type { Preview } from "@storybook/react"; - + const preview: Preview = { tags: ["existingTag"], parameters: { @@ -646,38 +615,19 @@ describe('addonA11yAddonTest', () => { }, }, }; - + export default preview; `; const transformed = await transformPreviewFile(source, process.cwd()); - const expected = dedent` - import type { Preview } from "@storybook/react"; - - const preview: Preview = { - // a11y-test tag controls whether accessibility tests are run as part of a standalone Vitest test run - // For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing - tags: ["existingTag"/*, "a11y-test"*/], - parameters: { - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/i, - }, - }, - }, - }; - - export default preview; - `; - expect(transformed).toBe(await formatFileContent(process.cwd(), expected)); + expect(transformed).toMatchSnapshot(); }); it('should not add a11y-test if it already exists in the tags property', async () => { - const expected = dedent` + const source = dedent` import type { Preview } from "@storybook/react"; - + const preview: Preview = { tags: ["a11y-test"], parameters: { @@ -689,13 +639,13 @@ describe('addonA11yAddonTest', () => { }, }, }; - + export default preview; `; - const transformed = await transformPreviewFile(expected, process.cwd()); + const transformed = await transformPreviewFile(source, process.cwd()); - expect(transformed).toBe(await formatFileContent(process.cwd(), expected)); + expect(transformed).toMatchSnapshot(); }); it('should handle the default export without type annotations', async () => { @@ -713,24 +663,8 @@ describe('addonA11yAddonTest', () => { `; const transformed = await transformPreviewFile(source, process.cwd()); - const expected = dedent` - export default { - parameters: { - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/i, - }, - }, - }, - - // a11y-test tag controls whether accessibility tests are run as part of a standalone Vitest test run - // For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing - tags: [/*"a11y-test"*/] - }; - `; - expect(transformed).toBe(await formatFileContent(process.cwd(), expected)); + expect(transformed).toMatchSnapshot(); }); it('should extend the existing tags property without type annotations', async () => { @@ -749,23 +683,8 @@ describe('addonA11yAddonTest', () => { `; const transformed = await transformPreviewFile(source, process.cwd()); - const expected = dedent` - export default { - // a11y-test tag controls whether accessibility tests are run as part of a standalone Vitest test run - // For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing - tags: ["existingTag"/*, "a11y-test"*/], - parameters: { - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/i, - }, - }, - }, - }; - `; - expect(transformed).toBe(await formatFileContent(process.cwd(), expected)); + expect(transformed).toMatchSnapshot(); }); }); });