Skip to content

Commit

Permalink
fix(jest-changed-files): only return files from `getChangedFilesFromR…
Browse files Browse the repository at this point in the history
…oots` (#7961)
  • Loading branch information
jumoel authored and SimenB committed Feb 22, 2019
1 parent 65b9535 commit 88d6b72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,7 @@
- `[jest-circus]` Fix bug with test.only ([#7888](https://github.com/facebook/jest/pull/7888))
- `[jest-transform]` Normalize config and remove unecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801))
- `[jest-worker]` Fix `jest-worker` when using pre-allocated jobs ([#7934](https://github.com/facebook/jest/pull/7934))
- `[jest-changed-files]` Fix `getChangedFilesFromRoots` to not return parts of the commit messages as if they were files, when the commit messages contained multiple paragraphs ([#7961](https://github.com/facebook/jest/pull/7961))

### Chore & Maintenance

Expand Down
15 changes: 12 additions & 3 deletions e2e/__tests__/jestChangedFiles.test.js
Expand Up @@ -148,7 +148,11 @@ test('gets changed files for git', async () => {
).toEqual(['file1.txt', 'file2.txt', 'file3.txt']);

run(`${GIT} add .`, DIR);
run(`${GIT} commit --no-gpg-sign -m "test"`, DIR);

// Uses multiple `-m` to make the commit message have multiple
// paragraphs. This is done to ensure that `changedFiles` only
// returns files and not parts of commit messages.
run(`${GIT} commit --no-gpg-sign -m "test" -m "extra-line"`, DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {}));
expect(Array.from(files)).toEqual([]);
Expand Down Expand Up @@ -266,8 +270,13 @@ test('gets changed files for hg', async () => {
// skip this test and run it only locally.
return;
}

// file1.txt is used to make a multi-line commit message
// with `hg commit -l file1.txt`.
// This is done to ensure that `changedFiles` only returns files
// and not parts of commit messages.
writeFiles(DIR, {
'file1.txt': 'file1',
'file1.txt': 'file1\n\nextra-line',
'nested-dir/file2.txt': 'file2',
'nested-dir/second-nested-dir/file3.txt': 'file3',
});
Expand All @@ -286,7 +295,7 @@ test('gets changed files for hg', async () => {
).toEqual(['file1.txt', 'file2.txt', 'file3.txt']);

run(`${HG} add .`, DIR);
run(`${HG} commit -m "test"`, DIR);
run(`${HG} commit -l file1.txt`, DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {}));
expect(Array.from(files)).toEqual([]);
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-changed-files/src/git.ts
Expand Up @@ -35,15 +35,17 @@ const adapter: SCMAdapter = {

if (options && options.lastCommit) {
return findChangedFilesUsingCommand(
['show', '--name-only', '--pretty=%b', 'HEAD'].concat(includePaths),
['show', '--name-only', '--pretty=format:', 'HEAD'].concat(
includePaths,
),
cwd,
);
} else if (changedSince) {
const committed = await findChangedFilesUsingCommand(
[
'log',
'--name-only',
'--pretty=%b',
'--pretty=format:',
'HEAD',
`^${changedSince}`,
].concat(includePaths),
Expand Down

0 comments on commit 88d6b72

Please sign in to comment.