Skip to content

Commit

Permalink
feat(storybook): add projectNameAndRootFormat as-provided in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Aug 31, 2023
1 parent 818d04c commit 3feb612
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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,
},
},
Expand All @@ -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": [
Expand All @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 () => {
Expand All @@ -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');
Expand All @@ -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(`
Expand All @@ -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: [],
};
Expand All @@ -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",
],
}
`);
Expand All @@ -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, {
Expand All @@ -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(
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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',
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 3feb612

Please sign in to comment.