From 31e10dbbbce41612825142853ba3f423ada15454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Wierci=C5=84ski?= Date: Tue, 19 Mar 2019 16:21:36 +0100 Subject: [PATCH] Change method of obtaining git root (#8052) --- CHANGELOG.md | 5 +++-- e2e/__tests__/jestChangedFiles.test.ts | 12 ++++++------ packages/jest-changed-files/src/git.ts | 10 ++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fbb3f9d9de4..f920e1c54f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,20 +6,21 @@ ### Fixes +- `[jest-changed-files]` Change method of obtaining git root ([#8052](https://github.com/facebook/jest/pull/8052)) - `[jest-each]` Fix test function type ([#8145](https://github.com/facebook/jest/pull/8145)) -- `[pretty-format]` Print `BigInt` as a readable number instead of `{}` ([#8138](https://github.com/facebook/jest/pull/8138)) - `[jest-fake-timers]` `getTimerCount` not taking immediates and ticks into account ([#8139](https://github.com/facebook/jest/pull/8139)) - `[jest-worker]` Move from `process.exit` to `exit` ([#7327](https://github.com/facebook/jest/pull/7327)) +- `[pretty-format]` Print `BigInt` as a readable number instead of `{}` ([#8138](https://github.com/facebook/jest/pull/8138)) ### Chore & Maintenance - `[*]` Remove flow from code base ([#8061](https://github.com/facebook/jest/pull/8061)) - `[*]` Use property initializer syntax in Jest codebase ([#8117](https://github.com/facebook/jest/pull/8117)) -- `[docs]` Improve description of optional arguments in ExpectAPI.md ([#8126](https://github.com/facebook/jest/pull/8126) - `[*]` Move @types/node to the root package.json [#8129](https://github.com/facebook/jest/pull/8129)) - `[*]` Add documentation and tests related to auto-mocking ([#8099](https://github.com/facebook/jest/pull/8099)) - `[*]` Add `jest-watch-typeahead` as a devDependency ([#6449](https://github.com/facebook/jest/pull/6449)) - `[*]` upgrade TS to 3.4.0-dev\* for inceremental builds ([#8149](https://github.com/facebook/jest/pull/8149)) +- `[docs]` Improve description of optional arguments in ExpectAPI.md ([#8126](https://github.com/facebook/jest/pull/8126) ### Performance diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index 5cd462fc3937..5f70987d0e08 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -54,8 +54,8 @@ test('gets hg SCM roots and dedups them', async () => { // NOTE: This test can break if you have a .hg repo initialized inside your // os tmp directory. expect(hgRepos).toHaveLength(2); - expect(hgRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo$/); - expect(hgRepos[1]).toMatch(/\/jest-changed-files-test-dir\/second-repo$/); + expect(hgRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo\/?$/); + expect(hgRepos[1]).toMatch(/\/jest-changed-files-test-dir\/second-repo\/?$/); }); test('gets git SCM roots and dedups them', async () => { @@ -88,8 +88,8 @@ test('gets git SCM roots and dedups them', async () => { // NOTE: This test can break if you have a .git repo initialized inside your // os tmp directory. expect(gitRepos).toHaveLength(2); - expect(gitRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo$/); - expect(gitRepos[1]).toMatch(/\/jest-changed-files-test-dir\/second-repo$/); + expect(gitRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo\/?$/); + expect(gitRepos[1]).toMatch(/\/jest-changed-files-test-dir\/second-repo\/?$/); }); test('gets mixed git and hg SCM roots and dedups them', async () => { @@ -121,8 +121,8 @@ test('gets mixed git and hg SCM roots and dedups them', async () => { // inside your os tmp directory. expect(gitRepos).toHaveLength(1); expect(hgRepos).toHaveLength(1); - expect(gitRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo$/); - expect(hgRepos[0]).toMatch(/\/jest-changed-files-test-dir\/second-repo$/); + expect(gitRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo\/?$/); + expect(hgRepos[0]).toMatch(/\/jest-changed-files-test-dir\/second-repo\/?$/); }); test('gets changed files for git', async () => { diff --git a/packages/jest-changed-files/src/git.ts b/packages/jest-changed-files/src/git.ts index ed0d4a9b90a1..29cf3cf0ede7 100644 --- a/packages/jest-changed-files/src/git.ts +++ b/packages/jest-changed-files/src/git.ts @@ -29,8 +29,10 @@ const adapter: SCMAdapter = { const changedSince: string | undefined = options && (options.withAncestor ? 'HEAD^' : options.changedSince); - const includePaths: Array = - (options && options.includePaths) || []; + const includePaths: Array = ( + (options && options.includePaths) || + [] + ).map(absoluteRoot => path.normalize(path.relative(cwd, absoluteRoot))); if (options && options.lastCommit) { return findChangedFilesUsingCommand( @@ -72,12 +74,12 @@ const adapter: SCMAdapter = { }, getRoot: async cwd => { - const options = ['rev-parse', '--show-toplevel']; + const options = ['rev-parse', '--show-cdup']; try { const result = await execa('git', options, {cwd}); - return result.stdout; + return path.resolve(cwd, result.stdout); } catch (e) { return null; }