diff --git a/packages/expo/src/generators/component/component.spec.ts b/packages/expo/src/generators/component/component.spec.ts index bb617cdfadd94a..799b5ddf5b0c67 100644 --- a/packages/expo/src/generators/component/component.spec.ts +++ b/packages/expo/src/generators/component/component.spec.ts @@ -59,6 +59,16 @@ describe('component', () => { expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy(); }); + it('should handle path with file extension', async () => { + await expoComponentGenerator(appTree, { + ...defaultSchema, + path: 'my-lib/src/lib/hello/hello.tsx', + }); + + expect(appTree.exists('my-lib/src/lib/hello/hello.tsx')).toBeTruthy(); + expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy(); + }); + it('should generate files for an app', async () => { await expoComponentGenerator(appTree, { ...defaultSchema, diff --git a/packages/next/src/generators/component/component.spec.ts b/packages/next/src/generators/component/component.spec.ts index 7ee0934f6b8029..d89527922f5390 100644 --- a/packages/next/src/generators/component/component.spec.ts +++ b/packages/next/src/generators/component/component.spec.ts @@ -40,6 +40,19 @@ describe('component', () => { ).toBeTruthy(); }); + it('should handle path with file extension', async () => { + await componentGenerator(tree, { + path: `${appName}/components/hello/hello.tsx`, + style: 'css', + }); + + expect(tree.exists('my-app/components/hello/hello.tsx')).toBeTruthy(); + expect(tree.exists('my-app/components/hello/hello.spec.tsx')).toBeTruthy(); + expect( + tree.exists('my-app/components/hello/hello.module.css') + ).toBeTruthy(); + }); + it('should generate component in default directory for library', async () => { await componentGenerator(tree, { name: 'hello', diff --git a/packages/plugin/src/generators/executor/executor.spec.ts b/packages/plugin/src/generators/executor/executor.spec.ts index b08c1327c354ad..24fd9de440bf8c 100644 --- a/packages/plugin/src/generators/executor/executor.spec.ts +++ b/packages/plugin/src/generators/executor/executor.spec.ts @@ -47,6 +47,28 @@ describe('NxPlugin Executor Generator', () => { ).toBeTruthy(); }); + it('should handle path with file extension', async () => { + await executorGenerator(tree, { + name: 'my-executor', + path: 'my-plugin/src/executors/my-executor/executor.ts', + unitTestRunner: 'jest', + includeHasher: false, + }); + + expect( + tree.exists('my-plugin/src/executors/my-executor/schema.d.ts') + ).toBeTruthy(); + expect( + tree.exists('my-plugin/src/executors/my-executor/schema.json') + ).toBeTruthy(); + expect( + tree.exists('my-plugin/src/executors/my-executor/executor.ts') + ).toBeTruthy(); + expect( + tree.exists('my-plugin/src/executors/my-executor/executor.spec.ts') + ).toBeTruthy(); + }); + it('should generate files relative to the cwd', async () => { setCwd('my-plugin/src/executors/my-executor'); await executorGenerator(tree, { diff --git a/packages/plugin/src/generators/generator/generator.spec.ts b/packages/plugin/src/generators/generator/generator.spec.ts index 619249c8fa338a..6a2a460c9755e9 100644 --- a/packages/plugin/src/generators/generator/generator.spec.ts +++ b/packages/plugin/src/generators/generator/generator.spec.ts @@ -50,6 +50,27 @@ describe('NxPlugin Generator Generator', () => { ).toBeTruthy(); }); + it('should handle path with file extension', async () => { + await generatorGenerator(tree, { + name: 'my-generator', + path: 'my-plugin/src/generators/my-generator/generator.ts', + unitTestRunner: 'jest', + }); + + expect( + tree.exists('my-plugin/src/generators/my-generator/schema.d.ts') + ).toBeTruthy(); + expect( + tree.exists('my-plugin/src/generators/my-generator/schema.json') + ).toBeTruthy(); + expect( + tree.exists('my-plugin/src/generators/my-generator/generator.ts') + ).toBeTruthy(); + expect( + tree.exists('my-plugin/src/generators/my-generator/generator.spec.ts') + ).toBeTruthy(); + }); + it('should generate files relative to cwd', async () => { setCwd('my-plugin/src/nx-integrations/generators/my-generator'); await generatorGenerator(tree, { diff --git a/packages/plugin/src/generators/migration/migration.spec.ts b/packages/plugin/src/generators/migration/migration.spec.ts index 53ad5d02294ae0..23b5403492f43e 100644 --- a/packages/plugin/src/generators/migration/migration.spec.ts +++ b/packages/plugin/src/generators/migration/migration.spec.ts @@ -68,6 +68,34 @@ describe('NxPlugin migration generator', () => { ); }); + it('should handle path with file extension', async () => { + await migrationGenerator(tree, { + name: 'my-migration', + path: 'packages/my-plugin/migrations/1.0.0/my-migration.ts', + packageVersion: '1.0.0', + }); + + const migrationsJson = readJson(tree, 'packages/my-plugin/migrations.json'); + const packageJson = readJson(tree, 'packages/my-plugin/package.json'); + + expect( + tree.exists('packages/my-plugin/migrations/1.0.0/my-migration.ts') + ).toBeTruthy(); + + expect(migrationsJson.generators['my-migration'].version).toEqual('1.0.0'); + expect(migrationsJson.generators['my-migration'].description).toEqual( + 'Migration for v1.0.0' + ); + expect(migrationsJson.generators['my-migration'].implementation).toEqual( + './migrations/1.0.0/my-migration' + ); + expect(migrationsJson.packageJsonUpdates).toBeFalsy(); + + expect(packageJson['nx-migrations'].migrations).toEqual( + './migrations.json' + ); + }); + it('should generate files with default name', async () => { await migrationGenerator(tree, { description: 'my-migration description', diff --git a/packages/react-native/src/generators/component/component.spec.ts b/packages/react-native/src/generators/component/component.spec.ts index 1bbf2190f44c95..b231d37f43884e 100644 --- a/packages/react-native/src/generators/component/component.spec.ts +++ b/packages/react-native/src/generators/component/component.spec.ts @@ -33,6 +33,15 @@ describe('component', () => { expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy(); }); + it('should handle path with file extension', async () => { + await reactNativeComponentGenerator(appTree, { + path: `${projectName}/src/lib/hello/hello.tsx`, + }); + + expect(appTree.exists('my-lib/src/lib/hello/hello.tsx')).toBeTruthy(); + expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy(); + }); + it('should generate files for an app', async () => { await reactNativeComponentGenerator(appTree, { name: 'hello', diff --git a/packages/react/src/generators/component/component.spec.ts b/packages/react/src/generators/component/component.spec.ts index 76555e45f042d8..acb66237ed83cf 100644 --- a/packages/react/src/generators/component/component.spec.ts +++ b/packages/react/src/generators/component/component.spec.ts @@ -57,6 +57,26 @@ describe('component', () => { ); }); + it('should handle path with file extension', async () => { + await componentGenerator(appTree, { + name: 'hello', + style: 'css', + path: `${projectName}/src/lib/hello/hello.tsx`, + }); + + expect(appTree.exists('my-lib/src/lib/hello/hello.tsx')).toBeTruthy(); + expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy(); + expect( + appTree.exists('my-lib/src/lib/hello/hello.module.css') + ).toBeTruthy(); + expect(appTree.read('my-lib/src/lib/hello/hello.tsx').toString()).toMatch( + /import styles from '.\/hello.module.css'/ + ); + expect(appTree.read('my-lib/src/lib/hello/hello.tsx').toString()).toMatch( + /
/ + ); + }); + it('should generate files with global CSS', async () => { await componentGenerator(appTree, { name: 'hello', diff --git a/packages/react/src/generators/hook/hook.spec.ts b/packages/react/src/generators/hook/hook.spec.ts index f3fe55b5657fd2..eff082891b9455 100644 --- a/packages/react/src/generators/hook/hook.spec.ts +++ b/packages/react/src/generators/hook/hook.spec.ts @@ -34,6 +34,17 @@ describe('hook', () => { ).toBeTruthy(); }); + it('should handle path with file extension', async () => { + await hookGenerator(appTree, { + path: `${projectName}/src/lib/use-form/use-form.ts`, + }); + + expect(appTree.exists('my-lib/src/lib/use-form/use-form.ts')).toBeTruthy(); + expect( + appTree.exists('my-lib/src/lib/use-form/use-form.spec.tsx') + ).toBeTruthy(); + }); + it('should generate files for an app', async () => { await hookGenerator(appTree, { name: 'use-form', diff --git a/packages/vue/src/generators/component/component.spec.ts b/packages/vue/src/generators/component/component.spec.ts index e023e6f6e22508..93e0360b5e904d 100644 --- a/packages/vue/src/generators/component/component.spec.ts +++ b/packages/vue/src/generators/component/component.spec.ts @@ -55,6 +55,39 @@ describe('component', () => { `); }); + it('should handle path with file extension', async () => { + await componentGenerator(appTree, { + path: `${libName}/src/lib/hello/hello.vue`, + }); + + expect(appTree.read(`${libName}/src/lib/hello/hello.vue`, 'utf-8')) + .toMatchInlineSnapshot(` + " + + + + + " + `); + expect(appTree.read(`${libName}/src/lib/hello/hello.spec.ts`, 'utf-8')) + .toMatchInlineSnapshot(` + "import { mount } from '@vue/test-utils'; + import Hello from './hello.vue'; + + describe('Hello', () => { + it('renders properly', () => { + const wrapper = mount(Hello, {}); + expect(wrapper.text()).toContain('Welcome to Hello'); + }); + }); + " + `); + }); + it('should have correct component name based on directory', async () => { await componentGenerator(appTree, { path: `${libName}/src/foo/bar/hello-world/hello-world`,