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

feat(repo): update storybook to v7 (#16174) #16289

Merged
merged 1 commit into from
Apr 24, 2023
Merged
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"ignorePatterns": ["**/*.ts"],
"plugins": ["@typescript-eslint", "@nx"],
"extends": [],
"extends": ["plugin:storybook/recommended"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"no-restricted-imports": ["error", "create-nx-workspace"],
Expand Down
13 changes: 6 additions & 7 deletions e2e/storybook-angular/src/storybook-angular.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ describe('Storybook executors for Angular', () => {
const angularStorybookLib = uniq('test-ui-ng-lib');
beforeAll(() => {
newProject();
createTestUILib(angularStorybookLib);
runCLI(`g @nx/angular:library ${angularStorybookLib} --no-interactive`);
runCLI(
`generate @nrwl/angular:storybook-configuration ${angularStorybookLib} --configureCypress --generateStories --generateCypressSpecs --no-interactive`
`generate @nx/angular:storybook-configuration ${angularStorybookLib} --configureCypress --generateStories --generateCypressSpecs --no-interactive`
);
});

afterAll(() => {
cleanupProject();
});

// TODO: Enable on SB7
xdescribe('serve and build storybook', () => {
describe('serve and build storybook', () => {
afterAll(() => killPorts());

it('should serve an Angular based Storybook setup', async () => {
Expand All @@ -49,6 +48,7 @@ describe('Storybook executors for Angular', () => {
xdescribe('run cypress tests using storybook', () => {
it('should execute e2e tests using Cypress running against Storybook', async () => {
if (runCypressTests()) {
addTestButtonToUILib(angularStorybookLib);
writeFileSync(
tmpProjPath(
`apps/${angularStorybookLib}-e2e/src/e2e/test-button/test-button.component.cy.ts`
Expand Down Expand Up @@ -82,10 +82,9 @@ describe('Storybook executors for Angular', () => {
});
});

export function createTestUILib(libName: string): void {
runCLI(`g @nrwl/angular:library ${libName} --no-interactive`);
function addTestButtonToUILib(libName: string): void {
runCLI(
`g @nrwl/angular:component test-button --project=${libName} --no-interactive`
`g @nx/angular:component test-button --project=${libName} --no-interactive`
);

writeFileSync(
Expand Down
101 changes: 58 additions & 43 deletions e2e/storybook/src/storybook-nested.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
checkFilesExist,
cleanupProject,
getSelectedPackageManager,
killPorts,
readJson,
runCLI,
Expand All @@ -10,6 +11,7 @@ import {
uniq,
} from '@nrwl/e2e/utils';
import { writeFileSync } from 'fs';
import { createFileSync } from 'fs-extra';

describe('Storybook generators and executors for standalone workspaces - using React + Vite', () => {
const wsName = uniq('react');
Expand All @@ -22,10 +24,11 @@ describe('Storybook generators and executors for standalone workspaces - using R
appName,
style: 'css',
bundler: 'vite',
packageManager: getSelectedPackageManager(),
});

runCLI(
`generate @nrwl/react:storybook-configuration ${appName} --generateStories --no-interactive`
`generate @nx/react:storybook-configuration ${appName} --generateStories --no-interactive`
);

runCLI(`report`);
Expand All @@ -50,82 +53,94 @@ describe('Storybook generators and executors for standalone workspaces - using R
});
});

// TODO: Use --storybook7Configuration and re-enable this test - or else it NEEDS NODE 16
xdescribe('serve storybook', () => {
describe('serve storybook', () => {
afterEach(() => killPorts());

it('should serve a React based Storybook setup that uses Vite', async () => {
const p = await runCommandUntil(`run ${appName}:storybook`, (output) => {
return /Storybook.*started/gi.test(output);
});
p.kill();
}, 40000);
}, 60000);
});

// TODO: Use --storybook7Configuration and re-enable this test - or else it NEEDS NODE 16
xdescribe('build storybook', () => {
describe('build storybook', () => {
it('should build a React based storybook that uses Vite', () => {
runCLI(`run ${appName}:build-storybook --verbose`);
checkFilesExist(`dist/storybook/${appName}/index.html`);
}, 40000);
}, 60000);

// This test makes sure path resolution works
// This needs fixing on the Storybook side
// vite paths resolution is not working on standalone
xit('should build a React based storybook that references another lib and uses Vite', () => {
const reactLib = uniq('test-lib-react');
runCLI(`generate @nrwl/react:lib ${reactLib} --no-interactive`);
const anotherReactLib = uniq('test-another-lib-react');
runCLI(`generate @nx/react:lib ${anotherReactLib} --no-interactive`);
// create a React component we can reference
createFileSync(tmpProjPath(`${anotherReactLib}/src/lib/mytestcmp.tsx`));
writeFileSync(
tmpProjPath(`${reactLib}/src/lib/mytestcmp.tsx`),
tmpProjPath(`${anotherReactLib}/src/lib/mytestcmp.tsx`),
`
import React from 'react';
/* eslint-disable-next-line */
export interface MyTestCmpProps {}
export const MyTestCmp = (props: MyTestCmpProps) => {
return (
<div>
<h1>Welcome to test cmp!</h1>
</div>
);
};
export default MyTestCmp;
export function MyTestCmp() {
return (
<div>
<h1>Welcome to OtherLib!</h1>
</div>
);
}
export default MyTestCmp;
`
);
// update index.ts and export it
writeFileSync(
tmpProjPath(`${reactLib}/src/index.ts`),
tmpProjPath(`${anotherReactLib}/src/index.ts`),
`
export * from './lib/mytestcmp';
`
);

// create a story in the first lib to reference the cmp from the 2nd lib
// create a component and a story in the first lib to reference the cmp from the 2nd lib
createFileSync(tmpProjPath(`src/app/test-button.tsx`));
writeFileSync(
tmpProjPath(`${reactLib}/src/lib/myteststory.stories.tsx`),
tmpProjPath(`src/app/test-button.tsx`),
`
import React from 'react';
import { MyTestCmp, MyTestCmpProps } from '@${wsName}/${reactLib}';
import { MyTestCmp } from '@${wsName}/${anotherReactLib}';
export default {
component: MyTestCmp,
title: 'MyTestCmp',
};
export function TestButton() {
return (
<div>
<MyTestCmp />
</div>
);
}
export const primary = () => {
/* eslint-disable-next-line */
const props: MyTestCmpProps = {};
export default TestButton;
`
);

return <MyTestCmp />;
};
// create a story in the first lib to reference the cmp from the 2nd lib
createFileSync(tmpProjPath(`src/app/test-button.stories.tsx`));
writeFileSync(
tmpProjPath(`src/app/test-button.stories.tsx`),
`
import type { Meta } from '@storybook/react';
import { TestButton } from './test-button';
const Story: Meta<typeof TestButton> = {
component: TestButton,
title: 'TestButton',
};
export default Story;
export const Primary = {
args: {},
};
`
);

// build React lib
runCLI(`run ${reactLib}:build-storybook --verbose`);
checkFilesExist(`dist/storybook/${reactLib}/index.html`);
}, 40000);
runCLI(`run ${appName}:build-storybook --verbose`);
checkFilesExist(`dist/storybook/${appName}/index.html`);
}, 60000);
});
});
39 changes: 10 additions & 29 deletions e2e/storybook/src/storybook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,28 @@ import {
checkFilesExist,
cleanupProject,
killPorts,
newProject,
runCLI,
runCommandUntil,
tmpProjPath,
uniq,
getPackageManagerCommand,
runCommand,
newProject,
updateJson,
} from '@nrwl/e2e/utils';
import { writeFileSync } from 'fs';

describe('Storybook generators and executors for monorepos', () => {
const previousPM = process.env.SELECTED_PM;
// TODO: re-enable once the issue is fixed with long build times
describe.skip('Storybook generators and executors for monorepos', () => {
const reactStorybookLib = uniq('test-ui-lib-react');
let proj;
beforeAll(() => {
process.env.SELECTED_PM = 'yarn';
proj = newProject({
packageManager: 'yarn',
});
runCLI(`generate @nrwl/react:lib ${reactStorybookLib} --no-interactive`);
proj = newProject();
runCLI(`generate @nx/react:lib ${reactStorybookLib} --no-interactive`);
runCLI(
`generate @nrwl/react:storybook-configuration ${reactStorybookLib} --generateStories --no-interactive --bundler=webpack`
`generate @nx/react:storybook-configuration ${reactStorybookLib} --generateStories --no-interactive --bundler=webpack`
);

// TODO(jack): Overriding enhanced-resolve to 5.10.0 now until the package is fixed.
// TODO: Use --storybook7Configuration and remove this
// See: https://github.com/webpack/enhanced-resolve/issues/362
updateJson('package.json', (json) => {
json['overrides'] = {
'enhanced-resolve': '5.10.0',
};

return json;
});
runCommand(getPackageManagerCommand().install);
});

afterAll(() => {
cleanupProject();
process.env.SELECTED_PM = previousPM;
});

describe('serve and build storybook', () => {
Expand All @@ -57,18 +38,18 @@ describe('Storybook generators and executors for monorepos', () => {
}
);
p.kill();
}, 50000);
}, 60000);

it('should build a React based storybook setup that uses webpack', () => {
// build
runCLI(`run ${reactStorybookLib}:build-storybook --verbose`);
checkFilesExist(`dist/storybook/${reactStorybookLib}/index.html`);
}, 50000);
}, 60000);

// This test makes sure path resolution works
it('should build a React based storybook that references another lib and uses webpack', () => {
const anotherReactLib = uniq('test-another-lib-react');
runCLI(`generate @nrwl/react:lib ${anotherReactLib} --no-interactive`);
runCLI(`generate @nx/react:lib ${anotherReactLib} --no-interactive`);
// create a React component we can reference
writeFileSync(
tmpProjPath(`libs/${anotherReactLib}/src/lib/mytestcmp.tsx`),
Expand Down Expand Up @@ -117,6 +98,6 @@ describe('Storybook generators and executors for monorepos', () => {
// build React lib
runCLI(`run ${reactStorybookLib}:build-storybook --verbose`);
checkFilesExist(`dist/storybook/${reactStorybookLib}/index.html`);
}, 50000);
}, 60000);
});
});
14 changes: 9 additions & 5 deletions graph/client/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/* eslint-disable storybook/no-uninstalled-addons */
module.exports = {
core: { builder: 'webpack5' },
stories: [
'../src/app/**/*.stories.mdx',
'../src/app/**/*.stories.@(js|jsx|ts|tsx)',
],
stories: ['../src/app/**/*.stories.@(mdx|js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-essentials',
'@nx/react/plugins/storybook',
'storybook-dark-mode',
],
framework: {
name: '@storybook/react-webpack5',
options: {},
},
docs: {
autodocs: true,
},
};
2 changes: 0 additions & 2 deletions graph/client/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@
"storybook": {
"executor": "@nx/storybook:storybook",
"options": {
"uiFramework": "@storybook/react",
"port": 4400,
"configDir": "graph/client/.storybook"
},
Expand All @@ -259,7 +258,6 @@
"executor": "@nx/storybook:build",
"outputs": ["{options.outputDir}"],
"options": {
"uiFramework": "@storybook/react",
"configDir": "graph/client/.storybook",
"outputDir": "dist/storybook/graph-client"
},
Expand Down
14 changes: 9 additions & 5 deletions graph/ui-components/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/* eslint-disable storybook/no-uninstalled-addons */
module.exports = {
core: { builder: 'webpack5' },
stories: [
'../src/lib/**/*.stories.mdx',
'../src/lib/**/*.stories.@(js|jsx|ts|tsx)',
],
stories: ['../src/lib/**/*.stories.@(mdx|js|jsx|ts|tsx)'],
addons: ['@storybook/addon-essentials', '@nx/react/plugins/storybook'],
framework: {
name: '@storybook/react-webpack5',
options: {},
},
docs: {
autodocs: true,
},
};
2 changes: 0 additions & 2 deletions graph/ui-components/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"storybook": {
"executor": "@nx/storybook:storybook",
"options": {
"uiFramework": "@storybook/react",
"port": 4400,
"configDir": "graph/ui-components/.storybook"
},
Expand All @@ -24,7 +23,6 @@
"executor": "@nx/storybook:build",
"outputs": ["{options.outputDir}"],
"options": {
"uiFramework": "@storybook/react",
"configDir": "graph/ui-components/.storybook",
"outputDir": "dist/storybook/graph-ui-components"
},
Expand Down
14 changes: 9 additions & 5 deletions graph/ui-graph/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/* eslint-disable storybook/no-uninstalled-addons */
module.exports = {
core: { builder: 'webpack5' },
stories: [
'../src/lib/**/*.stories.mdx',
'../src/lib/**/*.stories.@(js|jsx|ts|tsx)',
],
stories: ['../src/lib/**/*.stories.@(mdx|js|jsx|ts|tsx)'],
addons: ['@storybook/addon-essentials', '@nx/react/plugins/storybook'],
framework: {
name: '@storybook/react-webpack5',
options: {},
},
docs: {
autodocs: true,
},
};
Loading