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 unhandled error when a bad revision is provided to changedSince #7112

Closed
wants to merge 4 commits into from
Closed
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 @@ -25,6 +25,7 @@
- `[jest-jasmine2`] Fix crash when test return Promise rejected with null ([#7049](https://github.com/facebook/jest/pull/7049))
- `[jest-runtime]` Check `_isMockFunction` is true rather than truthy on potential global mocks ([#7017](https://github.com/facebook/jest/pull/7017))
- `[jest-jasmine]` Show proper error message from async `assert` errors ([#6821](https://github.com/facebook/jest/pull/6821))
- `[jest-cli]` Fix unhandled error when a bad revision is provided to `changedSince` ([#7112](https://github.com/facebook/jest/pull/7112))

### Chore & Maintenance

Expand Down
35 changes: 35 additions & 0 deletions e2e/__tests__/jest_changed_files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
findRepos,
getChangedFilesForRoots,
} from '../../packages/jest-changed-files/src';
import runJest from '../runJest';
const ConditionalTest = require('../../scripts/ConditionalTest');
const {cleanup, run, writeFiles} = require('../Utils');

Expand Down Expand Up @@ -243,6 +244,23 @@ test('monitors only root paths for git', async () => {
).toEqual(['file2.txt', 'file3.txt']);
});

test('handles a bad revision for "changedSince", for git', async () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`,
'file1.js': 'module.exports = {}',
'package.json': '{}',
});

run(`${GIT} init`, DIR);
run(`${GIT} add .`, DIR);
run(`${GIT} commit -m "first"`, DIR);

const stderr = runJest(DIR, ['--changedSince=blablabla']).stderr;

expect(stderr).toMatch(`\n\nfatal: bad revision '^blablabla'\n`);
});

test('gets changed files for hg', async () => {
if (process.env.CI) {
// Circle and Travis have very old version of hg (v2, and current
Expand Down Expand Up @@ -371,3 +389,20 @@ test('monitors only root paths for hg', async () => {
.sort(),
).toEqual(['file2.txt', 'file3.txt']);
});

test('handles a bad revision for "changedSince", for hg', async () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`,
'file1.js': 'module.exports = {}',
'package.json': '{}',
});

run(`${HG} init`, DIR);
run(`${HG} add .`, DIR);
run(`${HG} commit -m "first"`, DIR);

const stderr = runJest(DIR, ['--changedSince=blablabla']).stderr;

expect(stderr).toMatch(`\n\nabort: unknown revision 'blablabla'!\n`);
});
20 changes: 15 additions & 5 deletions packages/jest-changed-files/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ const findChangedFilesUsingCommand = async (
args: Array<string>,
cwd: Path,
): Promise<Array<Path>> => {
const result = await execa('git', args, {cwd});
try {
const result = await execa('git', args, {cwd});

return result.stdout
.split('\n')
.filter(s => s !== '')
.map(changedPath => path.resolve(cwd, changedPath));
return result.stdout
.split('\n')
.filter(s => s !== '')
.map(changedPath => path.resolve(cwd, changedPath));
} catch (e) {
const errorMsg = e.message.split('\n')[1];

console.error(`\n\n${errorMsg}\n`);

process.exit(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should exit with code 1, not 0


return [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to return after the process.exit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mainly to pass the flow tests, though eslint also complained.

}
};

const adapter: SCMAdapter = {
Expand Down
20 changes: 15 additions & 5 deletions packages/jest-changed-files/src/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,22 @@ const adapter: SCMAdapter = {
}
args.push(...includePaths);

const result = await execa('hg', args, {cwd, env});
try {
const result = await execa('hg', args, {cwd, env});

return result.stdout
.split('\n')
.filter(s => s !== '')
.map(changedPath => path.resolve(cwd, changedPath));
} catch (e) {
const errorMsg = e.message.split('\n')[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


return result.stdout
.split('\n')
.filter(s => s !== '')
.map(changedPath => path.resolve(cwd, changedPath));
console.error(`\n\n${errorMsg}\n`);

process.exit(0);

return [];
}
},

getRoot: async (cwd: Path): Promise<?Path> => {
Expand Down