From 34d1eb9d1d5c12190cc5262c0e0edd5524d9008f Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Thu, 26 Sep 2024 10:51:49 -0400 Subject: [PATCH] fix(misc): update more generators and tests --- .../generators/component/component.spec.ts | 2 - ...press-component-configuration.spec.ts.snap | 77 ------------------- packages/next/src/generators/page/page.ts | 24 ++++-- .../configuration.spec.ts | 2 +- .../react/src/generators/hook/hook.spec.ts | 18 ++--- .../configuration.spec.ts | 2 +- 6 files changed, 27 insertions(+), 98 deletions(-) delete mode 100644 packages/next/src/generators/cypress-component-configuration/__snapshots__/cypress-component-configuration.spec.ts.snap diff --git a/packages/next/src/generators/component/component.spec.ts b/packages/next/src/generators/component/component.spec.ts index 9c6533f3b8d705..4b6060b44ba7d0 100644 --- a/packages/next/src/generators/component/component.spec.ts +++ b/packages/next/src/generators/component/component.spec.ts @@ -15,7 +15,6 @@ describe('component', () => { await applicationGenerator(tree, { name: appName, style: 'css', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { name: libName, @@ -24,7 +23,6 @@ describe('component', () => { skipFormat: true, skipTsConfig: false, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }); }); diff --git a/packages/next/src/generators/cypress-component-configuration/__snapshots__/cypress-component-configuration.spec.ts.snap b/packages/next/src/generators/cypress-component-configuration/__snapshots__/cypress-component-configuration.spec.ts.snap deleted file mode 100644 index aeb0eb1af82cd6..00000000000000 --- a/packages/next/src/generators/cypress-component-configuration/__snapshots__/cypress-component-configuration.spec.ts.snap +++ /dev/null @@ -1,77 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`cypress-component-configuration generator should setup nextjs app: - { - "compilerOptions": { - "allowJs": true, - "module": "commonjs", - "outDir": "../dist/out-tsc", - "sourceMap": false, - "types": [ - "cypress", - "node", - ], - } - } 1`] = ` -{ - "compilerOptions": { - "allowJs": true, - "module": "commonjs", - "outDir": "../dist/out-tsc", - "sourceMap": false, - "types": [ - "cypress", - "node", - ], - }, - "extends": "../tsconfig.json", - "include": [ - "**/*.ts", - "**/*.js", - "../cypress.config.ts", - "../**/*.cy.ts", - "../**/*.cy.tsx", - "../**/*.cy.js", - "../**/*.cy.jsx", - "../**/*.d.ts", - ], -} -`; - -exports[`cypress-component-configuration generator should setup nextjs lib: - { - "compilerOptions": { - "allowJs": true, - "module": "commonjs", - "outDir": "../dist/out-tsc", - "sourceMap": false, - "types": [ - "cypress", - "node", - ], - } - } 1`] = ` -{ - "compilerOptions": { - "allowJs": true, - "module": "commonjs", - "outDir": "../dist/out-tsc", - "sourceMap": false, - "types": [ - "cypress", - "node", - ], - }, - "extends": "../tsconfig.json", - "include": [ - "**/*.ts", - "**/*.js", - "../cypress.config.ts", - "../**/*.cy.ts", - "../**/*.cy.tsx", - "../**/*.cy.js", - "../**/*.cy.jsx", - "../**/*.d.ts", - ], -} -`; diff --git a/packages/next/src/generators/page/page.ts b/packages/next/src/generators/page/page.ts index d1ce46118e534c..84b3e4476e12a1 100644 --- a/packages/next/src/generators/page/page.ts +++ b/packages/next/src/generators/page/page.ts @@ -56,16 +56,24 @@ async function normalizeOptions(host: Tree, options: Schema) { host.exists(`${project.root}/app`) || host.exists(`${project.root}/src/app`); - const { project: projectName, fileName } = - await determineArtifactNameAndDirectoryOptions(host, { - name: options.name, - fileName: isAppRouter ? 'page' : 'index', - path: options.path, - fileExtension: 'tsx', - }); + const fileName = isAppRouter ? 'page' : 'index'; + const path = `${options.path}/${fileName}`; + const { + project: projectName, + fileName: extractedFileName, + directory, + } = await determineArtifactNameAndDirectoryOptions(host, { + name: options.name, + fileName, + path, + fileExtension: 'tsx', + }); + return { ...options, - fileName, + path, + directory, + fileName: extractedFileName, projectName, }; } diff --git a/packages/nuxt/src/generators/storybook-configuration/configuration.spec.ts b/packages/nuxt/src/generators/storybook-configuration/configuration.spec.ts index 0aa17450c27ce6..7e9ff2d087c3b4 100644 --- a/packages/nuxt/src/generators/storybook-configuration/configuration.spec.ts +++ b/packages/nuxt/src/generators/storybook-configuration/configuration.spec.ts @@ -95,7 +95,7 @@ export async function createTestApp( await componentGenerator(appTree, { name: 'my-component', - directory: `${appName}/src/components`, + path: `${appName}/src/components/my-component`, }); return appTree; diff --git a/packages/react/src/generators/hook/hook.spec.ts b/packages/react/src/generators/hook/hook.spec.ts index 57f1b9a94aefa1..f3fe55b5657fd2 100644 --- a/packages/react/src/generators/hook/hook.spec.ts +++ b/packages/react/src/generators/hook/hook.spec.ts @@ -25,7 +25,7 @@ describe('hook', () => { it('should generate files', async () => { await hookGenerator(appTree, { name: 'use-form', - path: `${projectName}/src/lib/use-form`, + path: `${projectName}/src/lib/use-form/use-form`, }); expect(appTree.exists('my-lib/src/lib/use-form/use-form.ts')).toBeTruthy(); @@ -37,7 +37,7 @@ describe('hook', () => { it('should generate files for an app', async () => { await hookGenerator(appTree, { name: 'use-form', - path: 'my-app/src/app/use-form', + path: 'my-app/src/app/use-form/use-form', }); expect(appTree.exists('my-app/src/app/use-form/use-form.ts')).toBeTruthy(); @@ -49,7 +49,7 @@ describe('hook', () => { it('handles "use" in the name', async () => { await hookGenerator(appTree, { name: 'use-hello', - path: `${projectName}/src/lib/use-hello`, + path: `${projectName}/src/lib/use-hello/use-hello`, skipTests: true, }); @@ -64,7 +64,7 @@ describe('hook', () => { it('handles "use-" in the name', async () => { await hookGenerator(appTree, { name: 'use-hello', - path: `${projectName}/src/lib/use-hello`, + path: `${projectName}/src/lib/use-hello/use-hello`, skipTests: true, }); expect( @@ -79,7 +79,7 @@ describe('hook', () => { it('should add to index.ts barrel', async () => { await hookGenerator(appTree, { name: 'hello', - path: `${projectName}/src/lib/use-hello`, + path: `${projectName}/src/lib/use-hello/use-hello`, export: true, }); @@ -91,7 +91,7 @@ describe('hook', () => { it('should not export from an app', async () => { await hookGenerator(appTree, { name: 'hello', - path: 'my-lib/src/app/use-hello', + path: 'my-lib/src/app/use-hello/use-hello', export: true, }); @@ -105,7 +105,7 @@ describe('hook', () => { it('should not generate tests', async () => { await hookGenerator(appTree, { name: 'use-hello', - path: `${projectName}/src/lib/use-hello`, + path: `${projectName}/src/lib/use-hello/use-hello`, skipTests: true, }); expect( @@ -121,7 +121,7 @@ describe('hook', () => { it('should create component under the directory', async () => { await hookGenerator(appTree, { name: 'use-hello', - path: 'my-lib/src/hooks/use-hello', + path: 'my-lib/src/hooks/use-hello/use-hello', skipTests: true, }); @@ -131,7 +131,7 @@ describe('hook', () => { it('should create with nested directories', async () => { await hookGenerator(appTree, { name: 'use-hello-world', - path: `${projectName}/src/lib/foo/use-hello-world`, + path: `${projectName}/src/lib/foo/use-hello-world/use-hello-world`, skipTests: true, }); diff --git a/packages/vue/src/generators/storybook-configuration/configuration.spec.ts b/packages/vue/src/generators/storybook-configuration/configuration.spec.ts index 32c34b29a6e2ff..570a2cf9241838 100644 --- a/packages/vue/src/generators/storybook-configuration/configuration.spec.ts +++ b/packages/vue/src/generators/storybook-configuration/configuration.spec.ts @@ -171,7 +171,7 @@ export async function createTestAppLib( await componentGenerator(appTree, { name: 'my-component', - directory: `${libName}/src/app/my-component`, + path: `${libName}/src/app/my-component/my-component`, }); return appTree;