Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use --canary=<value> as prerelease tag, not commit-ish #1020

Merged
merged 2 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/UpdatedPackagesCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ export default class UpdatedPackagesCollector {

if (GitUtilities.hasTags(execOpts)) {
if (canary) {
let currentSHA;

if (canary !== true) {
currentSHA = canary;
} else {
currentSHA = GitUtilities.getCurrentSHA(execOpts);
}
const currentSHA = GitUtilities.getCurrentSHA(execOpts);

since = this.getAssociatedCommits(currentSHA);
} else if (!since) {
Expand Down
74 changes: 74 additions & 0 deletions test/UpdatedPackagesCollector.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,84 @@
// mocked modules
import GitUtilities from "../src/GitUtilities";

// file under test
import UpdatedPackagesCollector from "../src/UpdatedPackagesCollector";

jest.mock("../src/GitUtilities");

const filteredPackages = [{
name: 'package-1',
location: 'location-1'
}, {
name: 'package-2',
location: 'location-2'
}];

const logger = {
silly: () => {},
info: () => {},
verbose: () => {}
};

const repository = {
rootPath: 'root-path'
};

describe("UpdatedPackagesCollector", () => {
it("should exist", () => {
expect(UpdatedPackagesCollector).toBeDefined();
});

it("needs better tests");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It now has them, thank you! (you can delete this empty test case, if you want)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I left that in because I agree with the sentiment 😉

Will remove.


describe(".collectUpdatedPackages()", () => {
beforeEach(() => {
GitUtilities.getCurrentSHA = jest.fn(() => "deadbeefcafe");
GitUtilities.hasTags = jest.fn(() => true);
GitUtilities.diffSinceIn = jest.fn(() => "");
GitUtilities.getLastTag = jest.fn(() => "lastTag");
});

afterEach(() => jest.resetAllMocks());

it("should use the current SHA for commit ranges when the canary flag has been passed", () => {
new UpdatedPackagesCollector({
options: {
canary: true
},
repository: repository,
logger: logger,
filteredPackages: filteredPackages
}).getUpdates();

expect(GitUtilities.diffSinceIn).toBeCalledWith('deadbeef^..deadbeef', 'location-1', undefined);
expect(GitUtilities.diffSinceIn).toBeCalledWith('deadbeef^..deadbeef', 'location-2', undefined);
});

it("should use the current SHA for commit ranges when the canary flag is a string", () => {
new UpdatedPackagesCollector({
options: {
canary: 'my-tag'
},
repository: repository,
logger: logger,
filteredPackages: filteredPackages
}).getUpdates();

expect(GitUtilities.diffSinceIn).toBeCalledWith('deadbeef^..deadbeef', 'location-1', undefined);
expect(GitUtilities.diffSinceIn).toBeCalledWith('deadbeef^..deadbeef', 'location-2', undefined);
});

it("should use the last tag in non-canary mode for commit ranges when a repo has tags", () => {
new UpdatedPackagesCollector({
options: {},
repository: repository,
logger: logger,
filteredPackages: filteredPackages
}).getUpdates();

expect(GitUtilities.diffSinceIn).toBeCalledWith('lastTag', 'location-1', undefined);
expect(GitUtilities.diffSinceIn).toBeCalledWith('lastTag', 'location-2', undefined);
});
});
});
40 changes: 40 additions & 0 deletions test/integration/__snapshots__/lerna-publish.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ Array [
]
`;

exports[`stderr: canary beta version 1`] = `
"lerna info version __TEST_VERSION__
lerna info canary enabled
lerna info current version 1.0.0
lerna info Checking for updated packages...
lerna info Comparing with initial commit.
lerna info auto-confirmed "
`;

exports[`stderr: canary beta version 2`] = `
"lerna info version __TEST_VERSION__
lerna info canary enabled
lerna info current version 1.0.0
lerna info Checking for updated packages...
lerna info Comparing with initial commit.
lerna info auto-confirmed "
`;

exports[`stderr: exit 0 when no updates 1`] = `
"lerna info version __TEST_VERSION__
lerna info current version 1.0.0
Expand All @@ -230,6 +248,28 @@ lerna info Comparing with initial commit.
lerna info auto-confirmed "
`;

exports[`stdout: canary beta version 1`] = `
"
Changes:
- package-1: 1.0.0 => 1.1.0-beta.hash
- package-2: 1.0.0 => 1.1.0-beta.hash
- package-3: 1.0.0 => 1.1.0-beta.hash
- package-4: 1.0.0 => 1.1.0-beta.hash
- package-5: 1.0.0 => 1.1.0-beta.hash (private)
"
`;

exports[`stdout: canary default version 1`] = `
"
Changes:
- package-1: 1.0.0 => 1.1.0-alpha.hash
- package-2: 1.0.0 => 1.1.0-alpha.hash
- package-3: 1.0.0 => 1.1.0-alpha.hash
- package-4: 1.0.0 => 1.1.0-alpha.hash
- package-5: 1.0.0 => 1.1.0-alpha.hash (private)
"
`;

exports[`stdout: exit 0 when no updates 1`] = `""`;

exports[`stdout: first feature added in fixed mode --conventional-commits --force-publish=* 1`] = `
Expand Down
33 changes: 33 additions & 0 deletions test/integration/lerna-publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import loadPkgManifests from "../helpers/loadPkgManifests";
const lastCommitMessage = (cwd) =>
execa.stdout("git", ["log", "-1", "--format=%B"], { cwd }).then(normalizeNewline);

const lastCommitId = (cwd) =>
execa.stdout("git", ["rev-parse", "HEAD"], { cwd }).then((line) => line.trim().substring(0, 8));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought execa automatically trimmed stdout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


async function pkgManifestsAndCommitMsg(cwd) {
return Promise.all([
loadPkgManifests(cwd),
Expand Down Expand Up @@ -66,6 +69,36 @@ describe("lerna publish", () => {
expect(commitMessage).toMatchSnapshot("commit: updates fixed versions");
});

test.concurrent("uses detault suffix with canary flag", async () => {
const cwd = await initFixture("PublishCommand/normal");
const args = [
"publish",
"--canary",
"--skip-npm",
"--yes",
];

const { stdout, stderr } = await execa(LERNA_BIN, args, { cwd });
const hash = await lastCommitId(cwd);
expect(stdout.replace(new RegExp(hash, 'g'), 'hash')).toMatchSnapshot("stdout: canary default version");
expect(stderr).toMatchSnapshot("stderr: canary beta version");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snapshot label should be stderr: canary default version, looks like copy+paste oversight.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

});

test.concurrent("uses meta suffix from canary flag", async () => {
const cwd = await initFixture("PublishCommand/normal");
const args = [
"publish",
"--canary=beta",
"--skip-npm",
"--yes",
];

const { stdout, stderr } = await execa(LERNA_BIN, args, { cwd });
const hash = await lastCommitId(cwd);
expect(stdout.replace(new RegExp(hash, 'g'), 'hash')).toMatchSnapshot("stdout: canary beta version");
expect(stderr).toMatchSnapshot("stderr: canary beta version");
});

test.concurrent("updates independent versions", async () => {
const cwd = await initFixture("PublishCommand/independent");
const args = [
Expand Down