diff --git a/e2e/storybook-angular/src/storybook-angular.test.ts b/e2e/storybook-angular/src/storybook-angular.test.ts index ebef66d5e51e5..9d81f21cc2e8e 100644 --- a/e2e/storybook-angular/src/storybook-angular.test.ts +++ b/e2e/storybook-angular/src/storybook-angular.test.ts @@ -2,12 +2,12 @@ import { checkFilesExist, cleanupProject, getPackageManagerCommand, + getSelectedPackageManager, isNotWindows, killPorts, - newProject, - readFile, runCLI, runCommand, + runCreateWorkspace, runCypressTests, tmpProjPath, uniq, @@ -16,10 +16,21 @@ import { import { writeFileSync } from 'fs'; describe('Storybook for Angular', () => { - let proj: string; + const packageManager = getSelectedPackageManager() || 'yarn'; + const proj = uniq('proj'); + const appName = uniq('app'); beforeAll(() => { - proj = newProject(); + runCreateWorkspace(proj, { + preset: 'angular-monorepo', + appName, + style: 'css', + packageManager, + }); + + runCLI( + `generate @nrwl/angular:storybook-configuration ${appName} --generateStories --no-interactive` + ); // TODO(jack): Overriding enhanced-resolve to 5.10.0 now until the package is fixed. // See: https://github.com/webpack/enhanced-resolve/issues/362 @@ -46,213 +57,62 @@ describe('Storybook for Angular', () => { afterAll(() => cleanupProject()); - describe('build storybook', () => { + describe('Storybook builder', () => { + it('shoud build storybook', () => { + runCLI(`run ${appName}:build-storybook`); + checkFilesExist(`dist/storybook/${appName}/index.html`); + }); + }); + + describe('run cypress tests using storybook', () => { let angularStorybookLib; beforeAll(() => { angularStorybookLib = uniq('test-ui-lib'); createTestUILib(angularStorybookLib); runCLI( - `generate @nrwl/angular:storybook-configuration ${angularStorybookLib} --generateStories --no-interactive` + `generate @nrwl/angular:storybook-configuration ${angularStorybookLib} --configureCypress --generateStories --generateCypressSpecs --no-interactive` ); }); - xit('should execute e2e tests using Cypress running against Storybook', async () => { - if (isNotWindows()) { - const myapp = uniq('myapp'); - runCLI(`generate @nrwl/angular:app ${myapp} --no-interactive`); - - const myAngularLib = uniq('test-ui-lib'); - createTestUILib(myAngularLib); - const myReactLib = uniq('test-ui-lib-react'); - runCLI(`generate @nrwl/react:lib ${myReactLib} --no-interactive`); - runCLI( - `generate @nrwl/react:component Button --project=${myReactLib} --no-interactive` - ); - writeFileSync( - tmpProjPath(`libs/${myReactLib}/src/lib/button.tsx`), - ` - import React from 'react'; - - import './button.css'; - - export type ButtonStyle = 'default' | 'primary' | 'warning'; - - /* eslint-disable-next-line */ - export interface ButtonProps { - text?: string; - style?: ButtonStyle; - padding?: number; - } - - export const Button = (props: ButtonProps) => { - return ( - - ); - }; - - export default Button; - ` - ); - writeFileSync( - tmpProjPath(`libs/${myReactLib}/src/lib/button.stories.tsx`), - ` - import { Story, Meta } from '@storybook/react'; - import { Button, ButtonProps } from './button'; - - export default { - component: Button, - title: 'Button', - } as Meta; - - const Template: Story = (args) => -

You are {{age}} years old.

+ ` ); runCLI( diff --git a/e2e/storybook/src/storybook.test.ts b/e2e/storybook/src/storybook.test.ts index ecfbc6bad6d9a..51351dfb48fa5 100644 --- a/e2e/storybook/src/storybook.test.ts +++ b/e2e/storybook/src/storybook.test.ts @@ -2,7 +2,6 @@ import { checkFilesExist, cleanupProject, killPorts, - newProject, runCLI, runCommandUntil, tmpProjPath, @@ -10,19 +9,30 @@ import { updateJson, getPackageManagerCommand, runCommand, + getSelectedPackageManager, + runCreateWorkspace, } from '@nrwl/e2e/utils'; import { writeFileSync } from 'fs'; -describe('Storybook schematics', () => { +describe('Storybook generators for non-angular projects', () => { const previousPM = process.env.SELECTED_PM; let reactStorybookLib: string; - let proj: string; + const packageManager = getSelectedPackageManager() || 'yarn'; + const proj = uniq('proj'); + const appName = uniq('app'); beforeAll(() => { process.env.SELECTED_PM = 'yarn'; - proj = newProject(); + runCreateWorkspace(proj, { + preset: 'react-monorepo', + appName, + style: 'css', + packageManager, + bundler: 'webpack', + }); + reactStorybookLib = uniq('test-ui-lib-react'); runCLI(`generate @nrwl/react:lib ${reactStorybookLib} --no-interactive`); @@ -61,7 +71,12 @@ describe('Storybook schematics', () => { }, 1000000); }); - describe('build storybook', () => { + // TODO: Re-enable this test when Nx uses only Storybook 7 (Nx 16) + // This fails for Node 18 because Storybook 6.5 uses webpack even in non-webpack projects + // https://github.com/storybookjs/builder-vite/issues/414#issuecomment-1287536049 + // https://github.com/storybookjs/storybook/issues/20209 + // Error: error:0308010C:digital envelope routines::unsupported + xdescribe('build storybook', () => { it('should build and lint a React based storybook', () => { // build runCLI(`run ${reactStorybookLib}:build-storybook --verbose`); @@ -72,27 +87,23 @@ describe('Storybook schematics', () => { expect(output).toContain('All files pass linting.'); }, 1000000); - it('should build a React based storybook that references another lib', () => { + // I am not sure how much sense this test makes - Maybe it's just adding noise + xit('should build a React based storybook that references another lib', () => { const anotherReactLib = uniq('test-another-lib-react'); runCLI(`generate @nrwl/react:lib ${anotherReactLib} --no-interactive`); // create a React component we can reference writeFileSync( tmpProjPath(`libs/${anotherReactLib}/src/lib/mytestcmp.tsx`), ` - import React from 'react'; - - /* eslint-disable-next-line */ - export interface MyTestCmpProps {} - - export const MyTestCmp = (props: MyTestCmpProps) => { - return ( -
-

Welcome to test cmp!

-
- ); - }; - - export default MyTestCmp; + export function MyTestCmp() { + return ( +
+

Welcome to OtherLib!

+
+ ); + } + + export default MyTestCmp; ` ); // update index.ts and export it @@ -109,21 +120,19 @@ describe('Storybook schematics', () => { `libs/${reactStorybookLib}/src/lib/myteststory.stories.tsx` ), ` - import React from 'react'; - - import { MyTestCmp, MyTestCmpProps } from '@${proj}/${anotherReactLib}'; + import type { Meta } from '@storybook/react'; + import { MyTestCmp } from '@${proj}/${anotherReactLib}'; - export default { + const Story: Meta = { component: MyTestCmp, title: 'MyTestCmp', }; + export default Story; - export const primary = () => { - /* eslint-disable-next-line */ - const props: MyTestCmpProps = {}; - - return ; + export const Primary = { + args: {}, }; + ` );