Skip to content

Commit

Permalink
fix(misc): update more generators and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Sep 26, 2024
1 parent b32fdc8 commit f5767b3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
2 changes: 0 additions & 2 deletions packages/next/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('component', () => {
await applicationGenerator(tree, {
name: appName,
style: 'css',
projectNameAndRootFormat: 'as-provided',
});
await libraryGenerator(tree, {
name: libName,
Expand All @@ -24,7 +23,6 @@ describe('component', () => {
skipFormat: true,
skipTsConfig: false,
unitTestRunner: 'jest',
projectNameAndRootFormat: 'as-provided',
});
});

Expand Down
24 changes: 16 additions & 8 deletions packages/next/src/generators/page/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions packages/react/src/generators/hook/hook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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,
});

Expand All @@ -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(
Expand All @@ -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,
});

Expand All @@ -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,
});

Expand All @@ -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(
Expand All @@ -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,
});

Expand All @@ -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,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f5767b3

Please sign in to comment.