Skip to content

Commit

Permalink
fix(manifest): package paths sharing same prefix being shadowed in co…
Browse files Browse the repository at this point in the history
…mmit-split (#848)

Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
joeldodge79 and bcoe committed Apr 7, 2021
1 parent a5e2cc2 commit 29ba3b5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/commit-split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class CommitSplit {
let pkgName;
if (this.packagePaths) {
// only track paths under this.packagePaths
pkgName = this.packagePaths.find(p => file.indexOf(p) === 0);
pkgName = this.packagePaths.find(p => file.indexOf(`${p}/`) === 0);
} else {
// track paths by top level folder
pkgName = splitPath[0];
Expand Down
62 changes: 39 additions & 23 deletions test/commit-split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,34 @@ describe('CommitSplit', () => {
usePackagePaths: boolean
): [ExpectedCommitSplit, PackagePaths, Commit[]] => {
const pkgsPath = 'packages';
const fooPath = pkgsPath + '/foo';
const barPath = pkgsPath + '/bar';
const fooPath = `${pkgsPath}/foo`;
const barPath = `${pkgsPath}/bar`;
const fooBarPath = `${pkgsPath}/foobar`;
const bazPath = 'python';
const somePath = 'some';
const fooCommit = buildMockCommit('fix(foo): fix foo', [
fooPath + '/foo.ts',
`${fooPath}/foo.ts`,
]);
const barCommit = buildMockCommit('fix(bar): fix bar', [
barPath + '/bar.ts',
`${barPath}/bar.ts`,
]);
const bazCommit = buildMockCommit('fix(baz): fix baz', [
bazPath + '/baz/baz.py',
`${bazPath}/baz/baz.py`,
]);
const foobarCommit = buildMockCommit('fix(foobar): fix foobar', [
fooPath + '/foo.ts',
barPath + '/bar.ts',
const fooBarCommit = buildMockCommit('fix(foobar): fix foobar', [
`${fooBarPath}/foobar.ts`,
]);
const foobarCommit = buildMockCommit('fix(foo+bar): fix foo+bar', [
`${fooPath}/foo.ts`,
`${barPath}/bar.ts`,
]);
const foobarbazCommit = buildMockCommit('fix(foobarbaz): fix foobarbaz', [
fooPath + '/foo.ts',
barPath + '/bar.ts',
bazPath + '/baz/baz.py',
`${fooPath}/foo.ts`,
`${barPath}/bar.ts`,
`${bazPath}/baz/baz.py`,
]);
const someCommit = buildMockCommit('fix(some): fix something', [
somePath + '/other/file.ts',
`${somePath}/other/file.ts`,
]);
const emptyCommit = buildMockCommit(
'chore: empty\n\nrelease-packages/foo-as: 1.2.3',
Expand All @@ -103,6 +107,7 @@ describe('CommitSplit', () => {
fooCommit,
barCommit,
bazCommit,
fooBarCommit,
foobarCommit,
foobarbazCommit,
// should only appear in usePackagePaths == false case
Expand All @@ -113,47 +118,58 @@ describe('CommitSplit', () => {
];

let packagePaths: string[] = [];
let perPathCommits: ExpectedCommitSplit = {};
let expectedPerPathCommits: ExpectedCommitSplit = {};

if (usePackagePaths) {
// trailing slash to test path normalization.
packagePaths = [fooPath, barPath, bazPath + '/'];
// leading/trailing slashs to test path normalization.
packagePaths = [`/${fooPath}`, barPath, `${bazPath}/`, fooBarPath];
// Expected output of commit-split with packagePaths
// someCommit and topLevelFileCommit not present
perPathCommits = {
expectedPerPathCommits = {
[fooPath]: [fooCommit, foobarCommit, foobarbazCommit],
[barPath]: [barCommit, foobarCommit, foobarbazCommit],
[bazPath]: [bazCommit, foobarbazCommit],
[fooBarPath]: [fooBarCommit],
};
} else {
// Expected output of commit-split with default behavior
// topLevelFileCommit not present
perPathCommits = {
[pkgsPath]: [fooCommit, barCommit, foobarCommit, foobarbazCommit],
expectedPerPathCommits = {
[pkgsPath]: [
fooCommit,
barCommit,
fooBarCommit,
foobarCommit,
foobarbazCommit,
],
[bazPath]: [bazCommit, foobarbazCommit],
[somePath]: [someCommit],
};
}
if (includeEmpty) {
// Expected that each splits' Commit[] will have the empty commit appended
for (const commitPath in perPathCommits) {
perPathCommits[commitPath].push(emptyCommit);
for (const commitPath in expectedPerPathCommits) {
expectedPerPathCommits[commitPath].push(emptyCommit);
}
}
return [perPathCommits, packagePaths, commits];
return [expectedPerPathCommits, packagePaths, commits];
};

// Test combinations of commit splitting with CommitSplitOptions.includeEmpty
// and CommitSplitOptions.packagePaths set to the following values
const emptyVsPaths = [
// CommitSplitOptions.includeEmpty == true
// CommitSplitOptions.packagePaths == ["packages/foo", "packages/bar", "python"]
// CommitSplitOptions.packagePaths == [
// "packages/foo", "packages/bar", "python", "packages/foobar"
// ]
[true, true],
// CommitSplitOptions.includeEmpty == true
// CommitSplitOptions.packagePaths == undefined
[true, false],
// CommitSplitOptions.includeEmpty == undefined
// CommitSplitOptions.packagePaths == ["packages/foo", "packages/bar", "python"]
// CommitSplitOptions.packagePaths == [
// "packages/foo", "packages/bar", "python", "packages/foobar"
// ]
[false, true],
// CommitSplitOptions.includeEmpty == undefined
// CommitSplitOptions.packagePaths == undefined
Expand Down

0 comments on commit 29ba3b5

Please sign in to comment.