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

fix(jest-changed-files): only return files from getChangedFilesFromRoots #7961

Merged
merged 2 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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