-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"); | ||
|
||
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); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
|
||
async function pkgManifestsAndCommitMsg(cwd) { | ||
return Promise.all([ | ||
loadPkgManifests(cwd), | ||
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This snapshot label should be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = [ | ||
|
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.