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 --watch fails with ambiguous argument #11160

Merged
merged 1 commit into from Mar 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

### Features

- `[jest-changed-files]` Use '--' to separate paths from revisions ([#11160](https://github.com/facebook/jest/pull/11160))
- `[jest-circus]` [**BREAKING**] Fail tests when multiple `done()` calls are made ([#10624](https://github.com/facebook/jest/pull/10624))
- `[jest-circus, jest-jasmine2]` [**BREAKING**] Fail the test instead of just warning when describe returns a value ([#10947](https://github.com/facebook/jest/pull/10947))
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874))
Expand Down
10 changes: 9 additions & 1 deletion e2e/__tests__/jestChangedFiles.test.ts
Expand Up @@ -44,6 +44,10 @@ function gitInit(dir: string) {
run(initCommand, dir);
}

function gitCreateBranch(branchName: string, dir: string) {
run(`git branch ${branchName}`, dir);
}

beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));

Expand Down Expand Up @@ -171,9 +175,11 @@ test('gets changed files for git', async () => {
gitInit(DIR);

const roots = [
'',
// same first root name with existing branch name makes pitfall that
// causes "ambiguous argument" git error.
'nested-dir',
'nested-dir/second-nested-dir',
'',
].map(filename => path.resolve(DIR, filename));

let {changedFiles: files} = await getChangedFilesForRoots(roots, {});
Expand All @@ -190,6 +196,8 @@ test('gets changed files for git', async () => {
// returns files and not parts of commit messages.
run(`${GIT} commit --no-gpg-sign -m "test" -m "extra-line"`, DIR);

gitCreateBranch('nested-dir', DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {}));
expect(Array.from(files)).toEqual([]);

Expand Down
28 changes: 18 additions & 10 deletions packages/jest-changed-files/src/git.ts
Expand Up @@ -44,7 +44,7 @@ const adapter: SCMAdapter = {

if (options && options.lastCommit) {
return findChangedFilesUsingCommand(
['show', '--name-only', '--pretty=format:', 'HEAD'].concat(
['show', '--name-only', '--pretty=format:', 'HEAD', '--'].concat(
includePaths,
),
cwd,
Expand All @@ -53,33 +53,41 @@ const adapter: SCMAdapter = {
if (changedSince) {
const [committed, staged, unstaged] = await Promise.all([
findChangedFilesUsingCommand(
['diff', '--name-only', `${changedSince}...HEAD`].concat(
['diff', '--name-only', `${changedSince}...HEAD`, '--'].concat(
includePaths,
),
cwd,
),
findChangedFilesUsingCommand(
['diff', '--cached', '--name-only'].concat(includePaths),
['diff', '--cached', '--name-only', '--'].concat(includePaths),
cwd,
),
findChangedFilesUsingCommand(
['ls-files', '--other', '--modified', '--exclude-standard'].concat(
includePaths,
),
[
'ls-files',
'--other',
'--modified',
'--exclude-standard',
'--',
Copy link
Contributor Author

@yokomotod yokomotod Mar 6, 2021

Choose a reason for hiding this comment

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

note: git ls-files won't fail so not require --, just unifying same style with git diff

].concat(includePaths),
cwd,
),
]);
return [...committed, ...staged, ...unstaged];
}
const [staged, unstaged] = await Promise.all([
findChangedFilesUsingCommand(
['diff', '--cached', '--name-only'].concat(includePaths),
['diff', '--cached', '--name-only', '--'].concat(includePaths),
cwd,
),
findChangedFilesUsingCommand(
['ls-files', '--other', '--modified', '--exclude-standard'].concat(
includePaths,
),
[
'ls-files',
'--other',
'--modified',
'--exclude-standard',
'--',
].concat(includePaths),
cwd,
),
]);
Expand Down