From 334cf6ab9910ee432d6dfbb67957388bdd258eeb Mon Sep 17 00:00:00 2001 From: Austin Fahsl Date: Fri, 22 Jul 2022 10:39:16 -0400 Subject: [PATCH] chore(e2e): e2e fixture now reverts useNx and useWorkspaces by default --- e2e/tests/lerna-init/lerna-init.spec.ts | 8 ++++---- e2e/utils/fixture.ts | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/e2e/tests/lerna-init/lerna-init.spec.ts b/e2e/tests/lerna-init/lerna-init.spec.ts index ad6620e4277..4dbf4121682 100644 --- a/e2e/tests/lerna-init/lerna-init.spec.ts +++ b/e2e/tests/lerna-init/lerna-init.spec.ts @@ -15,7 +15,7 @@ describe("lerna-init", () => { afterEach(() => fixture.destroy()); it("should initialize a lerna workspace", async () => { - const output = await fixture.lernaInit(); + const output = await fixture.lernaInit("", { keepDefaultOptions: true }); expect(output.stderr).toMatchInlineSnapshot(` "lerna notice cli v999.9.9-e2e.0 @@ -55,7 +55,7 @@ describe("lerna-init", () => { describe("--independent", () => { it("should initialize a lerna workspace in independent versioning mode", async () => { - const output = await fixture.lernaInit("--independent"); + const output = await fixture.lernaInit("--independent", { keepDefaultOptions: true }); expect(output.stderr).toMatchInlineSnapshot(` "lerna notice cli v999.9.9-e2e.0 @@ -96,7 +96,7 @@ describe("lerna-init", () => { describe("--exact", () => { it("should initialize a lerna workspace with exact package version enforcement", async () => { - const output = await fixture.lernaInit("--exact"); + const output = await fixture.lernaInit("--exact", { keepDefaultOptions: true }); expect(output.stderr).toMatchInlineSnapshot(` "lerna notice cli v999.9.9-e2e.0 @@ -142,7 +142,7 @@ describe("lerna-init", () => { describe("--independent --exact", () => { it("should initialize a lerna workspace in independent versioning mode with exact package version enforcement", async () => { - const output = await fixture.lernaInit("--independent --exact"); + const output = await fixture.lernaInit("--independent --exact", { keepDefaultOptions: true }); expect(output.stderr).toMatchInlineSnapshot(` "lerna notice cli v999.9.9-e2e.0 diff --git a/e2e/utils/fixture.ts b/e2e/utils/fixture.ts index 5ad796c7eb2..c6856356399 100644 --- a/e2e/utils/fixture.ts +++ b/e2e/utils/fixture.ts @@ -124,14 +124,30 @@ export class Fixture { /** * Resolve the locally published version of lerna and run the `init` command, with an optionally - * provided arguments. + * provided arguments. Reverts useNx and useWorkspaces to false when options.keepDefaultOptions is not provided, since those options are off for most users. */ - async lernaInit(args?: string): Promise { + async lernaInit(args?: string, options?: { keepDefaultOptions: true }): Promise { return this.exec( `npx --registry=http://localhost:4872/ --yes lerna@${getPublishedVersion()} init ${args || ""}` + ).then((initResult) => + options?.keepDefaultOptions ? initResult : this.revertDefaultInitOptions().then(() => initResult) ); } + private async revertDefaultInitOptions(): Promise { + await this.updateJson("lerna.json", (json) => ({ + ...json, + useNx: false, + useWorkspaces: false, + packages: ["packages/*"], + })); + await this.updateJson("package.json", (json) => { + const newJson = { ...json }; + delete newJson.workspaces; + return newJson; + }); + } + /** * Execute the install command of the configured package manager for the current fixture. * This has been given a terse name to help with readability in the spec files.