Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: skip mercurial tests when no hg installed #9840

Merged
merged 8 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 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,21 @@ 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>
): ReturnType<typeof test> => {
dubzzz marked this conversation as resolved.
Show resolved Hide resolved
if (hgIsInstalled === null) {
hgIsInstalled = which.sync('hg', {nothrow: true}) !== null;
}

if (hgIsInstalled) {
return test(...args);
} else {
console.warn('Mercurial (hg) is not installed - skipping some tests');
return test.skip(...args);
}
};
dubzzz marked this conversation as resolved.
Show resolved Hide resolved
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