Skip to content

Commit

Permalink
chore(e2e): e2e fixture now reverts useNx and useWorkspaces by default
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Jul 22, 2022
1 parent c00768e commit 334cf6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions e2e/tests/lerna-init/lerna-init.spec.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions e2e/utils/fixture.ts
Expand Up @@ -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<RunCommandResult> {
async lernaInit(args?: string, options?: { keepDefaultOptions: true }): Promise<RunCommandResult> {
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<void> {
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.
Expand Down

0 comments on commit 334cf6a

Please sign in to comment.