Skip to content

Commit

Permalink
feat(storybook): get port of storybook and give it to cypress
Browse files Browse the repository at this point in the history
ISSUES CLOSED: nrwl#3953
  • Loading branch information
mandarini committed Dec 15, 2022
1 parent c051a27 commit c967123
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/storybook/presets/cypress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { nxE2EPreset } from '@nrwl/cypress/plugins/cypress-preset';
import {
nxE2EPreset,
getProjectConfigByPath,
} from '@nrwl/cypress/plugins/cypress-preset';
import { ProjectGraph, readCachedProjectGraph } from '@nrwl/devkit';

export function nxE2EStorybookPreset(filePath: string) {
let graph = readCachedProjectGraph();

const projectConfig = getProjectConfigByPath(graph, filePath);

const projectName = projectConfig.name;

return {
...nxE2EPreset(filePath),
baseUrl: 'http://localhost:4400',
Expand Down
19 changes: 19 additions & 0 deletions packages/storybook/src/executors/storybook/storybook.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ export default async function* storybookExecutor(
function runInstance(options: StorybookExecutorOptions) {
const env = process.env.NODE_ENV ?? 'development';
process.env.NODE_ENV = env;
const originalConsoleLog = console.log;
console.log = function (...args) {
const localhostString = 'http://localhost:';
if (args[0].includes(localhostString)) {
const indexOfLocalHost = args[0].indexOf(localhostString);
console.info(
args[0].slice(
indexOfLocalHost + localhostString.length,
indexOfLocalHost + localhostString.length + 4
),
indexOfLocalHost
);
process.env.NXPORT = args[0].slice(
indexOfLocalHost + localhostString.length,
indexOfLocalHost + localhostString.length + 4
);
}
originalConsoleLog.apply(console, args);
};
return buildDev({
...options,
configType: env.toUpperCase(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { defineConfig } from 'cypress';
import { nxE2EStorybookPreset } from '@nrwl/storybook/presets/cypress';

export default defineConfig({
e2e: nxE2EStorybookPreset(__dirname)
e2e: nxE2EStorybookPreset(__filename)
});

0 comments on commit c967123

Please sign in to comment.