From c9c766efa6bd509206721799d1bbf0f9c0ff8951 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sun, 19 Apr 2020 20:01:52 +0200 Subject: [PATCH 1/8] Skip hg tests when no hg installed The very same check is already done in jestChangedFiles.test.ts --- e2e/__tests__/onlyChanged.test.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/e2e/__tests__/onlyChanged.test.ts b/e2e/__tests__/onlyChanged.test.ts index 3a7ff38da596..d2042b5d5b72 100644 --- a/e2e/__tests__/onlyChanged.test.ts +++ b/e2e/__tests__/onlyChanged.test.ts @@ -7,6 +7,7 @@ import {tmpdir} from 'os'; import * as path from 'path'; +import which = require('which'); import runJest from '../runJest'; import {cleanup, run, writeFiles} from '../Utils'; @@ -17,6 +18,14 @@ const HG = 'hg --config ui.username=jest_test'; beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); +// Certain environments (like CITGM and GH Actions) do not come with mercurial installed +const hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; +const testIfHg = hgIsInstalled ? test : test.skip; + +if (!hgIsInstalled) { + console.warn('Mercurial (hg) is not installed - skipping some tests'); +} + test('run for "onlyChanged" and "changedSince"', () => { writeFiles(DIR, { '.watchmanconfig': '', @@ -252,7 +261,7 @@ test('onlyChanged in config is overwritten by --all or testPathPattern', () => { expect(stderr).toMatch(/PASS __tests__(\/|\\)file3.test.js/); }); -test('gets changed files for hg', 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 From 3254ea295bafe8b81f04304d903e0c6cda6db3de Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Mon, 20 Apr 2020 20:14:07 +0200 Subject: [PATCH 2/8] Extract check for hg in Utils --- e2e/Utils.ts | 5 +++++ e2e/__tests__/jestChangedFiles.test.ts | 7 +------ e2e/__tests__/onlyChanged.test.ts | 7 +------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 614831acae17..a4eec3e65adb 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -14,6 +14,7 @@ import {ExecaReturnValue, sync as spawnSync} from 'execa'; import makeDir = require('make-dir'); import rimraf = require('rimraf'); import dedent = require('dedent'); +import which = require('which'); interface RunResult extends ExecaReturnValue { status: number; @@ -260,3 +261,7 @@ export const normalizeIcons = (str: string) => { .replace(new RegExp('\u00D7', 'g'), '\u2715') .replace(new RegExp('\u221A', 'g'), '\u2713'); }; + +// Certain environments (like CITGM and GH Actions) do not come with mercurial installed +export const hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; +export const testIfHg = hgIsInstalled ? test : test.skip; diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index 5b8e3014cd7b..07f0674238c8 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -10,8 +10,7 @@ import * as path from 'path'; import {wrap} from 'jest-snapshot-serializer-raw'; import {findRepos, getChangedFilesForRoots} from 'jest-changed-files'; import {skipSuiteOnWindows} from '@jest/test-utils'; -import which = require('which'); -import {cleanup, run, writeFiles} from '../Utils'; +import {cleanup, hgIsInstalled, run, testIfHg, writeFiles} from '../Utils'; import runJest from '../runJest'; skipSuiteOnWindows(); @@ -24,10 +23,6 @@ const HG = 'hg --config ui.username=jest_test'; beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); -// Certain environments (like CITGM and GH Actions) do not come with mercurial installed -const hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; -const testIfHg = hgIsInstalled ? test : test.skip; - if (!hgIsInstalled) { console.warn('Mercurial (hg) is not installed - skipping some tests'); } diff --git a/e2e/__tests__/onlyChanged.test.ts b/e2e/__tests__/onlyChanged.test.ts index d2042b5d5b72..acc6c5748a8c 100644 --- a/e2e/__tests__/onlyChanged.test.ts +++ b/e2e/__tests__/onlyChanged.test.ts @@ -7,9 +7,8 @@ import {tmpdir} from 'os'; import * as path from 'path'; -import which = require('which'); import runJest from '../runJest'; -import {cleanup, run, writeFiles} from '../Utils'; +import {cleanup, hgIsInstalled, run, testIfHg, writeFiles} from '../Utils'; const DIR = path.resolve(tmpdir(), 'jest_only_changed'); const GIT = 'git -c user.name=jest_test -c user.email=jest_test@test.com'; @@ -18,10 +17,6 @@ const HG = 'hg --config ui.username=jest_test'; beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); -// Certain environments (like CITGM and GH Actions) do not come with mercurial installed -const hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; -const testIfHg = hgIsInstalled ? test : test.skip; - if (!hgIsInstalled) { console.warn('Mercurial (hg) is not installed - skipping some tests'); } From 65d6221200ddbe5e26b4fe161427e07d21b4eef3 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 21 Apr 2020 09:16:29 +0200 Subject: [PATCH 3/8] Another suggestion --- e2e/Utils.ts | 9 +++++++-- e2e/__tests__/jestChangedFiles.test.ts | 7 ++----- e2e/__tests__/onlyChanged.test.ts | 7 ++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/e2e/Utils.ts b/e2e/Utils.ts index a4eec3e65adb..9452c5f80bd0 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -263,5 +263,10 @@ export const normalizeIcons = (str: string) => { }; // Certain environments (like CITGM and GH Actions) do not come with mercurial installed -export const hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; -export const testIfHg = hgIsInstalled ? test : test.skip; +export const buildTestIfHg = () => { + const hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; + if (!hgIsInstalled) { + console.warn('Mercurial (hg) is not installed - skipping some tests'); + } + return hgIsInstalled ? test : test.skip; +}; diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index 07f0674238c8..ab850cd7a68f 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -10,7 +10,7 @@ import * as path from 'path'; import {wrap} from 'jest-snapshot-serializer-raw'; import {findRepos, getChangedFilesForRoots} from 'jest-changed-files'; import {skipSuiteOnWindows} from '@jest/test-utils'; -import {cleanup, hgIsInstalled, run, testIfHg, writeFiles} from '../Utils'; +import {buildTestIfHg, cleanup, run, writeFiles} from '../Utils'; import runJest from '../runJest'; skipSuiteOnWindows(); @@ -19,14 +19,11 @@ const DIR = path.resolve(tmpdir(), 'jest-changed-files-test-dir'); const GIT = 'git -c user.name=jest_test -c user.email=jest_test@test.com'; const HG = 'hg --config ui.username=jest_test'; +const testIfHg = buildTestIfHg(); beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); -if (!hgIsInstalled) { - console.warn('Mercurial (hg) is not installed - skipping some tests'); -} - testIfHg('gets hg SCM roots and dedupes them', async () => { writeFiles(DIR, { 'first-repo/file1.txt': 'file1', diff --git a/e2e/__tests__/onlyChanged.test.ts b/e2e/__tests__/onlyChanged.test.ts index acc6c5748a8c..fc4ec185937f 100644 --- a/e2e/__tests__/onlyChanged.test.ts +++ b/e2e/__tests__/onlyChanged.test.ts @@ -8,19 +8,16 @@ import {tmpdir} from 'os'; import * as path from 'path'; import runJest from '../runJest'; -import {cleanup, hgIsInstalled, run, testIfHg, writeFiles} from '../Utils'; +import {buildTestIfHg, cleanup, run, writeFiles} from '../Utils'; const DIR = path.resolve(tmpdir(), 'jest_only_changed'); const GIT = 'git -c user.name=jest_test -c user.email=jest_test@test.com'; const HG = 'hg --config ui.username=jest_test'; +const testIfHg = buildTestIfHg(); beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); -if (!hgIsInstalled) { - console.warn('Mercurial (hg) is not installed - skipping some tests'); -} - test('run for "onlyChanged" and "changedSince"', () => { writeFiles(DIR, { '.watchmanconfig': '', From 9bec25201e99ba01db63718b08da31f0e39eef5e Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 21 Apr 2020 18:59:34 +0200 Subject: [PATCH 4/8] Update e2e/Utils.ts Co-Authored-By: Simen Bekkhus --- e2e/Utils.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 9452c5f80bd0..8bfaea7f25be 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -263,10 +263,18 @@ export const normalizeIcons = (str: string) => { }; // Certain environments (like CITGM and GH Actions) do not come with mercurial installed -export const buildTestIfHg = () => { - const hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; - if (!hgIsInstalled) { +let hgIsInstalled: boolean | null = null; + +export const testIfHg: typeof test = (...args) => { + if (hgIsInstalled === null) { + hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; + } + + if (hgIsInstalled) { + test(...args); + } else { console.warn('Mercurial (hg) is not installed - skipping some tests'); + + test.skip(...args); } - return hgIsInstalled ? test : test.skip; }; From f2dce5dadfc151d0ac7488479da4ed565b6aa5bc Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 21 Apr 2020 19:15:14 +0200 Subject: [PATCH 5/8] Fix typings for testIfHg --- e2e/Utils.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 8bfaea7f25be..56ac971c7274 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -265,16 +265,17 @@ export const normalizeIcons = (str: string) => { // Certain environments (like CITGM and GH Actions) do not come with mercurial installed let hgIsInstalled: boolean | null = null; -export const testIfHg: typeof test = (...args) => { +export const testIfHg = ( + ...args: Parameters +): ReturnType => { if (hgIsInstalled === null) { hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; } - + if (hgIsInstalled) { - test(...args); + return test(...args); } else { console.warn('Mercurial (hg) is not installed - skipping some tests'); - - test.skip(...args); + return test.skip(...args); } }; From d57de701be21f1965a43eb595c1a3607f5ac27f4 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 21 Apr 2020 19:21:09 +0200 Subject: [PATCH 6/8] Fix missing renames --- e2e/__tests__/jestChangedFiles.test.ts | 3 +-- e2e/__tests__/onlyChanged.test.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index ab850cd7a68f..480e1d966187 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -10,7 +10,7 @@ import * as path from 'path'; import {wrap} from 'jest-snapshot-serializer-raw'; import {findRepos, getChangedFilesForRoots} from 'jest-changed-files'; import {skipSuiteOnWindows} from '@jest/test-utils'; -import {buildTestIfHg, cleanup, run, writeFiles} from '../Utils'; +import {cleanup, run, testIfHg, writeFiles} from '../Utils'; import runJest from '../runJest'; skipSuiteOnWindows(); @@ -19,7 +19,6 @@ const DIR = path.resolve(tmpdir(), 'jest-changed-files-test-dir'); const GIT = 'git -c user.name=jest_test -c user.email=jest_test@test.com'; const HG = 'hg --config ui.username=jest_test'; -const testIfHg = buildTestIfHg(); beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); diff --git a/e2e/__tests__/onlyChanged.test.ts b/e2e/__tests__/onlyChanged.test.ts index fc4ec185937f..52abdd6d0613 100644 --- a/e2e/__tests__/onlyChanged.test.ts +++ b/e2e/__tests__/onlyChanged.test.ts @@ -8,12 +8,11 @@ import {tmpdir} from 'os'; import * as path from 'path'; import runJest from '../runJest'; -import {buildTestIfHg, cleanup, run, writeFiles} from '../Utils'; +import {cleanup, run, testIfHg, writeFiles} from '../Utils'; const DIR = path.resolve(tmpdir(), 'jest_only_changed'); const GIT = 'git -c user.name=jest_test -c user.email=jest_test@test.com'; const HG = 'hg --config ui.username=jest_test'; -const testIfHg = buildTestIfHg(); beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); From 38268f7f30967de8a151a0f48f2490223d5d2878 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 21 Apr 2020 20:07:51 +0200 Subject: [PATCH 7/8] Update e2e/Utils.ts Co-Authored-By: Simen Bekkhus --- e2e/Utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 56ac971c7274..396b3768ad15 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -267,15 +267,15 @@ let hgIsInstalled: boolean | null = null; export const testIfHg = ( ...args: Parameters -): ReturnType => { +) => { if (hgIsInstalled === null) { hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; } if (hgIsInstalled) { - return test(...args); + test(...args); } else { console.warn('Mercurial (hg) is not installed - skipping some tests'); - return test.skip(...args); + test.skip(...args); } }; From fcab9600408c2536a4577620bbbb85143f03d530 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 21 Apr 2020 20:21:48 +0200 Subject: [PATCH 8/8] Fix format --- e2e/Utils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 396b3768ad15..52945c6f1041 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -265,9 +265,7 @@ export const normalizeIcons = (str: string) => { // Certain environments (like CITGM and GH Actions) do not come with mercurial installed let hgIsInstalled: boolean | null = null; -export const testIfHg = ( - ...args: Parameters -) => { +export const testIfHg = (...args: Parameters) => { if (hgIsInstalled === null) { hgIsInstalled = which.sync('hg', {nothrow: true}) !== null; }