From b25ceb6e96172d45bc65a63650ebf57fb910c464 Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Mon, 13 May 2024 03:56:37 -0400 Subject: [PATCH] (fix): `fern add` with a new `--group` works (#3602) --- .../generators-yml/updateGeneratorGroup.ts | 7 +- .../tests/add/__snapshots__/add.test.ts.snap | 117 ++++++++++++++++++ .../cli/ete-tests/src/tests/add/add.test.ts | 14 +++ 3 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 packages/cli/ete-tests/src/tests/add/__snapshots__/add.test.ts.snap diff --git a/packages/cli/configuration/src/generators-yml/updateGeneratorGroup.ts b/packages/cli/configuration/src/generators-yml/updateGeneratorGroup.ts index 41420bdad9a..b98bb3b6124 100644 --- a/packages/cli/configuration/src/generators-yml/updateGeneratorGroup.ts +++ b/packages/cli/configuration/src/generators-yml/updateGeneratorGroup.ts @@ -20,10 +20,13 @@ export async function updateGeneratorGroup({ return context.failAndThrow("No group specified."); } const groups = (generatorsConfiguration.groups ??= {}); - for (const groupName of Object.keys(groups)) { + + const group = groups[groupName]; + if (group == null) { const draftGroup = (groups[groupName] ??= { generators: [] }); await update(draftGroup, groupName); + } else { + await update(group, groupName); } - return generatorsConfiguration; } diff --git a/packages/cli/ete-tests/src/tests/add/__snapshots__/add.test.ts.snap b/packages/cli/ete-tests/src/tests/add/__snapshots__/add.test.ts.snap new file mode 100644 index 00000000000..f47863d9fa3 --- /dev/null +++ b/packages/cli/ete-tests/src/tests/add/__snapshots__/add.test.ts.snap @@ -0,0 +1,117 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`fern add fern add --group sdk 1`] = ` +[ + { + "contents": [ + { + "contents": [ + { + "contents": "name: api +error-discrimination: + strategy: status-code +", + "name": "api.yml", + "type": "file", + }, + { + "contents": "# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json + +service: + auth: false + base-path: /movies + endpoints: + createMovie: + docs: Add a movie to the database + method: POST + path: /create-movie + request: CreateMovieRequest + response: MovieId + + getMovie: + docs: Retrieve a movie from the database based on the ID + method: GET + path: /{id} + path-parameters: + id: MovieId + response: Movie + errors: + - MovieDoesNotExistError + examples: + # Success response + - path-parameters: + id: tt0111161 + response: + body: + id: tt0111161 + title: The Shawshank Redemption + rating: 9.3 + # Error response + - path-parameters: + id: tt1234 + response: + error: MovieDoesNotExistError + body: tt1234 + +types: + MovieId: + type: string + docs: The unique identifier for a Movie in the database + + Movie: + properties: + id: MovieId + title: string + rating: + type: double + docs: The rating scale out of ten stars + + CreateMovieRequest: + properties: + title: string + rating: double + +errors: + MovieDoesNotExistError: + status-code: 404 + type: MovieId +", + "name": "imdb.yml", + "type": "file", + }, + ], + "name": "definition", + "type": "directory", + }, + { + "contents": "{ + "organization": "fern", + "version": "0.0.0" +}", + "name": "fern.config.json", + "type": "file", + }, + { + "contents": "default-group: local +groups: + local: + generators: + - name: fernapi/fern-typescript-node-sdk + version: 0.9.5 + output: + location: local-file-system + path: ../sdks/typescript + typescript: + generators: + - name: fernapi/fern-typescript + version: 0.7.2 +", + "name": "generators.yml", + "type": "file", + }, + ], + "name": "fern", + "type": "directory", + }, +] +`; diff --git a/packages/cli/ete-tests/src/tests/add/add.test.ts b/packages/cli/ete-tests/src/tests/add/add.test.ts index 6717e124d5d..cb0df4175f4 100644 --- a/packages/cli/ete-tests/src/tests/add/add.test.ts +++ b/packages/cli/ete-tests/src/tests/add/add.test.ts @@ -17,4 +17,18 @@ describe("fern add", () => { expect(await getDirectoryContents(pathOfDirectory)).not.toBeNull(); }, 60_000); + + it("fern add --group sdk", async () => { + const pathOfDirectory = await init(); + + const add = async (generator: string, groupName: string) => { + await runFernCli(["add", generator, "--group", groupName], { + cwd: pathOfDirectory + }); + }; + + await add("fern-typescript", "typescript"); + + expect(await getDirectoryContents(pathOfDirectory)).toMatchSnapshot(); + }, 60_000); });