Skip to content

Commit

Permalink
fix: jest --watch fails with ambiguous argument
Browse files Browse the repository at this point in the history
  • Loading branch information
yokomotod committed Mar 6, 2021
1 parent fedafc3 commit 9587beb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
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',
'--',
].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

0 comments on commit 9587beb

Please sign in to comment.