Skip to content

Commit

Permalink
fix(storybook): return baseUrl from storybook and use in cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Jan 12, 2023
1 parent 9f19e93 commit 75d2c6e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/cypress/src/executors/cypress/cypress.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ async function* startDevServer(
for await (const output of await runExecutor<{
success: boolean;
baseUrl?: string;
info?: { port: number; baseUrl?: string };
}>(
{ project, target, configuration },
// @NOTE: Do not forward watch option if not supported by the target dev server,
Expand All @@ -183,7 +184,15 @@ async function* startDevServer(
)) {
if (!output.success && !opts.watch)
throw new Error('Could not compile application files');
yield opts.baseUrl || (output.baseUrl as string);
if (
!opts.baseUrl &&
!output.baseUrl &&
!output.info.baseUrl &&
output.info.port
) {
output.baseUrl = `http://localhost:${output.info.port}`;
}
yield opts.baseUrl || output.baseUrl || output.info.baseUrl;
}
}

Expand Down
15 changes: 13 additions & 2 deletions packages/storybook/src/executors/storybook/storybook.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { CommonNxStorybookConfig } from '../models';
export default async function* storybookExecutor(
options: CLIOptions & CommonNxStorybookConfig,
context: ExecutorContext
): AsyncGenerator<{ success: boolean; info?: { port: number } }> {
): AsyncGenerator<{
success: boolean;
info?: { port: number; baseUrl?: string };
}> {
const storybook7 = isStorybookV7();
storybookConfigExistsCheck(options.configDir, context.projectName);
if (storybook7) {
Expand All @@ -22,7 +25,15 @@ export default async function* storybookExecutor(
buildOptions,
storybook7
);
yield { success: true, info: { port: result.port } };
yield {
success: true,
info: {
port: result.port,
baseUrl: `${options.https ? 'https' : 'http'}://${
options.host ?? 'localhost'
}:${result.port}`,
},
};
await new Promise<{ success: boolean }>(() => {});
} else {
// TODO (katerina): Remove when Storybook 7
Expand Down

0 comments on commit 75d2c6e

Please sign in to comment.