feat(storybook): add projectNameAndRootFormat as-provided in tests (#18936)

This commit is contained in:
Katerina Skroumpelou 2023-08-31 18:59:54 +03:00 committed by GitHub
parent a2493b92f8
commit b17b30d13b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 41 deletions

View File

@ -12,7 +12,9 @@ describe('Storybook executors for Angular', () => {
const angularStorybookLib = uniq('test-ui-ng-lib');
beforeAll(() => {
newProject();
runCLI(`g @nx/angular:library ${angularStorybookLib} --no-interactive`);
runCLI(
`g @nx/angular:library ${angularStorybookLib} --project-name-and-root-format=as-provided --no-interactive`
);
runCLI(
`generate @nx/angular:storybook-configuration ${angularStorybookLib} --generateStories --no-interactive`
);

View File

@ -72,7 +72,7 @@ describe('Storybook generators and executors for standalone workspaces - using R
it('should build a React based storybook that references another lib and uses Vite', () => {
runCLI(
`generate @nx/react:lib my-lib --bundler=vite --unitTestRunner=none --no-interactive`
`generate @nx/react:lib my-lib --bundler=vite --unitTestRunner=none --project-name-and-root-format=as-provided --no-interactive`
);
// create a component and a story in the first lib to reference the cmp from the 2nd lib

View File

@ -18,7 +18,7 @@ describe('Storybook generators and executors for monorepos', () => {
beforeAll(async () => {
proj = newProject();
runCLI(
`generate @nx/react:app ${reactStorybookApp} --bundler=webpack --no-interactive`
`generate @nx/react:app ${reactStorybookApp} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive`
);
await setMaxWorkers();
runCLI(
@ -55,15 +55,15 @@ describe('Storybook generators and executors for monorepos', () => {
// This test makes sure path resolution works
it('should build a React based storybook that references another lib and uses rollup', () => {
runCLI(
`generate @nx/react:lib my-lib --bundler=rollup --unitTestRunner=none --no-interactive`
`generate @nx/react:lib my-lib --bundler=rollup --unitTestRunner=none --project-name-and-root-format=as-provided --no-interactive`
);
// create a component in the first lib to reference the cmp from the 2nd lib
createFileSync(
tmpProjPath(`apps/${reactStorybookApp}/src/app/test-button.tsx`)
tmpProjPath(`${reactStorybookApp}/src/app/test-button.tsx`)
);
writeFileSync(
tmpProjPath(`apps/${reactStorybookApp}/src/app/test-button.tsx`),
tmpProjPath(`${reactStorybookApp}/src/app/test-button.tsx`),
`
import { MyLib } from '@${proj}/my-lib';
@ -81,12 +81,10 @@ describe('Storybook generators and executors for monorepos', () => {
// create a story in the first lib to reference the cmp from the 2nd lib
createFileSync(
tmpProjPath(`apps/${reactStorybookApp}/src/app/test-button.stories.tsx`)
tmpProjPath(`${reactStorybookApp}/src/app/test-button.stories.tsx`)
);
writeFileSync(
tmpProjPath(
`apps/${reactStorybookApp}/src/app/test-button.stories.tsx`
),
tmpProjPath(`${reactStorybookApp}/src/app/test-button.stories.tsx`),
`
import type { Meta } from '@storybook/react';
import { TestButton } from './test-button';

View File

@ -22,11 +22,11 @@ export default config;
exports[`@nx/storybook:configuration for Storybook v7 basic functionalities should generate TypeScript Configuration files by default 1`] = `
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"$schema": "../node_modules/nx/schemas/project-schema.json",
"name": "test-ui-lib",
"projectType": "library",
"root": "libs/test-ui-lib",
"sourceRoot": "libs/test-ui-lib/src",
"root": "test-ui-lib",
"sourceRoot": "test-ui-lib/src",
"tags": [],
"targets": {
"build-storybook": {
@ -39,7 +39,7 @@ exports[`@nx/storybook:configuration for Storybook v7 basic functionalities shou
"options": {
"browserTarget": "test-ui-lib:build-storybook",
"compodoc": false,
"configDir": "libs/test-ui-lib/.storybook",
"configDir": "test-ui-lib/.storybook",
"outputDir": "dist/storybook/test-ui-lib",
},
"outputs": [
@ -50,7 +50,7 @@ exports[`@nx/storybook:configuration for Storybook v7 basic functionalities shou
"executor": "@nx/linter:eslint",
"options": {
"lintFilePatterns": [
"libs/test-ui-lib/**/*.ts",
"test-ui-lib/**/*.ts",
],
},
"outputs": [
@ -67,7 +67,7 @@ exports[`@nx/storybook:configuration for Storybook v7 basic functionalities shou
"options": {
"browserTarget": "test-ui-lib:build-storybook",
"compodoc": false,
"configDir": "libs/test-ui-lib/.storybook",
"configDir": "test-ui-lib/.storybook",
"port": 4400,
},
},
@ -80,7 +80,7 @@ exports[`@nx/storybook:configuration for Storybook v7 basic functionalities shou
},
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "libs/test-ui-lib/jest.config.ts",
"jestConfig": "test-ui-lib/jest.config.ts",
"passWithNoTests": true,
},
"outputs": [
@ -90,7 +90,7 @@ exports[`@nx/storybook:configuration for Storybook v7 basic functionalities shou
"test-storybook": {
"executor": "nx:run-commands",
"options": {
"command": "test-storybook -c libs/test-ui-lib/.storybook --url=http://localhost:4400",
"command": "test-storybook -c test-ui-lib/.storybook --url=http://localhost:4400",
},
},
},
@ -127,9 +127,9 @@ exports[`@nx/storybook:configuration for Storybook v7 basic functionalities shou
"outDir": ""
},
"files": [
"../../node_modules/@nx/react/typings/styled-jsx.d.ts",
"../../node_modules/@nx/react/typings/cssmodule.d.ts",
"../../node_modules/@nx/react/typings/image.d.ts"
"../node_modules/@nx/react/typings/styled-jsx.d.ts",
"../node_modules/@nx/react/typings/cssmodule.d.ts",
"../node_modules/@nx/react/typings/image.d.ts"
],
"exclude": [
"src/**/*.spec.ts",

View File

@ -41,6 +41,7 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
await libraryGenerator(tree, {
name: 'test-ui-lib',
bundler: 'none',
projectNameAndRootFormat: 'as-provided',
});
writeJson(tree, 'package.json', {
devDependencies: {
@ -66,15 +67,11 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
expect(project).toMatchSnapshot();
expect(tree.read('.storybook/main.ts', 'utf-8')).toMatchSnapshot();
expect(tree.exists('test-ui-lib/tsconfig.storybook.json')).toBeFalsy();
expect(
tree.exists('libs/test-ui-lib/tsconfig.storybook.json')
).toBeFalsy();
expect(
tree.read('libs/test-ui-lib/.storybook/main.ts', 'utf-8')
tree.read('test-ui-lib/.storybook/main.ts', 'utf-8')
).toMatchSnapshot();
expect(
tree.exists('libs/test-ui-lib/.storybook/preview.ts')
).toBeTruthy();
expect(tree.exists('test-ui-lib/.storybook/preview.ts')).toBeTruthy();
});
it('should update `tsconfig.lib.json` file', async () => {
@ -85,7 +82,7 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
});
const tsconfigJson = readJson<TsConfig>(
tree,
'libs/test-ui-lib/tsconfig.lib.json'
'test-ui-lib/tsconfig.lib.json'
) as Required<TsConfig>;
expect(tsconfigJson.exclude).toContain('**/*.stories.ts');
@ -102,7 +99,7 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
});
const tsconfigJson = readJson<TsConfig>(
tree,
'libs/test-ui-lib/tsconfig.json'
'test-ui-lib/tsconfig.json'
);
expect(tsconfigJson.references).toMatchInlineSnapshot(`
@ -124,9 +121,10 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
await libraryGenerator(tree, {
name: 'test-ui-lib2',
linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
});
updateJson(tree, 'libs/test-ui-lib2/.eslintrc.json', (json) => {
updateJson(tree, 'test-ui-lib2/.eslintrc.json', (json) => {
json.parserOptions = {
project: [],
};
@ -139,11 +137,11 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
uiFramework: '@storybook/react-webpack5',
});
expect(readJson(tree, 'libs/test-ui-lib2/.eslintrc.json').parserOptions)
expect(readJson(tree, 'test-ui-lib2/.eslintrc.json').parserOptions)
.toMatchInlineSnapshot(`
{
"project": [
"libs/test-ui-lib2/tsconfig.storybook.json",
"test-ui-lib2/tsconfig.storybook.json",
],
}
`);
@ -153,6 +151,7 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
await libraryGenerator(tree, {
name: 'test-ui-lib2',
linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
});
await configurationGenerator(tree, {
@ -162,7 +161,7 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
});
expect(
tree.read('libs/test-ui-lib2/tsconfig.storybook.json', 'utf-8')
tree.read('test-ui-lib2/tsconfig.storybook.json', 'utf-8')
).toMatchSnapshot();
expect(
@ -178,13 +177,11 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
});
expect(
tree.read('libs/test-ui-lib/.storybook/main.ts', 'utf-8')
tree.read('test-ui-lib/.storybook/main.ts', 'utf-8')
).toMatchSnapshot();
expect(
tree.exists('libs/test-ui-lib/.storybook/preview.ts')
).toBeTruthy();
expect(tree.exists('libs/test-ui-lib/.storybook/main.js')).toBeFalsy();
expect(tree.exists('libs/test-ui-lib/.storybook/preview.js')).toBeFalsy();
expect(tree.exists('test-ui-lib/.storybook/preview.ts')).toBeTruthy();
expect(tree.exists('test-ui-lib/.storybook/main.js')).toBeFalsy();
expect(tree.exists('test-ui-lib/.storybook/preview.js')).toBeFalsy();
});
it('should add test-storybook target', async () => {
@ -223,7 +220,7 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
executor: 'nx:run-commands',
options: {
command:
'test-storybook -c libs/test-ui-lib/.storybook --url=http://localhost:4400',
'test-storybook -c test-ui-lib/.storybook --url=http://localhost:4400',
},
});
});

View File

@ -17,6 +17,7 @@ describe('@nx/storybook:cypress-project', () => {
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
await libraryGenerator(tree, {
name: 'test-ui-lib',
projectNameAndRootFormat: 'as-provided',
});
});
afterEach(() => jest.clearAllMocks());