Skip to content

Commit

Permalink
chore(e2e): add version test for package-lock in with workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Aug 12, 2022
1 parent a87c1da commit 76cdfe0
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions e2e/tests/lerna-version/npm-workspaces.spec.ts
@@ -0,0 +1,71 @@
import { Fixture } from "../../utils/fixture";
import { normalizeCommitSHAs, normalizeEnvironment } from "../../utils/snapshot-serializer-utils";

expect.addSnapshotSerializer({
serialize(str: string) {
return normalizeCommitSHAs(normalizeEnvironment(str));
},
test(val: string) {
return val != null && typeof val === "string";
},
});

describe("lerna-version-with-workspaces", () => {
let fixture: Fixture;

beforeEach(async () => {
fixture = await Fixture.create({
name: "lerna-version-with-workspaces",
packageManager: "npm",
initializeGit: true,
runLernaInit: false,
installDependencies: false,
});
await fixture.lernaInit("", { keepDefaultOptions: true });
await fixture.install();

await fixture.lerna("create package-a -y");
await fixture.lerna("create package-b -y --dependencies package-a");
await fixture.createInitialGitCommit();
await fixture.exec("git push origin test-main");
});
afterEach(() => fixture.destroy());

it("should support setting a specific version imperatively and update root lockfile", async () => {
const output = await fixture.lerna("version 3.3.3 -y");
expect(output.combinedOutput).toMatchInlineSnapshot(`
lerna notice cli v999.9.9-e2e.0
lerna info current version 0.0.0
lerna info Assuming all packages changed
Changes:
- package-a: 0.0.0 => 3.3.3
- package-b: 0.0.0 => 3.3.3
lerna info auto-confirmed
lerna info execute Skipping releases
lerna info git Pushing tags...
lerna success version finished
`);

const checkTagIsPresentLocally = await fixture.exec("git describe --abbrev=0");
expect(checkTagIsPresentLocally.combinedOutput).toMatchInlineSnapshot(`
v3.3.3
`);

const checkTagIsPresentOnRemote = await fixture.exec("git ls-remote origin refs/tags/v3.3.3");
expect(checkTagIsPresentOnRemote.combinedOutput).toMatchInlineSnapshot(`
{FULL_COMMIT_SHA} refs/tags/v3.3.3
`);

const packageLockJson = await fixture.readWorkspaceFile("package-lock.json");
const packages = JSON.parse(packageLockJson).packages;

expect(packages["packages/package-a"].version).toEqual("3.3.3");
expect(packages["packages/package-b"].version).toEqual("3.3.3");
expect(packages["packages/package-b"].dependencies["package-a"]).toEqual("^3.3.3");
});
});

0 comments on commit 76cdfe0

Please sign in to comment.