Skip to content

Commit

Permalink
fix(core): Fix broken e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham authored and jaysoo committed Sep 30, 2024
1 parent c8dfed8 commit 0366daf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 37 deletions.
23 changes: 9 additions & 14 deletions docs/generated/packages/react-native/generators/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@
"type": "object",
"examples": [
{
"command": "nx g @nx/react-native:component my-component --directory=mylib/src/lib/my-component",
"command": "nx g @nx/react-native:component mylib/src/lib/my-component/my-component ",
"description": "Generate a component in the `mylib` library"
},
{
"command": "nx g @nx/react-native:component my-component --directory=mylib/src/lib/my-component --classComponent",
"command": "nx g @nx/react-native:component mylib/src/lib/my-component/my-component --classComponent",
"description": "Generate a class component in the `mylib` library"
}
],
"properties": {
"path": {
"type": "string",
"description": "The path at which to create the component file.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What path would you like to use for the component?"
},
"name": {
"type": "string",
"description": "The name of the component.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use for the component?"
},
"js": {
Expand All @@ -35,16 +40,6 @@
"description": "When true, does not create `spec.ts` test files for the new component.",
"default": false
},
"directory": {
"type": "string",
"description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
"x-priority": "important"
},
"nameAndDirectoryFormat": {
"description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
"type": "string",
"enum": ["as-provided", "derived"]
},
"export": {
"type": "boolean",
"description": "When true, the component is exported from the project `index.ts` (if it exists).",
Expand All @@ -59,7 +54,7 @@
"default": false
}
},
"required": ["name"],
"required": ["path"],
"presets": []
},
"description": "Create a React Native component.",
Expand Down
2 changes: 1 addition & 1 deletion e2e/next/src/next-storybook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Next.js Storybook', () => {
`generate @nx/next:app ${appName} --e2eTestRunner=none --project-name-and-root-format=as-provided --no-interactive`
);
runCLI(
`generate @nx/next:component foo --directory=${appName}/components/foo --nameAndDirectoryFormat=as-provided --no-interactive`
`generate @nx/next:component ${appName}/components/foo/foo --no-interactive`
);
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/react-native/src/react-native-legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('@nx/react-native (legacy)', () => {
const componentName = uniq('Component');

runCLI(
`generate @nx/react-native:component ${componentName} --directory=libs/${libName}/src/lib/${componentName} --export`
`generate @nx/react-native:component libs/${libName}/src/lib/${componentName}/${componentName} --export`
);
expect(() => {
runCLI(`build ${libName}`);
Expand Down
2 changes: 1 addition & 1 deletion e2e/react/src/cypress-component-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default App;`
`generate @nx/react:lib ${buildableLibName} --directory=libs/${buildableLibName} --buildable --no-interactive --unitTestRunner=jest`
);
runCLI(
`generate @nx/react:component input --directory=libs/${buildableLibName}/src/lib/input --export --no-interactive`
`generate @nx/react:component libs/${buildableLibName}/src/lib/input/input --export --no-interactive`
);

checkFilesExist(`libs/${buildableLibName}/src/lib/input/input.tsx`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Schema } from '../schema';
import { determineArtifactNameAndDirectoryOptions } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';

export interface NormalizedSchema extends Schema {
directory: string;
projectSourceRoot: string;
fileName: string;
className: string;
Expand All @@ -14,8 +15,6 @@ export async function normalizeOptions(
host: Tree,
options: Schema
): Promise<NormalizedSchema> {
assertValidOptions(options);

const {
artifactName: name,
directory,
Expand All @@ -28,6 +27,8 @@ export async function normalizeOptions(
fileExtension: 'tsx',
});

assertValidOptions({ name, directory });

const project = getProjects(host).get(projectName);

const { className } = names(name);
Expand All @@ -44,6 +45,7 @@ export async function normalizeOptions(

return {
...options,
name,
directory,
className,
fileName,
Expand All @@ -53,7 +55,7 @@ export async function normalizeOptions(
};
}

function assertValidOptions(options: Schema) {
function assertValidOptions(options: { name: string; directory: string }) {
const slashes = ['/', '\\'];
slashes.forEach((s) => {
if (options.name.indexOf(s) !== -1) {
Expand All @@ -63,7 +65,7 @@ function assertValidOptions(options: Schema) {
suggestion = `${options.directory}${s}${suggestion}`;
}
throw new Error(
`Found "${s}" in the component name. Did you mean to use the --directory option (e.g. \`nx g c ${name} --directory ${suggestion}\`)?`
`Found "${s}" in the component name. Did you mean to use the --path option (e.g. \`nx g c ${suggestion}/${name} \`)?`
);
}
});
Expand Down
1 change: 0 additions & 1 deletion packages/react-native/src/generators/component/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export interface Schema {
path: string;
name?: string;
skipTests?: boolean;
directory?: string;
export?: boolean;
classComponent?: boolean;
js?: boolean;
Expand Down
25 changes: 10 additions & 15 deletions packages/react-native/src/generators/component/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@
"type": "object",
"examples": [
{
"command": "nx g @nx/react-native:component my-component --directory=mylib/src/lib/my-component",
"command": "nx g @nx/react-native:component mylib/src/lib/my-component/my-component ",
"description": "Generate a component in the `mylib` library"
},
{
"command": "nx g @nx/react-native:component my-component --directory=mylib/src/lib/my-component --classComponent",
"command": "nx g @nx/react-native:component mylib/src/lib/my-component/my-component --classComponent",
"description": "Generate a class component in the `mylib` library"
}
],
"properties": {
"name": {
"path": {
"type": "string",
"description": "The name of the component.",
"description": "The path at which to create the component file.",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What path would you like to use for the component?"
},
"name": {
"type": "string",
"description": "The name of the component.",
"x-prompt": "What name would you like to use for the component?"
},
"js": {
Expand All @@ -35,16 +40,6 @@
"description": "When true, does not create `spec.ts` test files for the new component.",
"default": false
},
"directory": {
"type": "string",
"description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
"x-priority": "important"
},
"nameAndDirectoryFormat": {
"description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
"type": "string",
"enum": ["as-provided", "derived"]
},
"export": {
"type": "boolean",
"description": "When true, the component is exported from the project `index.ts` (if it exists).",
Expand All @@ -59,5 +54,5 @@
"default": false
}
},
"required": ["name"]
"required": ["path"]
}

0 comments on commit 0366daf

Please sign in to comment.