- feat(storybook): remove cypress options from configuration generator - feat(react): remove cypress options from storybook-configuration - feat(react): remove cypress options from stories generator - feat(react): remove component-cypress-spec generator - chore(storybook): restore @nx/cypress dep - feat(remix): remove cypress options from storybook - feat(angular): remove cypress options from storybook-configuration - feat(angular): remove cypress options from stories generator - feat(angular): remove component-cypress-spec generator - feat(vue): remove cypress options from stories generator <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> With Storybook Interaction Testing, there's no longer a need to setup Cypress to specifically test storybook instances ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Remove cypress options for creating an e2e project specifically for testing storybook instances. Use Storybook Interaction Testing instead ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
175 lines
4.9 KiB
TypeScript
175 lines
4.9 KiB
TypeScript
import { logger, Tree } from '@nx/devkit';
|
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
import { Linter } from '@nx/eslint';
|
|
import applicationGenerator from '../application/application';
|
|
import componentGenerator from '../component/component';
|
|
import libraryGenerator from '../library/library';
|
|
import storybookConfigurationGenerator from './configuration';
|
|
|
|
// nested code imports graph from the repo, which might have innacurate graph version
|
|
jest.mock('nx/src/project-graph/project-graph', () => ({
|
|
...jest.requireActual<any>('nx/src/project-graph/project-graph'),
|
|
createProjectGraphAsync: jest
|
|
.fn()
|
|
.mockImplementation(async () => ({ nodes: {}, dependencies: {} })),
|
|
}));
|
|
|
|
describe('react:storybook-configuration', () => {
|
|
let appTree;
|
|
|
|
beforeEach(async () => {
|
|
jest.spyOn(logger, 'warn').mockImplementation(() => {});
|
|
jest.spyOn(logger, 'debug').mockImplementation(() => {});
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.resetModules();
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
it('should configure everything and install correct dependencies', async () => {
|
|
appTree = await createTestUILib('test-ui-lib');
|
|
await storybookConfigurationGenerator(appTree, {
|
|
project: 'test-ui-lib',
|
|
addPlugin: true,
|
|
});
|
|
|
|
expect(
|
|
appTree.read('test-ui-lib/.storybook/main.ts', 'utf-8')
|
|
).toMatchSnapshot();
|
|
expect(appTree.exists('test-ui-lib/tsconfig.storybook.json')).toBeTruthy();
|
|
|
|
const packageJson = JSON.parse(appTree.read('package.json', 'utf-8'));
|
|
expect(packageJson.devDependencies['@storybook/react-vite']).toBeDefined();
|
|
expect(
|
|
packageJson.devDependencies['@storybook/addon-interactions']
|
|
).toBeDefined();
|
|
expect(packageJson.devDependencies['@storybook/test-runner']).toBeDefined();
|
|
expect(
|
|
packageJson.devDependencies['@storybook/testing-library']
|
|
).toBeDefined();
|
|
});
|
|
|
|
it('should generate stories for components', async () => {
|
|
appTree = await createTestUILib('test-ui-lib');
|
|
await storybookConfigurationGenerator(appTree, {
|
|
project: 'test-ui-lib',
|
|
generateStories: true,
|
|
addPlugin: true,
|
|
});
|
|
|
|
expect(
|
|
appTree.exists('test-ui-lib/src/lib/test-ui-lib.stories.tsx')
|
|
).toBeTruthy();
|
|
});
|
|
|
|
it('should generate stories for components written in plain JS', async () => {
|
|
appTree = await createTestUILib('test-ui-lib', true);
|
|
|
|
appTree.write(
|
|
'test-ui-lib/src/lib/test-ui-libplain.js',
|
|
`import React from 'react';
|
|
|
|
import './test.scss';
|
|
|
|
export const Test = (props) => {
|
|
return (
|
|
<div>
|
|
<h1>Welcome to test component</h1>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Test;
|
|
`
|
|
);
|
|
await storybookConfigurationGenerator(appTree, {
|
|
project: 'test-ui-lib',
|
|
generateStories: true,
|
|
js: true,
|
|
addPlugin: true,
|
|
});
|
|
|
|
expect(
|
|
appTree.read('test-ui-lib/src/lib/test-ui-libplain.stories.jsx', 'utf-8')
|
|
).toMatchSnapshot();
|
|
});
|
|
|
|
it('should configure everything at once', async () => {
|
|
appTree = await createTestAppLib('test-ui-app');
|
|
await storybookConfigurationGenerator(appTree, {
|
|
project: 'test-ui-app',
|
|
addPlugin: true,
|
|
});
|
|
|
|
expect(appTree.exists('test-ui-app/.storybook/main.ts')).toBeTruthy();
|
|
expect(appTree.exists('test-ui-app/tsconfig.storybook.json')).toBeTruthy();
|
|
});
|
|
|
|
it('should generate stories for components', async () => {
|
|
appTree = await createTestAppLib('test-ui-app');
|
|
await storybookConfigurationGenerator(appTree, {
|
|
project: 'test-ui-app',
|
|
generateStories: true,
|
|
addPlugin: true,
|
|
});
|
|
|
|
// Currently the auto-generate stories feature only picks up components under the 'lib' directory.
|
|
// In our 'createTestAppLib' function, we call @nx/react:component to generate a component
|
|
// under the specified 'lib' directory
|
|
expect(
|
|
appTree.read(
|
|
'test-ui-app/src/app/my-component/my-component.stories.tsx',
|
|
'utf-8'
|
|
)
|
|
).toMatchSnapshot();
|
|
});
|
|
});
|
|
|
|
export async function createTestUILib(
|
|
libName: string,
|
|
plainJS = false
|
|
): Promise<Tree> {
|
|
let appTree = createTreeWithEmptyWorkspace();
|
|
|
|
await libraryGenerator(appTree, {
|
|
linter: Linter.EsLint,
|
|
component: true,
|
|
skipFormat: true,
|
|
skipTsConfig: false,
|
|
style: 'css',
|
|
unitTestRunner: 'none',
|
|
name: libName,
|
|
projectNameAndRootFormat: 'as-provided',
|
|
addPlugin: true,
|
|
});
|
|
return appTree;
|
|
}
|
|
|
|
export async function createTestAppLib(
|
|
libName: string,
|
|
plainJS = false
|
|
): Promise<Tree> {
|
|
let appTree = createTreeWithEmptyWorkspace();
|
|
|
|
await applicationGenerator(appTree, {
|
|
e2eTestRunner: 'none',
|
|
linter: Linter.EsLint,
|
|
skipFormat: false,
|
|
style: 'css',
|
|
unitTestRunner: 'none',
|
|
name: libName,
|
|
js: plainJS,
|
|
projectNameAndRootFormat: 'as-provided',
|
|
addPlugin: true,
|
|
});
|
|
|
|
await componentGenerator(appTree, {
|
|
name: 'my-component',
|
|
directory: `${libName}/src/app/my-component`,
|
|
style: 'css',
|
|
});
|
|
|
|
return appTree;
|
|
}
|