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

Unify conditional test logic #6314

Merged
merged 1 commit into from
May 27, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
'use strict';

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const ConditionalTest = require('../../scripts/ConditionalTest');
const {extractSummary, cleanup, writeFiles} = require('../Utils');
const runJest = require('../runJest');

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

SkipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/__tests__/each.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const path = require('path');
const runJest = require('../runJest');
const {extractSummary} = require('../Utils');
const dir = path.resolve(__dirname, '../each');
const SkipOnJestCircus = require('../../scripts/SkipOnJestCircus');
const ConditionalTest = require('../../scripts/ConditionalTest');

SkipOnJestCircus.suite();
ConditionalTest.skipSuiteOnJestCircus();

test('works with passing tests', () => {
const result = runJest(dir, ['success.test.js']);
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/__tests__/jest_changed_files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
findRepos,
getChangedFilesForRoots,
} from '../../packages/jest-changed-files/src';
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const ConditionalTest = require('../../scripts/ConditionalTest');
const {cleanup, run, writeFiles} = require('../Utils');

SkipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();

const DIR = path.resolve(os.tmpdir(), 'jest_changed_files_test_dir');

Expand Down
7 changes: 3 additions & 4 deletions integration-tests/__tests__/location_in_results.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
*/
'use strict';

import skipOnJestCicrus from '../../scripts/SkipOnJestCircus';
const runJest = require('../runJest');
const SkipOnJestCircus = require('../../scripts/SkipOnJestCircus');
const ConditionalTest = require('../../scripts/ConditionalTest');

skipOnJestCicrus.suite();
ConditionalTest.skipSuiteOnJestCircus();

it('defaults to null for location', () => {
const result = runJest.json('location-in-results').json;
Expand All @@ -37,7 +36,7 @@ it('adds correct location info when provided with flag', () => {
// Technically the column should be 3, but callsites is not correct.
// jest-circus uses stack-utils + asyncErrors which resolves this.
expect(assertions[1].location).toEqual({
column: SkipOnJestCircus.isJestCircusRun() ? 3 : 2,
column: ConditionalTest.isJestCircusRun() ? 3 : 2,
line: 15,
});
});
4 changes: 2 additions & 2 deletions integration-tests/__tests__/show_config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
'use strict';

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const ConditionalTest = require('../../scripts/ConditionalTest');
const runJest = require('../runJest');
const os = require('os');
const {cleanup, writeFiles} = require('../Utils');

SkipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();
const DIR = path.resolve(os.tmpdir(), 'show_config_test');

beforeEach(() => cleanup(DIR));
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-circus/src/__mocks__/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import {spawnSync} from 'child_process';
import fs from 'fs';
import os from 'os';
import path from 'path';
import skipOnWindows from '../../../../scripts/SkipOnWindows';
import ConditionalTest from '../../../../scripts/ConditionalTest';

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

skipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();

export const runTest = (source: string) => {
const tmpFilename = path.join(os.tmpdir(), 'circus-test-file.js');
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-circus/src/__tests__/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import {runTest} from '../__mocks__/test_utils';

const SkipOnWindows = require('../../../../scripts/SkipOnWindows');
SkipOnWindows.suite();
const ConditionalTest = require('../../../../scripts/ConditionalTest');
ConditionalTest.skipSuiteOnWindows();

test('beforeEach is executed before each test in current/child describe blocks', () => {
const {stdout} = runTest(`
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/__tests__/search_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import path from 'path';

jest.setTimeout(15000);

const SkipOnWindows = require('../../../../scripts/SkipOnWindows');
const ConditionalTest = require('../../../../scripts/ConditionalTest');

const rootDir = path.resolve(__dirname, 'test_root');
const testRegex = path.sep + '__testtests__' + path.sep;
Expand All @@ -25,7 +25,7 @@ let findMatchingTests;
let normalize;

describe('SearchSource', () => {
SkipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();

const name = 'SearchSource';
let Runtime;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jest.mock('graceful-fs', () => ({
}));
jest.mock('fs', () => require('graceful-fs'));

const SkipOnWindows = require('../../../../scripts/SkipOnWindows');
const ConditionalTest = require('../../../../scripts/ConditionalTest');

const cacheFilePath = '/cache-file';
let consoleWarn;
Expand All @@ -119,7 +119,7 @@ let mockWorker;
let getCacheFilePath;

describe('HasteMap', () => {
SkipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();

beforeEach(() => {
jest.resetModules();
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/__tests__/worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import path from 'path';
import fs from 'graceful-fs';
import SkipOnWindows from '../../../../scripts/SkipOnWindows';
import ConditionalTest from '../../../../scripts/ConditionalTest';

import H from '../constants';

Expand All @@ -20,7 +20,7 @@ let mockFs;
let readFileSync;

describe('worker', () => {
SkipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();

beforeEach(() => {
mockFs = {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/crawlers/__tests__/node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

'use strict';

const SkipOnWindows = require('../../../../../scripts/SkipOnWindows');
const ConditionalTest = require('../../../../../scripts/ConditionalTest');

jest.mock('child_process', () => ({
spawn: jest.fn((cmd, args) => {
Expand Down Expand Up @@ -72,7 +72,7 @@ let nodeCrawl;
let childProcess;

describe('node crawler', () => {
SkipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();

beforeEach(() => {
jest.resetModules();
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-repl/src/__tests__/jest_repl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

const {spawnSync} = require('child_process');
const path = require('path');
const SkipOnWindows = require('../../../../scripts/SkipOnWindows');
const ConditionalTest = require('../../../../scripts/ConditionalTest');

const JEST_RUNTIME = path.resolve(__dirname, '../../bin/jest-repl.js');

describe('Repl', () => {
SkipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();

describe('cli', () => {
it('runs without errors', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-runtime/src/__tests__/runtime_cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

const path = require('path');
const {sync: spawnSync} = require('execa');
const SkipOnWindows = require('../../../../scripts/SkipOnWindows');
const ConditionalTest = require('../../../../scripts/ConditionalTest');

SkipOnWindows.suite();
ConditionalTest.skipSuiteOnWindows();

const JEST_RUNTIME = path.resolve(__dirname, '../../bin/jest-runtime.js');

Expand Down
42 changes: 42 additions & 0 deletions scripts/ConditionalTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/* eslint-disable jest/no-focused-tests */

const ConditionalTest = {
isJestCircusRun() {
return process.env.JEST_CIRCUS === '1';
},

skipSuiteOnJasmine() {
if (!this.isJestCircusRun()) {
fit('does not work on Jasmine', () => {
console.warn('[SKIP] Does not work on Jasmine');
});
}
},

skipSuiteOnJestCircus() {
if (this.isJestCircusRun()) {
fit('does not work on jest-circus', () => {
console.warn('[SKIP] Does not work on jest-circus');
});
}
},

skipSuiteOnWindows() {
if (process.platform === 'win32') {
fit('does not work on Windows', () => {
console.warn('[SKIP] Does not work on Windows');
});
}
},
};

module.exports = ConditionalTest;
26 changes: 0 additions & 26 deletions scripts/SkipOnJestCircus.js

This file was deleted.

22 changes: 0 additions & 22 deletions scripts/SkipOnWindows.js

This file was deleted.