Skip to content

Commit

Permalink
test: allow more tests to run on windows (#10351)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Aug 2, 2020
1 parent 9186361 commit 683b7e6
Show file tree
Hide file tree
Showing 14 changed files with 597 additions and 279 deletions.
7 changes: 3 additions & 4 deletions e2e/__tests__/cliHandlesExactFilenames.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@

import * as path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import {skipSuiteOnWindows} from '@jest/test-utils';
import {cleanup, extractSummary, writeFiles} from '../Utils';
import runJest from '../runJest';

const DIR = path.resolve(__dirname, '../cli_accepts_exact_filenames');

skipSuiteOnWindows();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

Expand All @@ -30,7 +27,9 @@ test('CLI accepts exact file names if matchers matched', () => {

expect(result.exitCode).toBe(0);

const {rest, summary} = extractSummary(result.stderr);
const {rest, summary} = extractSummary(
result.stderr.replace('\\\\foo\\\\bar', '\\/foo\\/bar'),
);

expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
Expand Down
9 changes: 3 additions & 6 deletions e2e/__tests__/dependencyClash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@

import * as path from 'path';
import {tmpdir} from 'os';
import {skipSuiteOnWindows} from '@jest/test-utils';
import {cleanup, createEmptyPackage, writeFiles} from '../Utils';
import runJest from '../runJest';

skipSuiteOnWindows();

// doing test in a temp directory because we don't want jest node_modules affect it
const tempDir = path.resolve(tmpdir(), 'clashing-dependencies-test');
const hasteImplModulePath = path.resolve(
'./packages/jest-haste-map/src/__tests__/haste_impl.js',
);
const hasteImplModulePath = path
.resolve('./packages/jest-haste-map/src/__tests__/haste_impl.js')
.replace(/\\/g, '\\\\');

beforeEach(() => {
cleanup(tempDir);
Expand Down
10 changes: 7 additions & 3 deletions e2e/__tests__/detectOpenHandles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import {wrap} from 'jest-snapshot-serializer-raw';
import {onNodeVersions, skipSuiteOnWindows} from '@jest/test-utils';
import {onNodeVersions} from '@jest/test-utils';
import runJest, {runContinuous} from '../runJest';

try {
Expand Down Expand Up @@ -72,9 +72,13 @@ it('does not report promises', () => {
});

describe('notify', () => {
skipSuiteOnWindows();

it('does not report --notify flag', () => {
if (process.platform === 'win32') {
console.warn('[SKIP] Does not work on Windows');

return;
}

// The test here is basically that it exits cleanly without reporting anything (does not need `until`)
const {stderr} = runJest('detect-open-handles', ['notify', '--notify']);
const textAfterTest = getTextAfterTest(stderr);
Expand Down
10 changes: 6 additions & 4 deletions e2e/__tests__/existentRoots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as path from 'path';
import {tmpdir} from 'os';
import {skipSuiteOnWindows} from '@jest/test-utils';
import {tryRealpath} from 'jest-util';
import {cleanup, writeFiles} from '../Utils';
import runJest from '../runJest';

Expand All @@ -16,8 +16,6 @@ const DIR = path.resolve(tmpdir(), 'existent-roots');
beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

skipSuiteOnWindows();

function writeConfig(rootDir: string, roots?: Array<string>) {
writeFiles(DIR, {
'jest.config.js': `
Expand All @@ -40,7 +38,11 @@ test('error when rootDir does not exist', () => {
});

test('error when rootDir is a file', () => {
const fakeRootDir = path.join(DIR, 'jest.config.js');
// Replace tmpdir with its realpath as Windows uses the 8.3 path
const fakeRootDir = path
.join(DIR, 'jest.config.js')
.replace(tmpdir(), tryRealpath(tmpdir()));

writeConfig(fakeRootDir);

const {exitCode, stderr} = runJest(DIR);
Expand Down
28 changes: 19 additions & 9 deletions e2e/__tests__/jestChangedFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import {tmpdir} from 'os';
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 slash from 'slash';
import {cleanup, run, testIfHg, writeFiles} from '../Utils';
import runJest from '../runJest';

skipSuiteOnWindows();

const DIR = path.resolve(tmpdir(), 'jest-changed-files-test-dir');

const GIT = 'git -c user.name=jest_test -c [email protected]';
Expand Down Expand Up @@ -54,8 +52,12 @@ testIfHg('gets hg SCM roots and dedupes 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(slash(hgRepos[0])).toMatch(
/\/jest-changed-files-test-dir\/first-repo\/?$/,
);
expect(slash(hgRepos[1])).toMatch(
/\/jest-changed-files-test-dir\/second-repo\/?$/,
);
});

test('gets git SCM roots and dedupes them', async () => {
Expand Down Expand Up @@ -88,8 +90,12 @@ test('gets git SCM roots and dedupes 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(slash(gitRepos[0])).toMatch(
/\/jest-changed-files-test-dir\/first-repo\/?$/,
);
expect(slash(gitRepos[1])).toMatch(
/\/jest-changed-files-test-dir\/second-repo\/?$/,
);
});

testIfHg('gets mixed git and hg SCM roots and dedupes them', async () => {
Expand Down Expand Up @@ -121,8 +127,12 @@ testIfHg('gets mixed git and hg SCM roots and dedupes 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(slash(gitRepos[0])).toMatch(
/\/jest-changed-files-test-dir\/first-repo\/?$/,
);
expect(slash(hgRepos[0])).toMatch(
/\/jest-changed-files-test-dir\/second-repo\/?$/,
);
});

test('gets changed files for git', async () => {
Expand Down
11 changes: 7 additions & 4 deletions e2e/__tests__/pnp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@
*/

import * as path from 'path';
import {skipSuiteOnWindows} from '@jest/test-utils';
import {json as runWithJson} from '../runJest';
import {runYarn} from '../Utils';

const DIR = path.resolve(__dirname, '..', 'pnp');

// https://github.com/facebook/jest/pull/8094#issuecomment-471220694
skipSuiteOnWindows();

beforeEach(() => {
runYarn(DIR, {YARN_NODE_LINKER: 'pnp'});
});

it('successfully runs the tests inside `pnp/`', () => {
// https://github.com/facebook/jest/pull/8094#issuecomment-471220694
if (process.platform === 'win32') {
console.warn('[SKIP] Does not work on Windows');

return;
}

const {json} = runWithJson(DIR, ['--no-cache', '--coverage'], {
env: {YARN_NODE_LINKER: 'pnp'},
nodeOptions: `--require ${DIR}/.pnp.js`,
Expand Down
5 changes: 2 additions & 3 deletions e2e/__tests__/showConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
import * as path from 'path';
import {tmpdir} from 'os';
import {wrap} from 'jest-snapshot-serializer-raw';
import {skipSuiteOnWindows} from '@jest/test-utils';
import runJest from '../runJest';
import {cleanup, writeFiles} from '../Utils';

skipSuiteOnWindows();

const DIR = path.resolve(tmpdir(), 'show-config-test');

beforeEach(() => cleanup(DIR));
Expand All @@ -33,6 +30,8 @@ test('--showConfig outputs config info and exits', () => {
]);

stdout = stdout
.replace(/\\\\node_modules\\\\/g, 'node_modules')
.replace(/\\\\(?:([^.]+?)|$)/g, '/$1')
.replace(/"cacheDirectory": "(.+)"/g, '"cacheDirectory": "/tmp/jest"')
.replace(/"name": "(.+)"/g, '"name": "[md5 hash]"')
.replace(/"version": "(.+)"/g, '"version": "[version]"')
Expand Down
21 changes: 13 additions & 8 deletions packages/jest-circus/src/__mocks__/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ import {createHash} from 'crypto';
import * as fs from 'graceful-fs';
// eslint-disable-next-line import/named
import {ExecaSyncReturnValue, sync as spawnSync} from 'execa';
import {skipSuiteOnWindows} from '@jest/test-utils';

const CIRCUS_PATH = require.resolve('../../build');
const CIRCUS_RUN_PATH = require.resolve('../../build/run');
const CIRCUS_STATE_PATH = require.resolve('../../build/state');
const TEST_EVENT_HANDLER_PATH = require.resolve('./testEventHandler');
const BABEL_REGISTER_PATH = require.resolve('@babel/register');

skipSuiteOnWindows();
const CIRCUS_PATH = require.resolve('../../build').replace(/\\/g, '\\\\');
const CIRCUS_RUN_PATH = require
.resolve('../../build/run')
.replace(/\\/g, '\\\\');
const CIRCUS_STATE_PATH = require
.resolve('../../build/state')
.replace(/\\/g, '\\\\');
const TEST_EVENT_HANDLER_PATH = require
.resolve('./testEventHandler')
.replace(/\\/g, '\\\\');
const BABEL_REGISTER_PATH = require
.resolve('@babel/register')
.replace(/\\/g, '\\\\');

interface Result extends ExecaSyncReturnValue {
status: number;
Expand Down
Loading

0 comments on commit 683b7e6

Please sign in to comment.