From d4a5679b88ee78b388f1bd8462fbb4498462a8fd Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Mon, 7 Feb 2022 20:35:52 +0200 Subject: [PATCH 01/12] disable flaky mercurial test --- e2e/__tests__/jestChangedFiles.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index deafea9f555b..9d93655a08e2 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -473,6 +473,7 @@ testIfHg('monitors only root paths for hg', async () => { // skip this test and run it only locally. return; } + writeFiles(DIR, { 'file1.txt': 'file1', 'nested-dir/file2.txt': 'file2', @@ -492,6 +493,14 @@ testIfHg('monitors only root paths for hg', async () => { }); testIfHg('handles a bad revision for "changedSince", for hg', async () => { + if (process.env.CI) { + // Circle and Travis have very old version of hg (v2, and current + // version is v4.2) and its API changed since then and not compatible + // any more. Changing the SCM version on CIs is not trivial, so we'll just + // skip this test and run it only locally. + return; + } + writeFiles(DIR, { '.watchmanconfig': '', '__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`, From 7af601b941a0705b57d320cf59b51da7683e0061 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Mon, 7 Feb 2022 21:30:26 +0200 Subject: [PATCH 02/12] add jest.retryTimes --- e2e/__tests__/jestChangedFiles.test.ts | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index 9d93655a08e2..52f32931017f 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -47,6 +47,8 @@ function gitCreateBranch(branchName: string, dir: string) { run(`git branch ${branchName}`, dir); } +jest.retryTimes(3); + beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); @@ -358,14 +360,6 @@ test('handles a bad revision for "changedSince", for git', async () => { }); testIfHg('gets changed files for hg', async () => { - if (process.env.CI) { - // Circle and Travis have very old version of hg (v2, and current - // version is v4.2) and its API changed since then and not compatible - // any more. Changing the SCM version on CIs is not trivial, so we'll just - // 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 @@ -466,14 +460,6 @@ testIfHg('gets changed files for hg', async () => { }); testIfHg('monitors only root paths for hg', async () => { - if (process.env.CI) { - // Circle and Travis have very old version of hg (v2, and current - // version is v4.2) and its API changed since then and not compatible - // any more. Changing the SCM version on CIs is not trivial, so we'll just - // skip this test and run it only locally. - return; - } - writeFiles(DIR, { 'file1.txt': 'file1', 'nested-dir/file2.txt': 'file2', @@ -493,14 +479,6 @@ testIfHg('monitors only root paths for hg', async () => { }); testIfHg('handles a bad revision for "changedSince", for hg', async () => { - if (process.env.CI) { - // Circle and Travis have very old version of hg (v2, and current - // version is v4.2) and its API changed since then and not compatible - // any more. Changing the SCM version on CIs is not trivial, so we'll just - // skip this test and run it only locally. - return; - } - writeFiles(DIR, { '.watchmanconfig': '', '__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`, From 7f06a80a4e28ce5d8a3837d4d9e2a9d4f577b291 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Mon, 7 Feb 2022 21:47:44 +0200 Subject: [PATCH 03/12] skip one test --- e2e/__tests__/jestChangedFiles.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index 52f32931017f..eec452a552a7 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -360,6 +360,14 @@ test('handles a bad revision for "changedSince", for git', async () => { }); testIfHg('gets changed files for hg', async () => { + if (process.env.CI) { + // Circle and Travis have very old version of hg (v2, and current + // version is v4.2) and its API changed since then and not compatible + // any more. Changing the SCM version on CIs is not trivial, so we'll just + // 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 From 879a8a527c2bd6d046b918d0248ade6d8729e4fb Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Mon, 7 Feb 2022 22:16:55 +0200 Subject: [PATCH 04/12] exclude failing part --- e2e/__tests__/jestChangedFiles.test.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index eec452a552a7..a3ff96541321 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -360,14 +360,6 @@ test('handles a bad revision for "changedSince", for git', async () => { }); testIfHg('gets changed files for hg', async () => { - if (process.env.CI) { - // Circle and Travis have very old version of hg (v2, and current - // version is v4.2) and its API changed since then and not compatible - // any more. Changing the SCM version on CIs is not trivial, so we'll just - // 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 @@ -423,15 +415,15 @@ testIfHg('gets changed files for hg', async () => { 'file4.txt': 'file4', }); - ({changedFiles: files} = await getChangedFilesForRoots(roots, { - withAncestor: true, - })); - // Returns files from current uncommitted state + the last commit - expect( - Array.from(files) - .map(filePath => path.basename(filePath)) - .sort(), - ).toEqual(['file1.txt', 'file4.txt']); + // ({changedFiles: files} = await getChangedFilesForRoots(roots, { + // withAncestor: true, + // })); + // // Returns files from current uncommitted state + the last commit + // expect( + // Array.from(files) + // .map(filePath => path.basename(filePath)) + // .sort(), + // ).toEqual(['file1.txt', 'file4.txt']); run(`${HG} add file4.txt`, DIR); run(`${HG} commit -m "test3"`, DIR); From e714e6e4621a8f364cf024b580f1b177bccc8d36 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 8 Feb 2022 12:03:44 +0200 Subject: [PATCH 05/12] fix revset --- e2e/__tests__/jestChangedFiles.test.ts | 2 -- packages/jest-changed-files/src/hg.ts | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index 7cc662c4fd97..fbb0c532cfef 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -47,8 +47,6 @@ function gitCreateBranch(branchName: string, dir: string) { run(`git branch ${branchName}`, dir); } -jest.retryTimes(3); - beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); diff --git a/packages/jest-changed-files/src/hg.ts b/packages/jest-changed-files/src/hg.ts index 02f1ea6099cd..20ae92a32dd3 100644 --- a/packages/jest-changed-files/src/hg.ts +++ b/packages/jest-changed-files/src/hg.ts @@ -18,7 +18,9 @@ const adapter: SCMAdapter = { const args = ['status', '-amnu']; if (options.withAncestor) { - args.push('--rev', 'min((!public() & ::.)+.)^'); + // working suggestion + // args.push('--rev', 'min((not public() and ancestors(.))^ or .^)'); + args.push('--rev', 'min((!public() & ::.)+.)^1'); } else if (options.changedSince) { args.push('--rev', `ancestor(., ${options.changedSince})`); } else if (options.lastCommit === true) { From 72ba692f9f1412988e89725a19d36ccfc03aa72c Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 8 Feb 2022 12:17:25 +0200 Subject: [PATCH 06/12] uncomment test --- e2e/__tests__/jestChangedFiles.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index fbb0c532cfef..7867abf786a6 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -413,15 +413,15 @@ testIfHg('gets changed files for hg', async () => { 'file4.txt': 'file4', }); - // ({changedFiles: files} = await getChangedFilesForRoots(roots, { - // withAncestor: true, - // })); - // // Returns files from current uncommitted state + the last commit - // expect( - // Array.from(files) - // .map(filePath => path.basename(filePath)) - // .sort(), - // ).toEqual(['file1.txt', 'file4.txt']); + ({changedFiles: files} = await getChangedFilesForRoots(roots, { + withAncestor: true, + })); + // Returns files from current uncommitted state + the last commit + expect( + Array.from(files) + .map(filePath => path.basename(filePath)) + .sort(), + ).toEqual(['file1.txt', 'file4.txt']); run(`${HG} add file4.txt`, DIR); run(`${HG} commit -m "test3"`, DIR); From 2140f7dde73ec6952177fda53f220a74fe2baee6 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 8 Feb 2022 14:12:54 +0200 Subject: [PATCH 07/12] with first --- packages/jest-changed-files/src/hg.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/jest-changed-files/src/hg.ts b/packages/jest-changed-files/src/hg.ts index 20ae92a32dd3..ea7e615318cc 100644 --- a/packages/jest-changed-files/src/hg.ts +++ b/packages/jest-changed-files/src/hg.ts @@ -18,9 +18,7 @@ const adapter: SCMAdapter = { const args = ['status', '-amnu']; if (options.withAncestor) { - // working suggestion - // args.push('--rev', 'min((not public() and ancestors(.))^ or .^)'); - args.push('--rev', 'min((!public() & ::.)+.)^1'); + args.push('--rev', 'first(min(not public() & ::.)^+.^)'); } else if (options.changedSince) { args.push('--rev', `ancestor(., ${options.changedSince})`); } else if (options.lastCommit === true) { From 2b175e4a430b7802a81918cea0e100ec5ffca097 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 8 Feb 2022 14:41:09 +0200 Subject: [PATCH 08/12] increase timeout? --- testSetupFile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testSetupFile.js b/testSetupFile.js index ef9ed18680f6..d128c1f3e43d 100644 --- a/testSetupFile.js +++ b/testSetupFile.js @@ -7,4 +7,4 @@ // Some of the `jest-runtime` tests are very slow and cause // timeouts on travis -jest.setTimeout(70000); +jest.setTimeout(90000); From b4ccbe20c3b44031857022f64ff9a3ed3b22313f Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 8 Feb 2022 15:22:59 +0200 Subject: [PATCH 09/12] revert timeout --- testSetupFile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testSetupFile.js b/testSetupFile.js index d128c1f3e43d..ef9ed18680f6 100644 --- a/testSetupFile.js +++ b/testSetupFile.js @@ -7,4 +7,4 @@ // Some of the `jest-runtime` tests are very slow and cause // timeouts on travis -jest.setTimeout(90000); +jest.setTimeout(70000); From 79ad64467fcff7b1d73c194b74a7dc2faea3b6ad Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 8 Feb 2022 17:15:39 +0200 Subject: [PATCH 10/12] pattern style --- packages/jest-changed-files/src/hg.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-changed-files/src/hg.ts b/packages/jest-changed-files/src/hg.ts index ea7e615318cc..c9fb11b5558a 100644 --- a/packages/jest-changed-files/src/hg.ts +++ b/packages/jest-changed-files/src/hg.ts @@ -18,7 +18,7 @@ const adapter: SCMAdapter = { const args = ['status', '-amnu']; if (options.withAncestor) { - args.push('--rev', 'first(min(not public() & ::.)^+.^)'); + args.push('--rev', 'first(min(!public() & ::.)^+.^)'); } else if (options.changedSince) { args.push('--rev', `ancestor(., ${options.changedSince})`); } else if (options.lastCommit === true) { From c1fbe7b8ce702fabdd710591769677826a806925 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 8 Feb 2022 17:15:52 +0200 Subject: [PATCH 11/12] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce76556d651a..b5c747b1054c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features ### Fixes +- `[jest-changed-files]` Improve `changedFilesWithAncestor` pattern for Mercurial SCM ([#12322](https://github.com/facebook/jest/pull/12322)) ### Chore & Maintenance From 3f43c84cfdcacccaf60afb94b2eb2978678cc4cf Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Tue, 8 Feb 2022 17:28:52 +0200 Subject: [PATCH 12/12] prettier --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5c747b1054c..de3571c760de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features ### Fixes + - `[jest-changed-files]` Improve `changedFilesWithAncestor` pattern for Mercurial SCM ([#12322](https://github.com/facebook/jest/pull/12322)) ### Chore & Maintenance