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

Addon Test: Error when addon interactions exists #29338

Open
wants to merge 1 commit into
base: unified-ui-testing
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
3 changes: 3 additions & 0 deletions code/addons/interactions/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ export const checkActionsLoaded = (configDir: string) => {
getConfig: (configFile) => serverRequire(configFile),
});
};

// This annotation is read by addon-test, so it can throw an error if both addons are used
export const ADDON_INTERACTIONS_IN_USE = true;
36 changes: 35 additions & 1 deletion code/addons/test/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
TESTING_MODULE_RUN_REQUEST,
TESTING_MODULE_WATCH_MODE_REQUEST,
} from 'storybook/internal/core-events';
import type { Options } from 'storybook/internal/types';
import 'storybook/internal/core-events';
import type { Options, PresetProperty } from 'storybook/internal/types';

import { dedent } from 'ts-dedent';

import { bootTestRunner } from './node/boot-test-runner';

Expand All @@ -28,6 +31,37 @@ export const checkActionsLoaded = (configDir: string) => {
});
};

export const previewAnnotations: PresetProperty<'previewAnnotations'> = async (
entry = [],
options
) => {
checkActionsLoaded(options.configDir);
return entry;
};

export const managerEntries: PresetProperty<'managerEntries'> = async (entry = [], options) => {
// Throw an error when addon-interactions is used.
// This is done by reading an annotation defined in addon-interactions, which although not ideal,
// is a way to handle addon conflict without having to worry about the order of which they are registered
const annotation = await options.presets.apply('ADDON_INTERACTIONS_IN_USE', false);
if (annotation) {
// eslint-disable-next-line local-rules/no-uncategorized-errors
const error = new Error(
dedent`
You have both addon-interactions and addon-test enabled, which is not allowed.

addon-test is a replacement for addon-interactions, please uninstall and remove addon-interactions from the addons list in your main config at ${options.configDir}.
`
);
error.name = 'AddonConflictError';

throw error;
}

// for whatever reason seems like the return type of managerEntries is not correct (it expects never instead of string[])
return entry as never;
Comment on lines +61 to +62
Copy link
Contributor

Choose a reason for hiding this comment

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

style: casting entry to never may hide type issues

};

// eslint-disable-next-line @typescript-eslint/naming-convention
export const experimental_serverChannel = async (channel: Channel, options: Options) => {
const core = await options.presets.apply('core');
Expand Down