From 933e33acd476d4c2a063ee5fcb544626b8546237 Mon Sep 17 00:00:00 2001 From: David Laban Date: Sun, 14 Jan 2018 15:04:32 +0000 Subject: [PATCH] fixup! WIP: --changedFilesSinceCommit=origin/master + hg support Turns out hacking things out drunkenly at midnight on a Friday isn't the greatest way to get high-quality code. --- integration-tests/__tests__/jest_changed_files.test.js | 9 ++++++--- packages/jest-changed-files/src/git.js | 1 + packages/jest-changed-files/src/hg.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/integration-tests/__tests__/jest_changed_files.test.js b/integration-tests/__tests__/jest_changed_files.test.js index 0122fb8bfd8b..12f77c9c5268 100644 --- a/integration-tests/__tests__/jest_changed_files.test.js +++ b/integration-tests/__tests__/jest_changed_files.test.js @@ -210,7 +210,8 @@ test('gets changed files for git', async () => { writeFiles(DIR, { 'file5.txt': 'file5', }); - run(`${GIT} commit -am "test5"`, DIR); + run(`${GIT} add file5.txt`, DIR); + run(`${GIT} commit -m "test5"`, DIR); ({changedFiles: files} = await getChangedFilesForRoots(roots, { sinceCommit: 'master', @@ -292,10 +293,11 @@ test('gets changed files for hg', async () => { .sort(), ).toEqual(['file1.txt', 'file4.txt']); + run(`${HG} add file4.txt`, DIR); run(`${HG} commit -m "test3"`, DIR); ({changedFiles: files} = await getChangedFilesForRoots(roots, { - sinceCommit: '-2', + sinceCommit: '-3', })); // Returns files from the last 2 commits expect( @@ -311,7 +313,8 @@ test('gets changed files for hg', async () => { writeFiles(DIR, { 'file5.txt': 'file5', }); - run(`${HG} commit -am "test5"`, DIR); + run(`${HG} add file5.txt`, DIR); + run(`${HG} commit -m "test4"`, DIR); ({changedFiles: files} = await getChangedFilesForRoots(roots, { sinceCommit: 'master', diff --git a/packages/jest-changed-files/src/git.js b/packages/jest-changed-files/src/git.js index 040185f688ff..e88c3145e3ca 100644 --- a/packages/jest-changed-files/src/git.js +++ b/packages/jest-changed-files/src/git.js @@ -33,6 +33,7 @@ const findChangedFilesUsingCommand = async ( resolve( stdout .split('\n') + .filter(s => s !== '') .map(changedPath => path.resolve(cwd, changedPath)), ); } diff --git a/packages/jest-changed-files/src/hg.js b/packages/jest-changed-files/src/hg.js index e26b329b1a60..994bda41dd33 100644 --- a/packages/jest-changed-files/src/hg.js +++ b/packages/jest-changed-files/src/hg.js @@ -27,7 +27,7 @@ const adapter: SCMAdapter = { if (options && options.withAncestor) { args.push('--rev', 'ancestor(.^)'); } else if (options && options.sinceCommit) { - args.push(`--rev', 'ancestor(., ${options.sinceCommit})`); + args.push('--rev', `ancestor(., ${options.sinceCommit})`); } else if (options && options.lastCommit === true) { args = ['tip', '--template', '{files%"{file}\n"}']; }