Skip to content

Commit

Permalink
chore: skip mercurial tests when no hg installed (#9840)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz authored Apr 21, 2020
1 parent 47e956f commit 542959c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
17 changes: 17 additions & 0 deletions e2e/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -260,3 +261,19 @@ 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
let hgIsInstalled: boolean | null = null;

export const testIfHg = (...args: Parameters<typeof test>) => {
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);
}
};
11 changes: 1 addition & 10 deletions e2e/__tests__/jestChangedFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, run, testIfHg, writeFiles} from '../Utils';
import runJest from '../runJest';

skipSuiteOnWindows();
Expand All @@ -24,14 +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');
}

testIfHg('gets hg SCM roots and dedupes them', async () => {
writeFiles(DIR, {
'first-repo/file1.txt': 'file1',
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/onlyChanged.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {tmpdir} from 'os';
import * as path from 'path';
import runJest from '../runJest';
import {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';
Expand Down Expand Up @@ -252,7 +252,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
Expand Down

0 comments on commit 542959c

Please sign in to comment.