Skip to content

Commit

Permalink
Fix for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Jan 9, 2025
1 parent 090276b commit fc2610f
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 () => {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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();
});
});
});

0 comments on commit fc2610f

Please sign in to comment.