Skip to content

Commit

Permalink
Rename a11ytest tag to a11y-test
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Jan 7, 2025
1 parent d31350d commit 21b452a
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion code/addons/a11y/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const TEST_PROVIDER_ID = 'storybook/addon-a11y/test-provider';

export const EVENTS = { RESULT, REQUEST, RUNNING, ERROR, MANUAL };

export const A11Y_TEST_TAG = 'a11ytest';
export const A11Y_TEST_TAG = 'a11y-test';
2 changes: 1 addition & 1 deletion code/addons/a11y/src/preview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('afterEach', () => {
});
});

it('should run accessibility checks if "a11ytest" flag is not available and is not running in Vitest', async () => {
it('should run accessibility checks if "a11y-test" flag is not available and is not running in Vitest', async () => {
const context = createContext({
tags: [],
});
Expand Down
2 changes: 1 addition & 1 deletion code/addons/test/src/components/TestProviderRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const TestProviderRender: FC<TestProviderRenderProps> = ({
return acc;
}, new Set<Tag>());

if (allTags.has('a11ytest')) {
if (allTags.has('a11y-test')) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion code/addons/test/src/vitest-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin> => {
? (envConfig.a11y ?? false)
: false;

return shouldSetTag ? ['a11ytest'] : [];
return shouldSetTag ? ['a11y-test'] : [];
},
},
// if there is a test.browser config AND test.browser.screenshotFailures is not explicitly set, we set it to false
Expand Down
4 changes: 2 additions & 2 deletions code/core/template/stories/tags-add.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const Inheritance = {
tags: ['story-one', '!vitest'],
play: async ({ canvasElement, tags }: PlayFunctionContext<any>) => {
const canvas = within(canvasElement);
if (tags.includes('a11ytest')) {
if (tags.includes('a11y-test')) {
await expect(JSON.parse(canvas.getByTestId('pre').innerText)).toEqual({
tags: ['a11ytest', 'story-one'],
tags: ['a11y-test', 'story-one'],
});
} else {
await expect(JSON.parse(canvas.getByTestId('pre').innerText)).toEqual({
Expand Down
4 changes: 2 additions & 2 deletions code/core/template/stories/tags-config.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export const Inheritance = {
tags: ['story-one', '!vitest'],
play: async ({ canvasElement, tags }: PlayFunctionContext<any>) => {
const canvas = within(canvasElement);
if (tags.includes('a11ytest')) {
if (tags.includes('a11y-test')) {
await expect(JSON.parse(canvas.getByTestId('pre').innerText)).toEqual({
tags: [
'dev',
'test',
'a11ytest',
'a11y-test',
'component-one',
'component-two',
'autodocs',
Expand Down
4 changes: 2 additions & 2 deletions code/core/template/stories/tags-remove.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const Inheritance = {
tags: ['story-one', '!vitest'],
play: async ({ canvasElement, tags }: PlayFunctionContext<any>) => {
const canvas = within(canvasElement);
if (tags.includes('a11ytest')) {
if (tags.includes('a11y-test')) {
await expect(JSON.parse(canvas.getByTestId('pre').innerText)).toEqual({
tags: ['dev', 'test', 'a11ytest', 'component-one', 'autodocs', 'story-one'],
tags: ['dev', 'test', 'a11y-test', 'component-one', 'autodocs', 'story-one'],
});
} else {
await expect(JSON.parse(canvas.getByTestId('pre').innerText)).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please manually update your .storybook/preview.<ts|js> file to include the follo
export default {
...
+ tags: ["a11ytest"],
+ tags: ["a11y-test"],
}
For more information, please refer to the accessibility addon documentation:
Expand Down Expand Up @@ -88,7 +88,7 @@ Please manually update your .storybook/preview.<ts|js> file to include the follo
export default {
...
+ tags: ["a11ytest"],
+ tags: ["a11y-test"],
}
For more information, please refer to the accessibility addon documentation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('addonA11yAddonTest', () => {
} else {
return `
export default {
tags: ['a11ytest'],
tags: ['a11y-test'],
}
`;
}
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('addonA11yAddonTest', () => {
} else {
return `
export default {
tags: ['a11ytest'],
tags: ['a11y-test'],
}
`;
}
Expand Down Expand Up @@ -588,9 +588,9 @@ describe('addonA11yAddonTest', () => {
},
},
// a11ytest tag controls whether accessibility tests are run as part of a standalone Vitest test run
// 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: ['a11ytest']
tags: ['a11y-test']
};
export default preview;
Expand Down Expand Up @@ -621,7 +621,7 @@ describe('addonA11yAddonTest', () => {
},
},
}
export const tags = ["a11ytest"];
export const tags = ["a11y-test"];
`;

expect(transformed).toBe(expected);

Check failure on line 627 in code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.test.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/automigrate/fixes/addon-a11y-addon-test.test.ts > addonA11yAddonTest > transformPreviewFile > should add a new tags property if it does not exist and a default export does not exist

AssertionError: expected '\r\n export const parameters =…' to be '\n export const parameters = {…' // Object.is equality - Expected + Received - + - export const parameters = { + export const parameters = { - controls: { + controls: { - matchers: { + matchers: { - color: /(background|color)$/i, + color: /(background|color)$/i, - date: /Date$/i, + date: /Date$/i, - }, + }, - }, + }, - } + } - export const tags = ["a11y-test"]; + export const tags = ["a11y-test"]; ❯ src/automigrate/fixes/addon-a11y-addon-test.test.ts:627:27
Expand Down Expand Up @@ -651,9 +651,9 @@ describe('addonA11yAddonTest', () => {
import type { Preview } from '@storybook/react';
const preview: Preview = {
// a11ytest tag controls whether accessibility tests are run as part of a standalone Vitest test run
// 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', 'a11ytest'],
tags: ['existingTag', 'a11y-test'],
parameters: {
controls: {
matchers: {
Expand All @@ -670,12 +670,12 @@ describe('addonA11yAddonTest', () => {
expect(transformed).toBe(j(expected).toSource());

Check failure on line 670 in code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.test.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/automigrate/fixes/addon-a11y-addon-test.test.ts > addonA11yAddonTest > transformPreviewFile > should extend the existing tags property

AssertionError: expected '\r\n import type { Preview } f…' to be '\r\n import type { Preview } f…' // Object.is equality - Expected + Received 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 + // 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 + // For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing - tags: ['existingTag', 'a11y-test'], + tags: ["existingTag", "a11y-test"], parameters: { controls: { matchers: { color: /(background|color)$/i, date: /Date$/i, }, }, }, }; export default preview; ❯ src/automigrate/fixes/addon-a11y-addon-test.test.ts:670:27
});

it('should not add a11ytest if it already exists in the tags property', () => {
it('should not add a11y-test if it already exists in the tags property', () => {
const source = `
import type { Preview } from '@storybook/react';
const preview: Preview = {
tags: ['a11ytest'],
tags: ['a11y-test'],
parameters: {
controls: {
matchers: {
Expand Down Expand Up @@ -720,9 +720,9 @@ describe('addonA11yAddonTest', () => {
},
},
// a11ytest tag controls whether accessibility tests are run as part of a standalone Vitest test run
// 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: ["a11ytest"]
tags: ["a11y-test"]
};
`;

Expand All @@ -747,9 +747,9 @@ describe('addonA11yAddonTest', () => {
const transformed = transformPreviewFile(source);
const expected = `
export default {
// a11ytest tag controls whether accessibility tests are run as part of a standalone Vitest test run
// 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', 'a11ytest'],
tags: ['existingTag', 'a11y-test'],
parameters: {
controls: {
matchers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const addonA11yAddonTest: Fix<AddonA11yAddonTestOptions> = {
const previewSetupSource = readFileSync(previewFile, 'utf8');

skipVitestSetupTransformation = vitestSetupSource.includes('@storybook/addon-a11y');
skipPreviewTransformation = previewSetupSource.includes('a11ytest');
skipPreviewTransformation = previewSetupSource.includes('a11y-test');

if (skipVitestSetupTransformation && skipPreviewTransformation) {
return null;
Expand Down Expand Up @@ -194,7 +194,7 @@ export const addonA11yAddonTest: Fix<AddonA11yAddonTestOptions> = {
${picocolors.gray('export default {')}
${picocolors.gray('...')}
${picocolors.green('+ tags: ["a11ytest"],')}
${picocolors.green('+ tags: ["a11y-test"],')}
${picocolors.gray('}')}
`);
} else {
Expand Down Expand Up @@ -275,11 +275,11 @@ export function transformPreviewFile(source: string) {
const tags = previewConfig.getFieldNode(['tags']);
const tagsValue = previewConfig.getFieldValue(['tags']) ?? [];

if (tags && tagsValue && (tagsValue.includes('a11ytest') || tagsValue.includes('!a11ytest'))) {
if (tags && tagsValue && (tagsValue.includes('a11y-test') || tagsValue.includes('!a11y-test'))) {
return source;
}

previewConfig.setFieldValue(['tags'], [...tagsValue, 'a11ytest']);
previewConfig.setFieldValue(['tags'], [...tagsValue, 'a11y-test']);

const formattedPreviewConfig = formatConfig(previewConfig);
const lines = formattedPreviewConfig.split('\n');
Expand All @@ -295,7 +295,7 @@ export function transformPreviewFile(source: string) {
const indentation = tagsLine?.match(/^\s*/)?.[0];

// Add the comment with the same indentation level
const comment = `${indentation}// a11ytest tag controls whether accessibility tests are run as part of a standalone Vitest test run\n${indentation}// For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing`;
const comment = `${indentation}// a11y-test tag controls whether accessibility tests are run as part of a standalone Vitest test run\n${indentation}// For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing`;
lines.splice(tagsLineIndex, 0, comment);

return lines.join('\n');
Expand Down
2 changes: 1 addition & 1 deletion scripts/tasks/sandbox-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ export const extendPreview: Task['run'] = async ({ template, sandboxDir }) => {
const previewConfig = await readConfig({ cwd: sandboxDir, fileName: 'preview' });

if (template.expected.builder.includes('vite')) {
previewConfig.setFieldValue(['tags'], ['vitest', '!a11ytest']);
previewConfig.setFieldValue(['tags'], ['vitest', '!a11y-test']);
}

await writeConfig(previewConfig);
Expand Down

0 comments on commit 21b452a

Please sign in to comment.