From e3f0b434ec73ad841a34dcd4583cd286503ba56a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 7 Oct 2018 17:33:48 +0200 Subject: [PATCH] chore: use ESM in integration tests (#7114) --- TestUtils.js | 9 +--- e2e/Utils.js | 49 +++++++---------- e2e/__tests__/auto_clear_mocks.test.js | 2 +- e2e/__tests__/auto_reset_mocks.test.js | 2 +- e2e/__tests__/auto_restore_mocks.test.js | 2 +- e2e/__tests__/babel_plugin_jest_hoist.test.js | 8 +-- e2e/__tests__/bad_source_map.test.js | 2 +- e2e/__tests__/before-all-filtered.js | 2 +- e2e/__tests__/before-each-queue.js | 2 +- e2e/__tests__/clear_cache.test.js | 8 +-- .../cli-handles-exact-filenames.test.js | 10 ++-- e2e/__tests__/compare_dom_nodes.test.js | 2 +- e2e/__tests__/config.test.js | 2 +- e2e/__tests__/console.test.js | 4 +- ...onsole_log_output_when_run_in_band.test.js | 6 +-- e2e/__tests__/coverage_remapping.test.js | 8 +-- e2e/__tests__/coverage_report.test.js | 8 +-- e2e/__tests__/coverage_threshold.test.js | 6 +-- .../coverage_transform_instrumented.test.js | 8 +-- e2e/__tests__/custom-resolver.test.js | 2 +- .../custom_matcher_stack_trace.test.js | 4 +- e2e/__tests__/custom_reporters.test.js | 8 +-- e2e/__tests__/debug.test.js | 4 +- e2e/__tests__/dependency_clash.test.js | 18 +++---- e2e/__tests__/deprecated_cli_options.test.js | 4 +- e2e/__tests__/detect_open_handles.js | 14 ++--- e2e/__tests__/each.test.js | 7 +-- .../empty-describe-with-hooks.test.js | 11 ++-- e2e/__tests__/empty_suite_error.test.js | 4 +- e2e/__tests__/env.test.js | 2 +- e2e/__tests__/error-on-deprecated.test.js | 8 +-- e2e/__tests__/execute-tests-once-in-mpr.js | 6 +-- e2e/__tests__/expect-async-matcher.test.js | 6 +-- e2e/__tests__/expect_in_vm.test.js | 2 +- e2e/__tests__/failures.test.js | 6 +-- e2e/__tests__/fake-promises.test.js | 2 +- e2e/__tests__/filter.test.js | 2 +- e2e/__tests__/find_related_files.test.js | 3 +- e2e/__tests__/force_exit.test.js | 2 +- e2e/__tests__/generator_mock.test.js | 2 +- e2e/__tests__/global_setup.test.js | 12 ++--- e2e/__tests__/global_teardown.test.js | 14 ++--- e2e/__tests__/globals.test.js | 14 +++-- e2e/__tests__/haste_map_sha1.test.js | 2 +- e2e/__tests__/jasmine_async.test.js | 26 ++++------ e2e/__tests__/jest.config.js.test.js | 6 +-- e2e/__tests__/jest_changed_files.test.js | 6 +-- e2e/__tests__/jest_require_actual.test.js | 8 +-- e2e/__tests__/jest_require_mock.test.js | 8 +-- e2e/__tests__/json_reporter.test.js | 6 +-- e2e/__tests__/lifecycles.js | 2 +- e2e/__tests__/list_tests.test.js | 4 +- e2e/__tests__/location_in_results.test.js | 12 ++--- e2e/__tests__/log_heap_usage.test.js | 8 +-- e2e/__tests__/mock_names.test.js | 2 +- e2e/__tests__/module_name_mapper.test.js | 4 +- e2e/__tests__/module_parent_null_in_test.js | 2 +- e2e/__tests__/multi_project_runner.test.js | 2 +- e2e/__tests__/native_async_mock.test.js | 6 +-- e2e/__tests__/nested_event_loop.test.js | 2 +- e2e/__tests__/no_test_found.test.js | 2 +- e2e/__tests__/no_tests_found.test.js | 4 +- e2e/__tests__/node_path.test.js | 2 +- e2e/__tests__/only_changed.test.js | 2 +- e2e/__tests__/presets.test.js | 2 +- e2e/__tests__/process_exit.test.js | 2 +- e2e/__tests__/promise_reject.test.js | 3 +- e2e/__tests__/regex_(char_in_path.test.js | 4 +- e2e/__tests__/require_after_teardown.test.js | 2 +- e2e/__tests__/require_main.test.js | 2 +- e2e/__tests__/reset_modules.test.js | 2 +- e2e/__tests__/resolve-get-paths.test.js | 2 +- e2e/__tests__/resolve-node-module.test.js | 2 +- e2e/__tests__/resolve-with-paths.test.js | 7 ++- e2e/__tests__/resolve.test.js | 2 +- e2e/__tests__/run_tests_by_path.test.js | 2 +- .../runtime_internal_module_registry.test.js | 4 +- e2e/__tests__/set_immediate.test.js | 2 +- ...t_framework_script_file_cli_config.test.js | 6 +-- e2e/__tests__/show_config.test.js | 13 ++--- e2e/__tests__/snapshot.test.js | 28 +++++----- e2e/__tests__/snapshot_resolver.test.js | 6 +-- e2e/__tests__/snapshot_serializers.test.js | 8 +-- e2e/__tests__/stack_trace.test.js | 4 +- .../stack_trace_no_captureStackTrace.test.js | 2 +- e2e/__tests__/stack_trace_source_maps.test.js | 6 +-- e2e/__tests__/test-todo.test.js | 6 +-- e2e/__tests__/test_environment.test.js | 6 +-- e2e/__tests__/test_environment_async.test.js | 8 +-- e2e/__tests__/test_failure_exit_code.test.js | 8 +-- e2e/__tests__/test_in_root.test.js | 6 +-- e2e/__tests__/test_name_pattern.test.js | 6 +-- .../test_name_pattern_skipped.test.js | 6 +-- ...test_path_pattern_reporter_message.test.js | 2 +- e2e/__tests__/test_results_processor.test.js | 6 +-- e2e/__tests__/test_retries.test.js | 11 ++-- e2e/__tests__/timeouts.test.js | 6 +-- e2e/__tests__/timeouts_legacy.test.js | 10 ++-- e2e/__tests__/timer_reset_mocks.test.js | 2 +- e2e/__tests__/timer_use_real_timers.test.js | 2 +- .../to_match_inline_snapshot.test.js | 8 +-- e2e/__tests__/to_match_snapshot.test.js | 6 +-- ...row_error_matching_inline_snapshot.test.js | 8 +-- .../to_throw_error_matching_snapshot.test.js | 8 +-- .../transform-linked-modules.test.js | 6 ++- e2e/__tests__/transform.test.js | 22 ++++---- e2e/__tests__/typescript_coverage.test.js | 6 +-- e2e/__tests__/unexpected-token.test.js | 2 +- e2e/__tests__/use_stderr.test.js | 2 +- e2e/__tests__/verbose.test.js | 2 +- e2e/__tests__/version.test.js | 8 +-- e2e/coverage-report/__tests__/Sum.test.js | 2 +- .../a/__tests__/Identical.test.js | 2 +- .../b/__tests__/Identical.test.js | 2 +- .../Preprocessor.js | 4 +- e2e/custom-resolver/resolver.js | 4 +- e2e/detect-open-handles/server.js | 4 +- e2e/require-main/loader.js | 2 +- e2e/runJest.js | 26 +++++----- .../jest-circus/src/__mocks__/test_utils.js | 4 +- .../src/__tests__/SearchSource.test.js | 6 +-- .../src/__tests__/index.test.js | 5 +- .../src/__tests__/worker.test.js | 4 +- .../src/crawlers/__tests__/node.test.js | 4 +- .../jest-repl/src/__tests__/jest_repl.test.js | 8 +-- .../src/__tests__/runtime_cli.test.js | 8 +-- scripts/ConditionalTest.js | 52 +++++++++---------- 127 files changed, 404 insertions(+), 420 deletions(-) diff --git a/TestUtils.js b/TestUtils.js index f7d376858913..3cd6e43ecb3e 100644 --- a/TestUtils.js +++ b/TestUtils.js @@ -119,7 +119,7 @@ const DEFAULT_PROJECT_CONFIG: ProjectConfig = { watchPathIgnorePatterns: [], }; -const makeGlobalConfig = (overrides: Object = {}): GlobalConfig => { +export const makeGlobalConfig = (overrides: Object = {}): GlobalConfig => { const overridesKeys = new Set(Object.keys(overrides)); Object.keys(DEFAULT_GLOBAL_CONFIG).forEach(key => overridesKeys.delete(key)); @@ -133,7 +133,7 @@ const makeGlobalConfig = (overrides: Object = {}): GlobalConfig => { return Object.assign({}, DEFAULT_GLOBAL_CONFIG, overrides); }; -const makeProjectConfig = (overrides: Object = {}): ProjectConfig => { +export const makeProjectConfig = (overrides: Object = {}): ProjectConfig => { const overridesKeys = new Set(Object.keys(overrides)); Object.keys(DEFAULT_PROJECT_CONFIG).forEach(key => overridesKeys.delete(key)); @@ -146,8 +146,3 @@ const makeProjectConfig = (overrides: Object = {}): ProjectConfig => { return Object.assign({}, DEFAULT_PROJECT_CONFIG, overrides); }; - -module.exports = { - makeGlobalConfig, - makeProjectConfig, -}; diff --git a/e2e/Utils.js b/e2e/Utils.js index 2677e252d3d5..5b8b68924328 100644 --- a/e2e/Utils.js +++ b/e2e/Utils.js @@ -11,13 +11,13 @@ import type {Path} from 'types/Config'; -const {sync: spawnSync} = require('execa'); -const fs = require('fs'); -const path = require('path'); -const mkdirp = require('mkdirp'); -const rimraf = require('rimraf'); +import {sync as spawnSync} from 'execa'; +import fs from 'fs'; +import path from 'path'; +import mkdirp from 'mkdirp'; +import rimraf from 'rimraf'; -const run = (cmd: string, cwd?: Path) => { +export const run = (cmd: string, cwd?: Path) => { const args = cmd.split(/\s/).slice(1); const spawnOptions = {cwd, reject: false}; const result = spawnSync(cmd.split(/\s/)[0], args, spawnOptions); @@ -39,7 +39,7 @@ const run = (cmd: string, cwd?: Path) => { return result; }; -const linkJestPackage = (packageName: string, cwd: Path) => { +export const linkJestPackage = (packageName: string, cwd: Path) => { const packagesDir = path.resolve(__dirname, '../packages'); const packagePath = path.resolve(packagesDir, packageName); const destination = path.resolve(cwd, 'node_modules/', packageName); @@ -48,9 +48,9 @@ const linkJestPackage = (packageName: string, cwd: Path) => { fs.symlinkSync(packagePath, destination, 'dir'); }; -const makeTemplate = (str: string): ((values?: Array) => string) => ( - values: ?Array, -) => +export const makeTemplate = ( + str: string, +): ((values?: Array) => string) => (values: ?Array) => str.replace(/\$(\d+)/g, (match, number) => { if (!Array.isArray(values)) { throw new Error('Array of values must be passed to the template.'); @@ -58,7 +58,7 @@ const makeTemplate = (str: string): ((values?: Array) => string) => ( return values[number - 1]; }); -const cleanup = (directory: string) => rimraf.sync(directory); +export const cleanup = (directory: string) => rimraf.sync(directory); /** * Creates a nested directory with files and their contents @@ -70,7 +70,10 @@ const cleanup = (directory: string) => rimraf.sync(directory); * } * ); */ -const writeFiles = (directory: string, files: {[filename: string]: string}) => { +export const writeFiles = ( + directory: string, + files: {[filename: string]: string}, +) => { mkdirp.sync(directory); Object.keys(files).forEach(fileOrPath => { const filePath = fileOrPath.split('/'); // ['tmp', 'a.js'] @@ -86,7 +89,7 @@ const writeFiles = (directory: string, files: {[filename: string]: string}) => { }); }; -const copyDir = (src: string, dest: string) => { +export const copyDir = (src: string, dest: string) => { const srcStat = fs.lstatSync(src); if (srcStat.isDirectory()) { if (!fs.existsSync(dest)) { @@ -100,7 +103,7 @@ const copyDir = (src: string, dest: string) => { } }; -const createEmptyPackage = ( +export const createEmptyPackage = ( directory: Path, packageJson?: {[keys: string]: any}, ) => { @@ -119,7 +122,7 @@ const createEmptyPackage = ( ); }; -const extractSummary = (stdout: string) => { +export const extractSummary = (stdout: string) => { const match = stdout.match( /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, ); @@ -148,12 +151,12 @@ const extractSummary = (stdout: string) => { // different versions of Node print different stack traces. This function // unifies their output to make it possible to snapshot them. // TODO: Remove when we drop support for node 4 -const cleanupStackTrace = (output: string) => +export const cleanupStackTrace = (output: string) => output .replace(/.*(?=packages)/g, ' at ') .replace(/^.*at.*[\s][\(]?(\S*\:\d*\:\d*).*$/gm, ' at $1'); -const normalizeIcons = (str: string) => { +export const normalizeIcons = (str: string) => { if (!str) { return str; } @@ -163,15 +166,3 @@ const normalizeIcons = (str: string) => { .replace(new RegExp('\u00D7', 'g'), '\u2715') .replace(new RegExp('\u221A', 'g'), '\u2713'); }; - -module.exports = { - cleanup, - copyDir, - createEmptyPackage, - extractSummary, - linkJestPackage, - makeTemplate, - normalizeIcons, - run, - writeFiles, -}; diff --git a/e2e/__tests__/auto_clear_mocks.test.js b/e2e/__tests__/auto_clear_mocks.test.js index 197880a92d13..115695536b4d 100644 --- a/e2e/__tests__/auto_clear_mocks.test.js +++ b/e2e/__tests__/auto_clear_mocks.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('suite with auto-clear', () => { const result = runJest('auto-clear-mocks/with-auto-clear'); diff --git a/e2e/__tests__/auto_reset_mocks.test.js b/e2e/__tests__/auto_reset_mocks.test.js index 405140ee3da1..a73a2bc44845 100644 --- a/e2e/__tests__/auto_reset_mocks.test.js +++ b/e2e/__tests__/auto_reset_mocks.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('suite with auto-reset', () => { const result = runJest('auto-reset-mocks/with-auto-reset'); diff --git a/e2e/__tests__/auto_restore_mocks.test.js b/e2e/__tests__/auto_restore_mocks.test.js index f0f211dd4d9f..e206cf142cb5 100644 --- a/e2e/__tests__/auto_restore_mocks.test.js +++ b/e2e/__tests__/auto_restore_mocks.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('suite with auto-restore', () => { const result = runJest('auto-restore-mocks/with-auto-restore'); diff --git a/e2e/__tests__/babel_plugin_jest_hoist.test.js b/e2e/__tests__/babel_plugin_jest_hoist.test.js index bb4d0b76ea7f..25afbc0fc2f3 100644 --- a/e2e/__tests__/babel_plugin_jest_hoist.test.js +++ b/e2e/__tests__/babel_plugin_jest_hoist.test.js @@ -8,9 +8,9 @@ */ 'use strict'; -const path = require('path'); -const {run} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {json as runWithJson} from '../runJest'; +import {run} from '../Utils'; const DIR = path.resolve(__dirname, '..', 'babel-plugin-jest-hoist'); @@ -19,7 +19,7 @@ beforeEach(() => { }); it('sucessfully runs the tests inside `babel-plugin-jest-hoist/`', () => { - const {json} = runJest.json(DIR, ['--no-cache', '--coverage']); + const {json} = runWithJson(DIR, ['--no-cache', '--coverage']); expect(json.success).toBe(true); expect(json.numTotalTestSuites).toBe(2); }); diff --git a/e2e/__tests__/bad_source_map.test.js b/e2e/__tests__/bad_source_map.test.js index f2ac3a4050c0..de4527a9b518 100644 --- a/e2e/__tests__/bad_source_map.test.js +++ b/e2e/__tests__/bad_source_map.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('suite with test cases that contain malformed sourcemaps', () => { const result = runJest('bad-source-map'); diff --git a/e2e/__tests__/before-all-filtered.js b/e2e/__tests__/before-all-filtered.js index 55c2401b45da..04d2e77ce9d4 100644 --- a/e2e/__tests__/before-all-filtered.js +++ b/e2e/__tests__/before-all-filtered.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; describe('Correct BeforeAll run', () => { it('ensures the BeforeAll of ignored suite is not run', () => { diff --git a/e2e/__tests__/before-each-queue.js b/e2e/__tests__/before-each-queue.js index a3d2b34d4f2d..dd177f2448b9 100644 --- a/e2e/__tests__/before-each-queue.js +++ b/e2e/__tests__/before-each-queue.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; describe('Correct beforeEach order', () => { it('ensures the correct order for beforeEach', () => { diff --git a/e2e/__tests__/clear_cache.test.js b/e2e/__tests__/clear_cache.test.js index 2d2bb4bd4bc6..da98372885a8 100644 --- a/e2e/__tests__/clear_cache.test.js +++ b/e2e/__tests__/clear_cache.test.js @@ -8,10 +8,10 @@ */ 'use strict'; -const fs = require('fs'); -const os = require('os'); -const path = require('path'); -const runJest = require('../runJest'); +import fs from 'fs'; +import os from 'os'; +import path from 'path'; +import runJest from '../runJest'; const CACHE = path.resolve(os.tmpdir(), 'clear-cache-directory'); diff --git a/e2e/__tests__/cli-handles-exact-filenames.test.js b/e2e/__tests__/cli-handles-exact-filenames.test.js index e60fc96909c0..9e838abac5ca 100644 --- a/e2e/__tests__/cli-handles-exact-filenames.test.js +++ b/e2e/__tests__/cli-handles-exact-filenames.test.js @@ -9,14 +9,14 @@ 'use strict'; -const path = require('path'); -const ConditionalTest = require('../../scripts/ConditionalTest'); -const {extractSummary, cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {skipSuiteOnWindows} from '../../scripts/ConditionalTest'; +import {cleanup, extractSummary, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../cli_accepts_exact_filenames'); -ConditionalTest.skipSuiteOnWindows(); +skipSuiteOnWindows(); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); diff --git a/e2e/__tests__/compare_dom_nodes.test.js b/e2e/__tests__/compare_dom_nodes.test.js index 58cc42b41d19..3cf76a34a31d 100644 --- a/e2e/__tests__/compare_dom_nodes.test.js +++ b/e2e/__tests__/compare_dom_nodes.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('does not crash when expect involving a DOM node fails', () => { const result = runJest('compare-dom-nodes'); diff --git a/e2e/__tests__/config.test.js b/e2e/__tests__/config.test.js index 08a5a6f31244..b93d04cff133 100644 --- a/e2e/__tests__/config.test.js +++ b/e2e/__tests__/config.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('config as JSON', () => { const result = runJest('verbose-reporter', [ diff --git a/e2e/__tests__/console.test.js b/e2e/__tests__/console.test.js index 807fc418744a..aa0a1e6a2edb 100644 --- a/e2e/__tests__/console.test.js +++ b/e2e/__tests__/console.test.js @@ -9,8 +9,8 @@ 'use strict'; -const {extractSummary} = require('../Utils'); -const runJest = require('../runJest'); +import {extractSummary} from '../Utils'; +import runJest from '../runJest'; test('console printing', () => { const {stderr, status} = runJest('console'); diff --git a/e2e/__tests__/console_log_output_when_run_in_band.test.js b/e2e/__tests__/console_log_output_when_run_in_band.test.js index 16be4ca0e33a..28d379616f62 100644 --- a/e2e/__tests__/console_log_output_when_run_in_band.test.js +++ b/e2e/__tests__/console_log_output_when_run_in_band.test.js @@ -9,9 +9,9 @@ 'use strict'; -const path = require('path'); -const {extractSummary, cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {cleanup, extractSummary, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../console_log_output_when_run_in_band'); diff --git a/e2e/__tests__/coverage_remapping.test.js b/e2e/__tests__/coverage_remapping.test.js index 676a0f07e29a..5194f5eba8df 100644 --- a/e2e/__tests__/coverage_remapping.test.js +++ b/e2e/__tests__/coverage_remapping.test.js @@ -9,10 +9,10 @@ 'use strict'; -const {readFileSync} = require('fs'); -const path = require('path'); -const {cleanup, run} = require('../Utils'); -const runJest = require('../runJest'); +import {readFileSync} from 'fs'; +import path from 'path'; +import {cleanup, run} from '../Utils'; +import runJest from '../runJest'; const dir = path.resolve(__dirname, '../coverage-remapping'); const coverageDir = path.join(dir, 'coverage'); diff --git a/e2e/__tests__/coverage_report.test.js b/e2e/__tests__/coverage_report.test.js index 2c29d268e945..98cf792dac3e 100644 --- a/e2e/__tests__/coverage_report.test.js +++ b/e2e/__tests__/coverage_report.test.js @@ -8,10 +8,10 @@ */ 'use strict'; -const fs = require('fs'); -const path = require('path'); -const {extractSummary} = require('../Utils'); -const runJest = require('../runJest'); +import fs from 'fs'; +import path from 'path'; +import {extractSummary} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../coverage-report'); diff --git a/e2e/__tests__/coverage_threshold.test.js b/e2e/__tests__/coverage_threshold.test.js index d0c81cef0d98..bc1256308b7b 100644 --- a/e2e/__tests__/coverage_threshold.test.js +++ b/e2e/__tests__/coverage_threshold.test.js @@ -9,9 +9,9 @@ 'use strict'; -const path = require('path'); -const {cleanup, writeFiles, extractSummary} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {cleanup, extractSummary, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../coverage-threshold'); diff --git a/e2e/__tests__/coverage_transform_instrumented.test.js b/e2e/__tests__/coverage_transform_instrumented.test.js index 47aad1f84c83..645c3d1c6022 100644 --- a/e2e/__tests__/coverage_transform_instrumented.test.js +++ b/e2e/__tests__/coverage_transform_instrumented.test.js @@ -9,10 +9,10 @@ 'use strict'; -const {readFileSync} = require('fs'); -const path = require('path'); -const {cleanup, run} = require('../Utils'); -const runJest = require('../runJest'); +import {readFileSync} from 'fs'; +import path from 'path'; +import {cleanup, run} from '../Utils'; +import runJest from '../runJest'; const dir = path.resolve(__dirname, '../coverage-transform-instrumented'); const coverageDir = path.join(dir, 'coverage'); diff --git a/e2e/__tests__/custom-resolver.test.js b/e2e/__tests__/custom-resolver.test.js index 5e3582ec861f..04d54fcddf07 100644 --- a/e2e/__tests__/custom-resolver.test.js +++ b/e2e/__tests__/custom-resolver.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('use the custom resolver', () => { const result = runJest('custom-resolver'); diff --git a/e2e/__tests__/custom_matcher_stack_trace.test.js b/e2e/__tests__/custom_matcher_stack_trace.test.js index badef8314bb3..993ac998dcfa 100644 --- a/e2e/__tests__/custom_matcher_stack_trace.test.js +++ b/e2e/__tests__/custom_matcher_stack_trace.test.js @@ -8,8 +8,8 @@ */ 'use strict'; -const runJest = require('../runJest'); -const {extractSummary} = require('../Utils'); +import runJest from '../runJest'; +import {extractSummary} from '../Utils'; test('works with custom matchers', () => { const {stderr} = runJest('custom-matcher-stack-trace'); diff --git a/e2e/__tests__/custom_reporters.test.js b/e2e/__tests__/custom_reporters.test.js index 7dd8ebe23704..5f4b3c40c254 100644 --- a/e2e/__tests__/custom_reporters.test.js +++ b/e2e/__tests__/custom_reporters.test.js @@ -8,10 +8,10 @@ */ 'use strict'; -const {cleanup, extractSummary, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); -const os = require('os'); -const path = require('path'); +import {cleanup, extractSummary, writeFiles} from '../Utils'; +import runJest from '../runJest'; +import os from 'os'; +import path from 'path'; const DIR = path.resolve(os.tmpdir(), 'custom-reporters-test-dir'); diff --git a/e2e/__tests__/debug.test.js b/e2e/__tests__/debug.test.js index ac8af5ad2c22..367bcd28d6a9 100644 --- a/e2e/__tests__/debug.test.js +++ b/e2e/__tests__/debug.test.js @@ -6,8 +6,8 @@ * @flow */ -const path = require('path'); -const runJest = require('../runJest'); +import path from 'path'; +import runJest from '../runJest'; describe('jest --debug', () => { const dir = path.resolve(__dirname, '..', 'verbose-reporter'); diff --git a/e2e/__tests__/dependency_clash.test.js b/e2e/__tests__/dependency_clash.test.js index d9730b57c74a..bbcdd37b3f33 100644 --- a/e2e/__tests__/dependency_clash.test.js +++ b/e2e/__tests__/dependency_clash.test.js @@ -7,20 +7,20 @@ * @flow */ -const path = require('path'); -const { +import path from 'path'; +import { cleanup, createEmptyPackage, linkJestPackage, writeFiles, -} = require('../Utils'); -const runJest = require('../runJest'); -const os = require('os'); -const mkdirp = require('mkdirp'); -const fs = require('fs'); -const ConditionalTest = require('../../scripts/ConditionalTest'); +} from '../Utils'; +import runJest from '../runJest'; +import os from 'os'; +import mkdirp from 'mkdirp'; +import fs from 'fs'; +import {skipSuiteOnWindows} from '../../scripts/ConditionalTest'; -ConditionalTest.skipSuiteOnWindows(); +skipSuiteOnWindows(); // doing test in a temp directory because we don't want jest node_modules affect it const tempDir = path.resolve(os.tmpdir(), 'clashing-dependencies-test'); diff --git a/e2e/__tests__/deprecated_cli_options.test.js b/e2e/__tests__/deprecated_cli_options.test.js index 102f4d5b3d03..ddbadb6f715c 100644 --- a/e2e/__tests__/deprecated_cli_options.test.js +++ b/e2e/__tests__/deprecated_cli_options.test.js @@ -9,8 +9,8 @@ 'use strict'; -const path = require('path'); -const runJest = require('../runJest'); +import path from 'path'; +import runJest from '../runJest'; const dir = path.resolve(__dirname, '../deprecated-cli-options'); diff --git a/e2e/__tests__/detect_open_handles.js b/e2e/__tests__/detect_open_handles.js index 1e47fd93ae9e..c4452234340d 100644 --- a/e2e/__tests__/detect_open_handles.js +++ b/e2e/__tests__/detect_open_handles.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest, {until} from '../runJest'; try { // $FlowFixMe: Node core @@ -29,7 +29,7 @@ function getTextAfterTest(stderr) { } it('prints message about flag on slow tests', async () => { - const {stderr} = await runJest.until( + const {stderr} = await until( 'detect-open-handles', ['outside'], 'Jest did not exit one second after the test run has completed.', @@ -40,7 +40,7 @@ it('prints message about flag on slow tests', async () => { }); it('prints message about flag on forceExit', async () => { - const {stderr} = await runJest.until( + const {stderr} = await until( 'detect-open-handles', ['outside', '--forceExit'], 'Force exiting Jest', @@ -51,7 +51,7 @@ it('prints message about flag on forceExit', async () => { }); it('prints out info about open handlers', async () => { - const {stderr} = await runJest.until( + const {stderr} = await until( 'detect-open-handles', ['outside', '--detectOpenHandles'], 'Jest has detected', @@ -63,7 +63,7 @@ it('prints out info about open handlers', async () => { ` ● GETADDRINFOREQWRAP - 5 | const app = new http.Server(); + 5 | const app = new Server(); 6 | > 7 | app.listen({host: 'localhost', port: 0}); | ^ @@ -76,7 +76,7 @@ it('prints out info about open handlers', async () => { }); it('does not report promises', () => { - // The test here is basically that it exits cleanly without reporting anything (does not need `runJest.until`) + // The test here is basically that it exits cleanly without reporting anything (does not need `until`) const {stderr} = runJest('detect-open-handles', [ 'promise', '--detectOpenHandles', @@ -87,7 +87,7 @@ it('does not report promises', () => { }); it('prints out info about open handlers from inside tests', async () => { - const {stderr} = await runJest.until( + const {stderr} = await until( 'detect-open-handles', ['inside', '--detectOpenHandles'], 'Jest has detected', diff --git a/e2e/__tests__/each.test.js b/e2e/__tests__/each.test.js index dbf20e10bc8c..8d18963c2c0b 100644 --- a/e2e/__tests__/each.test.js +++ b/e2e/__tests__/each.test.js @@ -9,9 +9,10 @@ 'use strict'; -const path = require('path'); -const runJest = require('../runJest'); -const {extractSummary} = require('../Utils'); +import path from 'path'; +import runJest from '../runJest'; +import {extractSummary} from '../Utils'; + const dir = path.resolve(__dirname, '../each'); test('works with passing tests', () => { diff --git a/e2e/__tests__/empty-describe-with-hooks.test.js b/e2e/__tests__/empty-describe-with-hooks.test.js index 7a366e3b6bf6..3ec27d391dc6 100644 --- a/e2e/__tests__/empty-describe-with-hooks.test.js +++ b/e2e/__tests__/empty-describe-with-hooks.test.js @@ -9,13 +9,14 @@ 'use strict'; -const path = require('path'); -const runJest = require('../runJest'); -const {extractSummary} = require('../Utils'); +import path from 'path'; +import runJest from '../runJest'; +import {extractSummary} from '../Utils'; +import {skipSuiteOnJasmine} from '../../scripts/ConditionalTest'; + const dir = path.resolve(__dirname, '../empty-describe-with-hooks'); -const ConditionalTest = require('../../scripts/ConditionalTest'); -ConditionalTest.skipSuiteOnJasmine(); +skipSuiteOnJasmine(); test('hook in empty describe', () => { const result = runJest(dir, ['hook-in-empty-describe.test.js']); diff --git a/e2e/__tests__/empty_suite_error.test.js b/e2e/__tests__/empty_suite_error.test.js index 40e7c1b99045..cba04194b535 100644 --- a/e2e/__tests__/empty_suite_error.test.js +++ b/e2e/__tests__/empty_suite_error.test.js @@ -8,8 +8,8 @@ 'use strict'; -const path = require('path'); -const runJest = require('../runJest'); +import path from 'path'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../empty-suite-error'); diff --git a/e2e/__tests__/env.test.js b/e2e/__tests__/env.test.js index 79dfcda7a61f..f65c6164ce84 100644 --- a/e2e/__tests__/env.test.js +++ b/e2e/__tests__/env.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; const getLog = result => result.stdout.split('\n')[1].trim(); diff --git a/e2e/__tests__/error-on-deprecated.test.js b/e2e/__tests__/error-on-deprecated.test.js index a3ea5f318916..8a69e0019a8a 100644 --- a/e2e/__tests__/error-on-deprecated.test.js +++ b/e2e/__tests__/error-on-deprecated.test.js @@ -8,11 +8,11 @@ */ 'use strict'; -const runJest = require('../runJest'); -const {extractSummary} = require('../Utils'); -const ConditionalTest = require('../../scripts/ConditionalTest'); +import runJest from '../runJest'; +import {extractSummary} from '../Utils'; +import {skipSuiteOnJestCircus} from '../../scripts/ConditionalTest'; -ConditionalTest.skipSuiteOnJestCircus(); +skipSuiteOnJestCircus(); const testFiles = [ 'fail.test.js', diff --git a/e2e/__tests__/execute-tests-once-in-mpr.js b/e2e/__tests__/execute-tests-once-in-mpr.js index 426e69171565..d367c2ddbcd6 100644 --- a/e2e/__tests__/execute-tests-once-in-mpr.js +++ b/e2e/__tests__/execute-tests-once-in-mpr.js @@ -9,9 +9,9 @@ 'use strict'; -const path = require('path'); -const {extractSummary, cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {cleanup, extractSummary, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../execute-tests-once-in-mpr'); diff --git a/e2e/__tests__/expect-async-matcher.test.js b/e2e/__tests__/expect-async-matcher.test.js index bdbb480e8a12..2e687a5fe0e6 100644 --- a/e2e/__tests__/expect-async-matcher.test.js +++ b/e2e/__tests__/expect-async-matcher.test.js @@ -9,9 +9,9 @@ 'use strict'; -const path = require('path'); -const runJest = require('../runJest'); -const {extractSummary} = require('../Utils'); +import path from 'path'; +import runJest from '../runJest'; +import {extractSummary} from '../Utils'; const dir = path.resolve(__dirname, '../expect-async-matcher'); test('works with passing tests', () => { diff --git a/e2e/__tests__/expect_in_vm.test.js b/e2e/__tests__/expect_in_vm.test.js index b4aca37ec889..30ba9cc96b6f 100644 --- a/e2e/__tests__/expect_in_vm.test.js +++ b/e2e/__tests__/expect_in_vm.test.js @@ -9,7 +9,7 @@ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('expect works correctly with RegExps created inside a VM', () => { const result = runJest('expect-in-vm'); diff --git a/e2e/__tests__/failures.test.js b/e2e/__tests__/failures.test.js index d8ee86c8b759..5b79e1ed3cd8 100644 --- a/e2e/__tests__/failures.test.js +++ b/e2e/__tests__/failures.test.js @@ -7,9 +7,9 @@ * @flow */ -const path = require('path'); -const {extractSummary} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {extractSummary} from '../Utils'; +import runJest from '../runJest'; const dir = path.resolve(__dirname, '../failures'); diff --git a/e2e/__tests__/fake-promises.test.js b/e2e/__tests__/fake-promises.test.js index b194a6ebdf23..df76c5546a16 100644 --- a/e2e/__tests__/fake-promises.test.js +++ b/e2e/__tests__/fake-promises.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; describe('Fake promises', () => { it('should be possible to resolve with fake timers using immediates', () => { diff --git a/e2e/__tests__/filter.test.js b/e2e/__tests__/filter.test.js index 092e58b57ae0..7a34def7f741 100644 --- a/e2e/__tests__/filter.test.js +++ b/e2e/__tests__/filter.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; describe('Dynamic test filtering', () => { it('uses the default JSON option', () => { diff --git a/e2e/__tests__/find_related_files.test.js b/e2e/__tests__/find_related_files.test.js index 45b8e52f0c3d..10b82c3cc832 100644 --- a/e2e/__tests__/find_related_files.test.js +++ b/e2e/__tests__/find_related_files.test.js @@ -12,8 +12,7 @@ import runJest from '../runJest'; import os from 'os'; import path from 'path'; - -const {cleanup, writeFiles, extractSummary} = require('../Utils'); +import {cleanup, extractSummary, writeFiles} from '../Utils'; const DIR = path.resolve(os.tmpdir(), 'find_related_tests_test'); diff --git a/e2e/__tests__/force_exit.test.js b/e2e/__tests__/force_exit.test.js index df39f1b36ec0..fbc805b9f408 100644 --- a/e2e/__tests__/force_exit.test.js +++ b/e2e/__tests__/force_exit.test.js @@ -12,7 +12,7 @@ import runJest from '../runJest'; import os from 'os'; import path from 'path'; -const {cleanup, writeFiles} = require('../Utils'); +import {cleanup, writeFiles} from '../Utils'; const DIR = path.resolve(os.tmpdir(), 'force_exit_test'); diff --git a/e2e/__tests__/generator_mock.test.js b/e2e/__tests__/generator_mock.test.js index 349e7d45148f..b8877472b28a 100644 --- a/e2e/__tests__/generator_mock.test.js +++ b/e2e/__tests__/generator_mock.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('mock works with generator', () => { const {status} = runJest('generator-mock'); diff --git a/e2e/__tests__/global_setup.test.js b/e2e/__tests__/global_setup.test.js index 8772a8e3e07c..be0d626cc350 100644 --- a/e2e/__tests__/global_setup.test.js +++ b/e2e/__tests__/global_setup.test.js @@ -7,11 +7,11 @@ */ 'use strict'; -const fs = require('fs'); -const os = require('os'); -const path = require('path'); -const runJest = require('../runJest'); -const {cleanup} = require('../Utils'); +import fs from 'fs'; +import os from 'os'; +import path from 'path'; +import runJest, {json as runWithJson} from '../runJest'; +import {cleanup} from '../Utils'; const DIR = path.join(os.tmpdir(), 'jest-global-setup'); @@ -20,7 +20,7 @@ afterAll(() => cleanup(DIR)); test('globalSetup is triggered once before all test suites', () => { const setupPath = path.resolve(__dirname, '../global-setup/setup.js'); - const result = runJest.json('global-setup', [`--globalSetup=${setupPath}`]); + const result = runWithJson('global-setup', [`--globalSetup=${setupPath}`]); expect(result.status).toBe(0); const files = fs.readdirSync(DIR); expect(files).toHaveLength(1); diff --git a/e2e/__tests__/global_teardown.test.js b/e2e/__tests__/global_teardown.test.js index 82bb9ccd425b..7408a1293155 100644 --- a/e2e/__tests__/global_teardown.test.js +++ b/e2e/__tests__/global_teardown.test.js @@ -7,12 +7,12 @@ */ 'use strict'; -const fs = require('fs'); -const mkdirp = require('mkdirp'); -const os = require('os'); -const path = require('path'); -const runJest = require('../runJest'); -const {cleanup} = require('../Utils'); +import fs from 'fs'; +import mkdirp from 'mkdirp'; +import os from 'os'; +import path from 'path'; +import runJest, {json as runWithJson} from '../runJest'; +import {cleanup} from '../Utils'; const DIR = path.join(os.tmpdir(), 'jest-global-teardown'); @@ -25,7 +25,7 @@ test('globalTeardown is triggered once after all test suites', () => { __dirname, '../global-teardown/teardown.js', ); - const result = runJest.json('global-teardown', [ + const result = runWithJson('global-teardown', [ `--globalTeardown=${teardownPath}`, ]); expect(result.status).toBe(0); diff --git a/e2e/__tests__/globals.test.js b/e2e/__tests__/globals.test.js index ed894869491c..cdaeadbac06b 100644 --- a/e2e/__tests__/globals.test.js +++ b/e2e/__tests__/globals.test.js @@ -9,11 +9,15 @@ 'use strict'; -const path = require('path'); -const os = require('os'); -const runJest = require('../runJest'); -const {extractSummary} = require('../Utils'); -const {createEmptyPackage, writeFiles, cleanup} = require('../Utils'); +import path from 'path'; +import os from 'os'; +import runJest from '../runJest'; +import { + cleanup, + createEmptyPackage, + extractSummary, + writeFiles, +} from '../Utils'; const DIR = path.resolve(os.tmpdir(), 'global-variables.test'); const TEST_DIR = path.resolve(DIR, '__tests__'); diff --git a/e2e/__tests__/haste_map_sha1.test.js b/e2e/__tests__/haste_map_sha1.test.js index 9889a2e2b45c..f09555ec6d3f 100644 --- a/e2e/__tests__/haste_map_sha1.test.js +++ b/e2e/__tests__/haste_map_sha1.test.js @@ -12,7 +12,7 @@ import os from 'os'; import path from 'path'; import JestHasteMap from 'jest-haste-map'; -const {cleanup, writeFiles} = require('../Utils'); +import {cleanup, writeFiles} from '../Utils'; const DIR = path.resolve(os.tmpdir(), 'haste_map_sha1'); diff --git a/e2e/__tests__/jasmine_async.test.js b/e2e/__tests__/jasmine_async.test.js index b410368896da..1ba352637969 100644 --- a/e2e/__tests__/jasmine_async.test.js +++ b/e2e/__tests__/jasmine_async.test.js @@ -9,13 +9,11 @@ 'use strict'; -const runJest = require('../runJest'); +import runJest, {json as runWithJson} from '../runJest'; describe('async jasmine', () => { it('works with beforeAll', () => { - const result = runJest.json('jasmine-async', [ - 'promise_before_all.test.js', - ]); + const result = runWithJson('jasmine-async', ['promise_before_all.test.js']); const json = result.json; expect(json.numTotalTests).toBe(4); @@ -31,7 +29,7 @@ describe('async jasmine', () => { }); it('works with beforeEach', () => { - const result = runJest.json('jasmine-async', [ + const result = runWithJson('jasmine-async', [ 'promise_before_each.test.js', ]); const json = result.json; @@ -47,7 +45,7 @@ describe('async jasmine', () => { }); it('works with afterAll', () => { - const result = runJest.json('jasmine-async', ['promise_after_all.test.js']); + const result = runWithJson('jasmine-async', ['promise_after_all.test.js']); const json = result.json; expect(json.numTotalTests).toBe(2); @@ -60,9 +58,7 @@ describe('async jasmine', () => { }); it('works with afterEach', () => { - const result = runJest.json('jasmine-async', [ - 'promise_after_each.test.js', - ]); + const result = runWithJson('jasmine-async', ['promise_after_each.test.js']); const json = result.json; expect(json.numTotalTests).toBe(2); @@ -73,7 +69,7 @@ describe('async jasmine', () => { }); it('works with fit', () => { - const result = runJest.json('jasmine-async', ['promise_fit.test.js']); + const result = runWithJson('jasmine-async', ['promise_fit.test.js']); const json = result.json; expect(json.numTotalTests).toBe(3); @@ -84,7 +80,7 @@ describe('async jasmine', () => { }); it('works with xit', () => { - const result = runJest.json('jasmine-async', ['promise_xit.test.js']); + const result = runWithJson('jasmine-async', ['promise_xit.test.js']); const json = result.json; expect(json.numTotalTests).toBe(2); @@ -94,7 +90,7 @@ describe('async jasmine', () => { }); it('throws when not a promise is returned', () => { - const result = runJest.json('jasmine-async', ['returning_values.test.js']); + const result = runWithJson('jasmine-async', ['returning_values.test.js']); const json = result.json; expect(json.numTotalTests).toBe(11); @@ -104,7 +100,7 @@ describe('async jasmine', () => { }); it('tests async promise code', () => { - const result = runJest.json('jasmine-async', ['promise_it.test.js']); + const result = runWithJson('jasmine-async', ['promise_it.test.js']); const json = result.json; const message = json.testResults[0].message; @@ -124,7 +120,7 @@ describe('async jasmine', () => { }); it('works with concurrent', () => { - const result = runJest.json('jasmine-async', ['concurrent.test.js']); + const result = runWithJson('jasmine-async', ['concurrent.test.js']); const json = result.json; expect(json.numTotalTests).toBe(4); expect(json.numPassedTests).toBe(2); @@ -134,7 +130,7 @@ describe('async jasmine', () => { }); it('async test fails', () => { - const result = runJest.json('jasmine-async', ['async_test_fails.test.js']); + const result = runWithJson('jasmine-async', ['async_test_fails.test.js']); expect(result.status).toBe(1); expect(result.json.testResults[0].message).toEqual( diff --git a/e2e/__tests__/jest.config.js.test.js b/e2e/__tests__/jest.config.js.test.js index ed367d791198..bc5ec2877a9c 100644 --- a/e2e/__tests__/jest.config.js.test.js +++ b/e2e/__tests__/jest.config.js.test.js @@ -9,9 +9,9 @@ 'use strict'; -const path = require('path'); -const {extractSummary, cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import runJest from '../runJest'; +import {cleanup, extractSummary, writeFiles} from '../Utils'; const DIR = path.resolve(__dirname, '../jest.config.js'); diff --git a/e2e/__tests__/jest_changed_files.test.js b/e2e/__tests__/jest_changed_files.test.js index facea568b39b..4498dd14598b 100644 --- a/e2e/__tests__/jest_changed_files.test.js +++ b/e2e/__tests__/jest_changed_files.test.js @@ -15,10 +15,10 @@ import { findRepos, getChangedFilesForRoots, } from '../../packages/jest-changed-files/src'; -const ConditionalTest = require('../../scripts/ConditionalTest'); -const {cleanup, run, writeFiles} = require('../Utils'); +import {skipSuiteOnWindows} from '../../scripts/ConditionalTest'; +import {cleanup, run, writeFiles} from '../Utils'; -ConditionalTest.skipSuiteOnWindows(); +skipSuiteOnWindows(); const DIR = path.resolve(os.tmpdir(), 'jest_changed_files_test_dir'); diff --git a/e2e/__tests__/jest_require_actual.test.js b/e2e/__tests__/jest_require_actual.test.js index 8a07876b1d70..6941eb645f89 100644 --- a/e2e/__tests__/jest_require_actual.test.js +++ b/e2e/__tests__/jest_require_actual.test.js @@ -9,10 +9,10 @@ 'use strict'; -const path = require('path'); -const os = require('os'); -const {cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import os from 'os'; +import {cleanup, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(os.tmpdir(), 'jest_require_actual_test'); diff --git a/e2e/__tests__/jest_require_mock.test.js b/e2e/__tests__/jest_require_mock.test.js index 5d7ab9e38475..e2a8984d9619 100644 --- a/e2e/__tests__/jest_require_mock.test.js +++ b/e2e/__tests__/jest_require_mock.test.js @@ -9,10 +9,10 @@ 'use strict'; -const path = require('path'); -const os = require('os'); -const {cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import os from 'os'; +import {cleanup, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(os.tmpdir(), 'jest_require_mock_test'); diff --git a/e2e/__tests__/json_reporter.test.js b/e2e/__tests__/json_reporter.test.js index 7fe8e803787c..3714aae2565e 100644 --- a/e2e/__tests__/json_reporter.test.js +++ b/e2e/__tests__/json_reporter.test.js @@ -8,9 +8,9 @@ */ 'use strict'; -const fs = require('fs'); -const path = require('path'); -const runJest = require('../runJest'); +import fs from 'fs'; +import path from 'path'; +import runJest from '../runJest'; describe('JSON Reporter', () => { const outputFileName = 'sum.result.json'; diff --git a/e2e/__tests__/lifecycles.js b/e2e/__tests__/lifecycles.js index 35b57fa973f2..e4fbe1bc7116 100644 --- a/e2e/__tests__/lifecycles.js +++ b/e2e/__tests__/lifecycles.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('suite with invalid assertions in afterAll', () => { const {stderr, status} = runJest('lifecycles'); diff --git a/e2e/__tests__/list_tests.test.js b/e2e/__tests__/list_tests.test.js index 392ee1def18b..34877a8cae68 100644 --- a/e2e/__tests__/list_tests.test.js +++ b/e2e/__tests__/list_tests.test.js @@ -8,8 +8,8 @@ */ 'use strict'; -const runJest = require('../runJest'); -const path = require('path'); +import runJest from '../runJest'; +import path from 'path'; const testRootDir = path.resolve(__dirname, '..', '..'); diff --git a/e2e/__tests__/location_in_results.test.js b/e2e/__tests__/location_in_results.test.js index 90ba52e641d9..4413863b98b1 100644 --- a/e2e/__tests__/location_in_results.test.js +++ b/e2e/__tests__/location_in_results.test.js @@ -8,11 +8,11 @@ */ 'use strict'; -const runJest = require('../runJest'); -const ConditionalTest = require('../../scripts/ConditionalTest'); +import {json as runWithJson} from '../runJest'; +import {isJestCircusRun} from '../../scripts/ConditionalTest'; it('defaults to null for location', () => { - const result = runJest.json('location-in-results').json; + const {json: result} = runWithJson('location-in-results'); const assertions = result.testResults[0].assertionResults; expect(result.success).toBe(true); @@ -22,9 +22,9 @@ it('defaults to null for location', () => { }); it('adds correct location info when provided with flag', () => { - const result = runJest.json('location-in-results', [ + const {json: result} = runWithJson('location-in-results', [ '--testLocationInResults', - ]).json; + ]); const assertions = result.testResults[0].assertionResults; expect(result.success).toBe(true); @@ -34,7 +34,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: ConditionalTest.isJestCircusRun() ? 3 : 2, + column: isJestCircusRun() ? 3 : 2, line: 15, }); }); diff --git a/e2e/__tests__/log_heap_usage.test.js b/e2e/__tests__/log_heap_usage.test.js index 7145d8652595..4ef70dce891d 100644 --- a/e2e/__tests__/log_heap_usage.test.js +++ b/e2e/__tests__/log_heap_usage.test.js @@ -9,10 +9,10 @@ 'use strict'; -const path = require('path'); -const os = require('os'); -const {cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import os from 'os'; +import {cleanup, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(os.tmpdir(), 'log_heap_usage_test'); diff --git a/e2e/__tests__/mock_names.test.js b/e2e/__tests__/mock_names.test.js index 0ba6cf786110..fd74fea05522 100644 --- a/e2e/__tests__/mock_names.test.js +++ b/e2e/__tests__/mock_names.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('suite without mock name, mock called', () => { const {stderr, status} = runJest('mock-names/without-mock-name'); diff --git a/e2e/__tests__/module_name_mapper.test.js b/e2e/__tests__/module_name_mapper.test.js index 4fda58c72e85..283b19d1bce4 100644 --- a/e2e/__tests__/module_name_mapper.test.js +++ b/e2e/__tests__/module_name_mapper.test.js @@ -8,8 +8,8 @@ */ 'use strict'; -const runJest = require('../runJest'); -const {extractSummary} = require('../Utils'); +import runJest from '../runJest'; +import {extractSummary} from '../Utils'; test('moduleNameMapper wrong configuration', () => { const {stderr, status} = runJest('module-name-mapper-wrong-config'); diff --git a/e2e/__tests__/module_parent_null_in_test.js b/e2e/__tests__/module_parent_null_in_test.js index 0b188ff36950..0b1fbfb15239 100644 --- a/e2e/__tests__/module_parent_null_in_test.js +++ b/e2e/__tests__/module_parent_null_in_test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('module.parent should be null in test files', () => { const {status} = runJest('module_parent_null_in_test'); diff --git a/e2e/__tests__/multi_project_runner.test.js b/e2e/__tests__/multi_project_runner.test.js index 4ecf778c55ed..68090f94ea4b 100644 --- a/e2e/__tests__/multi_project_runner.test.js +++ b/e2e/__tests__/multi_project_runner.test.js @@ -13,8 +13,8 @@ import runJest from '../runJest'; import os from 'os'; import path from 'path'; import stripAnsi from 'strip-ansi'; +import {cleanup, extractSummary, writeFiles} from '../Utils'; -const {cleanup, extractSummary, writeFiles} = require('../Utils'); const DIR = path.resolve(os.tmpdir(), 'multi_project_runner_test'); const fileContentWithProvidesModule = name => `/* diff --git a/e2e/__tests__/native_async_mock.test.js b/e2e/__tests__/native_async_mock.test.js index 3fd9c4517dde..4f3bccd201f0 100644 --- a/e2e/__tests__/native_async_mock.test.js +++ b/e2e/__tests__/native_async_mock.test.js @@ -9,9 +9,9 @@ 'use strict'; -const path = require('path'); -const {run, extractSummary} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {extractSummary, run} from '../Utils'; +import runJest from '../runJest'; const dir = path.resolve(__dirname, '..', 'native-async-mock'); diff --git a/e2e/__tests__/nested_event_loop.test.js b/e2e/__tests__/nested_event_loop.test.js index 7f44bb9dad8b..d7f187e7965d 100644 --- a/e2e/__tests__/nested_event_loop.test.js +++ b/e2e/__tests__/nested_event_loop.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('works with nested event loops', () => { const result = runJest('nested-event-loop'); diff --git a/e2e/__tests__/no_test_found.test.js b/e2e/__tests__/no_test_found.test.js index 3f056b42707c..dc80351ee8cf 100644 --- a/e2e/__tests__/no_test_found.test.js +++ b/e2e/__tests__/no_test_found.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; describe('Coverage Report', () => { it('outputs coverage report', () => { diff --git a/e2e/__tests__/no_tests_found.test.js b/e2e/__tests__/no_tests_found.test.js index 372476bf1d89..f3547cae37a7 100644 --- a/e2e/__tests__/no_tests_found.test.js +++ b/e2e/__tests__/no_tests_found.test.js @@ -9,8 +9,8 @@ 'use strict'; -const path = require('path'); -const runJest = require('../runJest'); +import path from 'path'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../no-tests-found-test'); diff --git a/e2e/__tests__/node_path.test.js b/e2e/__tests__/node_path.test.js index 7a06d20407b1..501b3b569b7e 100644 --- a/e2e/__tests__/node_path.test.js +++ b/e2e/__tests__/node_path.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('supports NODE_PATH', () => { // $FlowFixMe after adding @flow to this test this seems to be a real bug diff --git a/e2e/__tests__/only_changed.test.js b/e2e/__tests__/only_changed.test.js index cab816e9992e..af3dd5bdd048 100644 --- a/e2e/__tests__/only_changed.test.js +++ b/e2e/__tests__/only_changed.test.js @@ -12,7 +12,7 @@ import runJest from '../runJest'; import os from 'os'; import path from 'path'; -const {cleanup, run, writeFiles} = require('../Utils'); +import {cleanup, run, writeFiles} from '../Utils'; const DIR = path.resolve(os.tmpdir(), 'jest_only_changed'); const GIT = 'git -c user.name=jest_test -c user.email=jest_test@test.com'; diff --git a/e2e/__tests__/presets.test.js b/e2e/__tests__/presets.test.js index 0166d03dd26a..bc730eac97bc 100644 --- a/e2e/__tests__/presets.test.js +++ b/e2e/__tests__/presets.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('supports json preset', () => { const result = runJest('presets/json'); diff --git a/e2e/__tests__/process_exit.test.js b/e2e/__tests__/process_exit.test.js index 93397d67608e..68b371abdd36 100644 --- a/e2e/__tests__/process_exit.test.js +++ b/e2e/__tests__/process_exit.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; it('prints stack trace pointing to process.exit call', async () => { const {stderr} = await runJest('process-exit'); diff --git a/e2e/__tests__/promise_reject.test.js b/e2e/__tests__/promise_reject.test.js index b255afe5024a..47f74f49d7fd 100644 --- a/e2e/__tests__/promise_reject.test.js +++ b/e2e/__tests__/promise_reject.test.js @@ -7,10 +7,11 @@ * @flow */ 'use strict'; + import runJest from '../runJest'; import path from 'path'; +import {cleanup, writeFiles} from '../Utils'; -const {cleanup, writeFiles} = require('../Utils'); const DIR = path.resolve('../promise-reject'); beforeEach(() => cleanup(DIR)); diff --git a/e2e/__tests__/regex_(char_in_path.test.js b/e2e/__tests__/regex_(char_in_path.test.js index 2ca1db2c7d97..dde9d2d316ee 100644 --- a/e2e/__tests__/regex_(char_in_path.test.js +++ b/e2e/__tests__/regex_(char_in_path.test.js @@ -8,11 +8,11 @@ */ 'use strict'; -const runJest = require('../runJest'); +import {json as runWithJson} from '../runJest'; describe('Regex Char In Path', () => { it('parses paths containing regex chars correctly', () => { - const {json} = runJest.json('regex-(char-in-path', []); + const {json} = runWithJson('regex-(char-in-path', []); expect(json.numTotalTests).toBe(1); expect(json.numPassedTests).toBe(1); diff --git a/e2e/__tests__/require_after_teardown.test.js b/e2e/__tests__/require_after_teardown.test.js index c4652bb3267b..5cbea07fa87f 100644 --- a/e2e/__tests__/require_after_teardown.test.js +++ b/e2e/__tests__/require_after_teardown.test.js @@ -9,7 +9,7 @@ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('prints useful error for requires after test is done', () => { const {stderr} = runJest('require-after-teardown'); diff --git a/e2e/__tests__/require_main.test.js b/e2e/__tests__/require_main.test.js index 3853811e675b..380ce0ded02b 100644 --- a/e2e/__tests__/require_main.test.js +++ b/e2e/__tests__/require_main.test.js @@ -9,7 +9,7 @@ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('provides `require.main` set to test suite module', () => { const {stderr, stdout} = runJest('require-main'); diff --git a/e2e/__tests__/reset_modules.test.js b/e2e/__tests__/reset_modules.test.js index ed4ce5ca5ceb..a28ab4d0cff8 100644 --- a/e2e/__tests__/reset_modules.test.js +++ b/e2e/__tests__/reset_modules.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('jest.resetModules should not error when _isMockFunction is defined but not boolean', () => { const result = runJest('reset_modules'); diff --git a/e2e/__tests__/resolve-get-paths.test.js b/e2e/__tests__/resolve-get-paths.test.js index fd6de995a018..42d576d24f15 100644 --- a/e2e/__tests__/resolve-get-paths.test.js +++ b/e2e/__tests__/resolve-get-paths.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('require.resolve.paths', () => { const {status} = runJest('resolve-get-paths'); diff --git a/e2e/__tests__/resolve-node-module.test.js b/e2e/__tests__/resolve-node-module.test.js index bccde99d538a..b2b900476824 100644 --- a/e2e/__tests__/resolve-node-module.test.js +++ b/e2e/__tests__/resolve-node-module.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('resolve node module', () => { const result = runJest('resolve-node-module'); diff --git a/e2e/__tests__/resolve-with-paths.test.js b/e2e/__tests__/resolve-with-paths.test.js index 40f207a421e6..668c36d7cccd 100644 --- a/e2e/__tests__/resolve-with-paths.test.js +++ b/e2e/__tests__/resolve-with-paths.test.js @@ -8,10 +8,9 @@ */ 'use strict'; -const {resolve} = require('path'); - -const runJest = require('../runJest'); -const {writeFiles, cleanup} = require('../Utils'); +import {resolve} from 'path'; +import runJest from '../runJest'; +import {cleanup, writeFiles} from '../Utils'; const workdirNodeModules = resolve( __dirname, diff --git a/e2e/__tests__/resolve.test.js b/e2e/__tests__/resolve.test.js index 24bc9a436ae6..498808b9a9aa 100644 --- a/e2e/__tests__/resolve.test.js +++ b/e2e/__tests__/resolve.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('resolve platform modules', () => { const result = runJest('resolve'); diff --git a/e2e/__tests__/run_tests_by_path.test.js b/e2e/__tests__/run_tests_by_path.test.js index 2e9b555de4e7..46d202f41f4c 100644 --- a/e2e/__tests__/run_tests_by_path.test.js +++ b/e2e/__tests__/run_tests_by_path.test.js @@ -12,7 +12,7 @@ import runJest from '../runJest'; import os from 'os'; import path from 'path'; -const {cleanup, writeFiles} = require('../Utils'); +import {cleanup, writeFiles} from '../Utils'; const DIR = path.resolve(os.tmpdir(), 'run_tests_by_path_test'); diff --git a/e2e/__tests__/runtime_internal_module_registry.test.js b/e2e/__tests__/runtime_internal_module_registry.test.js index 56f73758fb04..1565e7e7127c 100644 --- a/e2e/__tests__/runtime_internal_module_registry.test.js +++ b/e2e/__tests__/runtime_internal_module_registry.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import {json as runWithJson} from '../runJest'; describe('Runtime Internal Module Registry', () => { // Previously, if Jest required a module (e.g. requiring `mkdirp` from @@ -22,7 +22,7 @@ describe('Runtime Internal Module Registry', () => { // environment, and a "normal" module registry that's used by the actual test // code (and can safely be cleared after every test) it('correctly makes use of internal module registry when requiring modules', () => { - const {json} = runJest.json('runtime-internal-module-registry', []); + const {json} = runWithJson('runtime-internal-module-registry', []); expect(json.numTotalTests).toBe(1); expect(json.numPassedTests).toBe(1); diff --git a/e2e/__tests__/set_immediate.test.js b/e2e/__tests__/set_immediate.test.js index 9e8820562d16..96e022e0cda2 100644 --- a/e2e/__tests__/set_immediate.test.js +++ b/e2e/__tests__/set_immediate.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('setImmediate', () => { const result = runJest('set-immediate', ['--verbose']); diff --git a/e2e/__tests__/setup_test_framework_script_file_cli_config.test.js b/e2e/__tests__/setup_test_framework_script_file_cli_config.test.js index 217709cba81d..4dcd170a08e2 100644 --- a/e2e/__tests__/setup_test_framework_script_file_cli_config.test.js +++ b/e2e/__tests__/setup_test_framework_script_file_cli_config.test.js @@ -8,11 +8,11 @@ */ 'use strict'; -const runJest = require('../runJest'); +import {json as runWithJson} from '../runJest'; describe('--setupTestFrameworkScriptFile setup.js', () => { it('requires a setup file before each file in the suite', () => { - const result = runJest.json('setup-test-framework-script-file-cli-config', [ + const result = runWithJson('setup-test-framework-script-file-cli-config', [ '--setupTestFrameworkScriptFile', './setup1.js', 'test1.test.js', @@ -26,7 +26,7 @@ describe('--setupTestFrameworkScriptFile setup.js', () => { }); it('requires setup files *after* the test runners are required', () => { - const result = runJest.json('setup-test-framework-script-file-cli-config', [ + const result = runWithJson('setup-test-framework-script-file-cli-config', [ '--setupTestFrameworkScriptFile', './setup_hooks_into_runner.js', 'runner_patch.test.js', diff --git a/e2e/__tests__/show_config.test.js b/e2e/__tests__/show_config.test.js index 429b00cac4f2..9e486abb20b8 100644 --- a/e2e/__tests__/show_config.test.js +++ b/e2e/__tests__/show_config.test.js @@ -9,13 +9,14 @@ 'use strict'; -const path = require('path'); -const ConditionalTest = require('../../scripts/ConditionalTest'); -const runJest = require('../runJest'); -const os = require('os'); -const {cleanup, writeFiles} = require('../Utils'); +import path from 'path'; +import runJest from '../runJest'; +import os from 'os'; +import {skipSuiteOnWindows} from '../../scripts/ConditionalTest'; +import {cleanup, writeFiles} from '../Utils'; + +skipSuiteOnWindows(); -ConditionalTest.skipSuiteOnWindows(); const DIR = path.resolve(os.tmpdir(), 'show_config_test'); beforeEach(() => cleanup(DIR)); diff --git a/e2e/__tests__/snapshot.test.js b/e2e/__tests__/snapshot.test.js index 4a63d2a3e94b..3092f6d74ea0 100644 --- a/e2e/__tests__/snapshot.test.js +++ b/e2e/__tests__/snapshot.test.js @@ -8,10 +8,10 @@ */ 'use strict'; -const fs = require('fs'); -const path = require('path'); -const {extractSummary} = require('../Utils'); -const runJest = require('../runJest'); +import fs from 'fs'; +import path from 'path'; +import {extractSummary} from '../Utils'; +import runJest, {json as runWithJson} from '../runJest'; const emptyTest = 'describe("", () => {it("", () => {})})'; const snapshotDir = path.resolve( @@ -100,7 +100,7 @@ describe('Snapshot', () => { afterAll(cleanup); it('stores new snapshots on the first run', () => { - const result = runJest.json('snapshot', ['-w=1', '--ci=false']); + const result = runWithJson('snapshot', ['-w=1', '--ci=false']); const json = result.json; expect(json.numTotalTests).toBe(5); @@ -225,7 +225,7 @@ describe('Snapshot', () => { }); it('does not save snapshots in CI mode by default', () => { - const result = runJest.json('snapshot', ['-w=1', '--ci=true']); + const result = runWithJson('snapshot', ['-w=1', '--ci=true']); expect(result.json.success).toBe(false); expect(result.json.numTotalTests).toBe(9); @@ -238,12 +238,12 @@ describe('Snapshot', () => { }); it('works on subsequent runs without `-u`', () => { - const firstRun = runJest.json('snapshot', ['-w=1', '--ci=false']); + const firstRun = runWithJson('snapshot', ['-w=1', '--ci=false']); // $FlowFixMe dynamic require const content = require(snapshotOfCopy); expect(content).not.toBe(undefined); - const secondRun = runJest.json('snapshot', []); + const secondRun = runWithJson('snapshot', []); expect(firstRun.json.numTotalTests).toBe(9); expect(secondRun.json.numTotalTests).toBe(9); @@ -256,13 +256,13 @@ describe('Snapshot', () => { }); it('deletes the snapshot if the test suite has been removed', () => { - const firstRun = runJest.json('snapshot', ['-w=1', '--ci=false']); + const firstRun = runWithJson('snapshot', ['-w=1', '--ci=false']); fs.unlinkSync(copyOfTestPath); // $FlowFixMe dynamic require const content = require(snapshotOfCopy); expect(content).not.toBe(undefined); - const secondRun = runJest.json('snapshot', ['-w=1', '--ci=false', '-u']); + const secondRun = runWithJson('snapshot', ['-w=1', '--ci=false', '-u']); expect(firstRun.json.numTotalTests).toBe(9); expect(secondRun.json.numTotalTests).toBe(5); @@ -277,10 +277,10 @@ describe('Snapshot', () => { }); it('deletes a snapshot when a test does removes all the snapshots', () => { - const firstRun = runJest.json('snapshot', ['-w=1', '--ci=false']); + const firstRun = runWithJson('snapshot', ['-w=1', '--ci=false']); fs.writeFileSync(copyOfTestPath, emptyTest); - const secondRun = runJest.json('snapshot', ['-w=1', '--ci=false', '-u']); + const secondRun = runWithJson('snapshot', ['-w=1', '--ci=false', '-u']); fs.unlinkSync(copyOfTestPath); expect(firstRun.json.numTotalTests).toBe(9); @@ -296,7 +296,7 @@ describe('Snapshot', () => { }); it('updates the snapshot when a test removes some snapshots', () => { - const firstRun = runJest.json('snapshot', ['-w=1', '--ci=false']); + const firstRun = runWithJson('snapshot', ['-w=1', '--ci=false']); fs.unlinkSync(copyOfTestPath); const beforeRemovingSnapshot = getSnapshotOfCopy(); @@ -307,7 +307,7 @@ describe('Snapshot', () => { '.not.toBe(undefined)', ), ); - const secondRun = runJest.json('snapshot', ['-w=1', '--ci=false', '-u']); + const secondRun = runWithJson('snapshot', ['-w=1', '--ci=false', '-u']); fs.unlinkSync(copyOfTestPath); expect(firstRun.json.numTotalTests).toBe(9); diff --git a/e2e/__tests__/snapshot_resolver.test.js b/e2e/__tests__/snapshot_resolver.test.js index aa1db8ee8f98..d3b4996bdf90 100644 --- a/e2e/__tests__/snapshot_resolver.test.js +++ b/e2e/__tests__/snapshot_resolver.test.js @@ -3,9 +3,9 @@ */ 'use strict'; -const fs = require('fs'); -const path = require('path'); -const runJest = require('../runJest'); +import fs from 'fs'; +import path from 'path'; +import runJest from '../runJest'; const snapshotDir = path.resolve( __dirname, diff --git a/e2e/__tests__/snapshot_serializers.test.js b/e2e/__tests__/snapshot_serializers.test.js index 720f4e004767..0d11d57833e2 100644 --- a/e2e/__tests__/snapshot_serializers.test.js +++ b/e2e/__tests__/snapshot_serializers.test.js @@ -8,16 +8,16 @@ */ 'use strict'; -const path = require('path'); -const {cleanup} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {cleanup} from '../Utils'; +import {json as runWithJson} from '../runJest'; const testDir = path.resolve(__dirname, '../snapshot-serializers'); const snapshotsDir = path.resolve(testDir, '__tests__/__snapshots__'); const snapshotPath = path.resolve(snapshotsDir, 'snapshot.test.js.snap'); const runAndAssert = () => { - const result = runJest.json('snapshot-serializers', [ + const result = runWithJson('snapshot-serializers', [ '-w=1', '--ci=false', '--no-cache', diff --git a/e2e/__tests__/stack_trace.test.js b/e2e/__tests__/stack_trace.test.js index d37b5409eca9..208d2d51c9c1 100644 --- a/e2e/__tests__/stack_trace.test.js +++ b/e2e/__tests__/stack_trace.test.js @@ -8,8 +8,8 @@ */ 'use strict'; -const runJest = require('../runJest'); -const {extractSummary} = require('../Utils'); +import runJest from '../runJest'; +import {extractSummary} from '../Utils'; describe('Stack Trace', () => { it('prints a stack trace for runtime errors', () => { diff --git a/e2e/__tests__/stack_trace_no_captureStackTrace.test.js b/e2e/__tests__/stack_trace_no_captureStackTrace.test.js index 6cd0865f1a09..9e8e906ed48c 100644 --- a/e2e/__tests__/stack_trace_no_captureStackTrace.test.js +++ b/e2e/__tests__/stack_trace_no_captureStackTrace.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; it('prints a usable stack trace even if no Error.captureStackTrace', () => { const {stderr, status} = runJest('stack-trace-no-capture-stack-trace'); diff --git a/e2e/__tests__/stack_trace_source_maps.test.js b/e2e/__tests__/stack_trace_source_maps.test.js index 4d990fb74555..e61258baeff3 100644 --- a/e2e/__tests__/stack_trace_source_maps.test.js +++ b/e2e/__tests__/stack_trace_source_maps.test.js @@ -9,9 +9,9 @@ 'use strict'; -const path = require('path'); -const {run} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {run} from '../Utils'; +import runJest from '../runJest'; it('processes stack traces and code frames with source maps', () => { const dir = path.resolve(__dirname, '../stack-trace-source-maps'); diff --git a/e2e/__tests__/test-todo.test.js b/e2e/__tests__/test-todo.test.js index c430731a8f62..72bbd791cbc7 100644 --- a/e2e/__tests__/test-todo.test.js +++ b/e2e/__tests__/test-todo.test.js @@ -9,9 +9,9 @@ 'use strict'; -const path = require('path'); -const runJest = require('../runJest'); -const {extractSummary} = require('../Utils'); +import path from 'path'; +import runJest from '../runJest'; +import {extractSummary} from '../Utils'; const dir = path.resolve(__dirname, '../test-todo'); test('works with all statuses', () => { diff --git a/e2e/__tests__/test_environment.test.js b/e2e/__tests__/test_environment.test.js index 6341b44b3904..57f14701a13d 100644 --- a/e2e/__tests__/test_environment.test.js +++ b/e2e/__tests__/test_environment.test.js @@ -8,14 +8,14 @@ */ 'use strict'; -const runJest = require('../runJest'); +import {json as runWithJson} from '../runJest'; -const testFixturePackage = require('../test-environment/package.json'); +import testFixturePackage from '../test-environment/package.json'; it('respects testEnvironment docblock', () => { expect(testFixturePackage.jest.testEnvironment).toEqual('node'); - const result = runJest.json('test-environment').json; + const {json: result} = runWithJson('test-environment'); expect(result.success).toBe(true); expect(result.numTotalTests).toBe(1); diff --git a/e2e/__tests__/test_environment_async.test.js b/e2e/__tests__/test_environment_async.test.js index 8decfc1121bc..32be3bdcf488 100644 --- a/e2e/__tests__/test_environment_async.test.js +++ b/e2e/__tests__/test_environment_async.test.js @@ -8,10 +8,10 @@ */ 'use strict'; -const fs = require('fs'); -const os = require('os'); -const runJest = require('../runJest'); -const {cleanup} = require('../Utils'); +import fs from 'fs'; +import os from 'os'; +import runJest from '../runJest'; +import {cleanup} from '../Utils'; const DIR = os.tmpdir() + '/jest-test-environment'; diff --git a/e2e/__tests__/test_failure_exit_code.test.js b/e2e/__tests__/test_failure_exit_code.test.js index 6212f37c1387..4acc0a7b885b 100644 --- a/e2e/__tests__/test_failure_exit_code.test.js +++ b/e2e/__tests__/test_failure_exit_code.test.js @@ -9,10 +9,10 @@ 'use strict'; -const path = require('path'); -const os = require('os'); -const {cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import os from 'os'; +import {cleanup, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(os.tmpdir(), 'test_failure_exit_code_test'); diff --git a/e2e/__tests__/test_in_root.test.js b/e2e/__tests__/test_in_root.test.js index c6ac37ec7b27..c065ed74fba0 100644 --- a/e2e/__tests__/test_in_root.test.js +++ b/e2e/__tests__/test_in_root.test.js @@ -8,11 +8,11 @@ */ 'use strict'; -const path = require('path'); -const runJest = require('../runJest'); +import path from 'path'; +import {json as runWithJson} from '../runJest'; it('runs tests in only test.js and spec.js', () => { - const result = runJest.json('test-in-root').json; + const {json: result} = runWithJson('test-in-root'); expect(result.success).toBe(true); expect(result.numTotalTests).toBe(2); diff --git a/e2e/__tests__/test_name_pattern.test.js b/e2e/__tests__/test_name_pattern.test.js index 2aeaed42df97..43fa3167ab73 100644 --- a/e2e/__tests__/test_name_pattern.test.js +++ b/e2e/__tests__/test_name_pattern.test.js @@ -8,11 +8,11 @@ */ 'use strict'; -const {extractSummary} = require('../Utils'); -const runJest = require('../runJest'); +import {extractSummary} from '../Utils'; +import {json as runWithJson} from '../runJest'; test('testNamePattern', () => { - const {stderr, status} = runJest.json('testNamePattern', [ + const {stderr, status} = runWithJson('testNamePattern', [ '--testNamePattern', 'should match', ]); diff --git a/e2e/__tests__/test_name_pattern_skipped.test.js b/e2e/__tests__/test_name_pattern_skipped.test.js index 2a513283e619..2866dc2b2f93 100644 --- a/e2e/__tests__/test_name_pattern_skipped.test.js +++ b/e2e/__tests__/test_name_pattern_skipped.test.js @@ -8,11 +8,11 @@ */ 'use strict'; -const {extractSummary} = require('../Utils'); -const runJest = require('../runJest'); +import {extractSummary} from '../Utils'; +import {json as runWithJson} from '../runJest'; test('testNamePattern skipped', () => { - const {stderr, status} = runJest.json('testNamePattern_skipped', [ + const {stderr, status} = runWithJson('testNamePattern_skipped', [ '--testNamePattern', 'false', ]); diff --git a/e2e/__tests__/test_path_pattern_reporter_message.test.js b/e2e/__tests__/test_path_pattern_reporter_message.test.js index 6e14e83fc77a..000712201459 100644 --- a/e2e/__tests__/test_path_pattern_reporter_message.test.js +++ b/e2e/__tests__/test_path_pattern_reporter_message.test.js @@ -11,7 +11,7 @@ import runJest from '../runJest'; import os from 'os'; import path from 'path'; -const {cleanup, writeFiles} = require('../Utils'); +import {cleanup, writeFiles} from '../Utils'; const DIR = path.resolve(os.tmpdir(), 'jest_path_pattern_reporter_message'); diff --git a/e2e/__tests__/test_results_processor.test.js b/e2e/__tests__/test_results_processor.test.js index 222eaf567dcd..8f6afd8a0e29 100644 --- a/e2e/__tests__/test_results_processor.test.js +++ b/e2e/__tests__/test_results_processor.test.js @@ -7,15 +7,15 @@ */ 'use strict'; -const runJest = require('../runJest'); +import path from 'path'; +import {json as runWithJson} from '../runJest'; test('testNamePattern', () => { - const path = require('path'); const processorPath = path.resolve( __dirname, '../testResultsProcessor/processor.js', ); - const result = runJest.json('testResultsProcessor', [ + const result = runWithJson('testResultsProcessor', [ '--json', `--testResultsProcessor=${processorPath}`, ]); diff --git a/e2e/__tests__/test_retries.test.js b/e2e/__tests__/test_retries.test.js index 9c2a7347212c..76d66b790362 100644 --- a/e2e/__tests__/test_retries.test.js +++ b/e2e/__tests__/test_retries.test.js @@ -8,13 +8,12 @@ */ 'use strict'; -const fs = require('fs'); -const path = require('path'); -const runJest = require('../runJest'); +import fs from 'fs'; +import path from 'path'; +import runJest from '../runJest'; +import {skipSuiteOnJasmine} from '../../scripts/ConditionalTest'; -const ConditionalTest = require('../../scripts/ConditionalTest'); - -ConditionalTest.skipSuiteOnJasmine(); +skipSuiteOnJasmine(); describe('Test Retries', () => { const outputFileName = 'retries.result.json'; diff --git a/e2e/__tests__/timeouts.test.js b/e2e/__tests__/timeouts.test.js index 29a6bf350bc9..edf3a965f1ae 100644 --- a/e2e/__tests__/timeouts.test.js +++ b/e2e/__tests__/timeouts.test.js @@ -8,9 +8,9 @@ 'use strict'; -const path = require('path'); -const {extractSummary, cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {cleanup, extractSummary, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../timeouts'); diff --git a/e2e/__tests__/timeouts_legacy.test.js b/e2e/__tests__/timeouts_legacy.test.js index 101d1f8f7e66..58a30ade5f73 100644 --- a/e2e/__tests__/timeouts_legacy.test.js +++ b/e2e/__tests__/timeouts_legacy.test.js @@ -8,10 +8,10 @@ 'use strict'; -const path = require('path'); -const {extractSummary, cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); -const ConditionalTest = require('../../scripts/ConditionalTest'); +import path from 'path'; +import {cleanup, extractSummary, writeFiles} from '../Utils'; +import runJest from '../runJest'; +import {skipSuiteOnJestCircus} from '../../scripts/ConditionalTest'; /** * NOTE: This test should be removed once jest-circus is rolled out as a breaking change. @@ -19,7 +19,7 @@ const ConditionalTest = require('../../scripts/ConditionalTest'); const DIR = path.resolve(__dirname, '../timeouts-legacy'); -ConditionalTest.skipSuiteOnJestCircus(); +skipSuiteOnJestCircus(); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); diff --git a/e2e/__tests__/timer_reset_mocks.test.js b/e2e/__tests__/timer_reset_mocks.test.js index 4fd251bafbb2..7e32d85762cb 100644 --- a/e2e/__tests__/timer_reset_mocks.test.js +++ b/e2e/__tests__/timer_reset_mocks.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('run timers after resetAllMocks test', () => { const result = runJest('timer-reset-mocks/after-reset-all-mocks'); diff --git a/e2e/__tests__/timer_use_real_timers.test.js b/e2e/__tests__/timer_use_real_timers.test.js index 53f4d511d452..6a5ea264b75d 100644 --- a/e2e/__tests__/timer_use_real_timers.test.js +++ b/e2e/__tests__/timer_use_real_timers.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('useRealTimers cancels "timers": "fake" for whole test file', () => { const result = runJest('timer-use-real-timers'); diff --git a/e2e/__tests__/to_match_inline_snapshot.test.js b/e2e/__tests__/to_match_inline_snapshot.test.js index 2ffa533f806f..576edd7bcd34 100644 --- a/e2e/__tests__/to_match_inline_snapshot.test.js +++ b/e2e/__tests__/to_match_inline_snapshot.test.js @@ -7,10 +7,10 @@ * @flow */ -const fs = require('fs'); -const path = require('path'); -const {makeTemplate, writeFiles, cleanup} = require('../Utils'); -const runJest = require('../runJest'); +import fs from 'fs'; +import path from 'path'; +import {cleanup, makeTemplate, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../toMatchInlineSnapshot'); const TESTS_DIR = path.resolve(DIR, '__tests__'); diff --git a/e2e/__tests__/to_match_snapshot.test.js b/e2e/__tests__/to_match_snapshot.test.js index b1ae499d0fc2..001bb9e4c6f0 100644 --- a/e2e/__tests__/to_match_snapshot.test.js +++ b/e2e/__tests__/to_match_snapshot.test.js @@ -7,9 +7,9 @@ * @flow */ -const path = require('path'); -const {makeTemplate, writeFiles, cleanup} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {cleanup, makeTemplate, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../toMatchSnapshot'); const TESTS_DIR = path.resolve(DIR, '__tests__'); diff --git a/e2e/__tests__/to_throw_error_matching_inline_snapshot.test.js b/e2e/__tests__/to_throw_error_matching_inline_snapshot.test.js index a50b01dd1dcb..afed44248613 100644 --- a/e2e/__tests__/to_throw_error_matching_inline_snapshot.test.js +++ b/e2e/__tests__/to_throw_error_matching_inline_snapshot.test.js @@ -7,10 +7,10 @@ * @flow */ -const path = require('path'); -const fs = require('fs'); -const {makeTemplate, writeFiles, cleanup} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import fs from 'fs'; +import {cleanup, makeTemplate, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../toThrowErrorMatchingInlineSnapshot'); const TESTS_DIR = path.resolve(DIR, '__tests__'); diff --git a/e2e/__tests__/to_throw_error_matching_snapshot.test.js b/e2e/__tests__/to_throw_error_matching_snapshot.test.js index b42312580ecd..75b2d3dd5740 100644 --- a/e2e/__tests__/to_throw_error_matching_snapshot.test.js +++ b/e2e/__tests__/to_throw_error_matching_snapshot.test.js @@ -7,10 +7,10 @@ * @flow */ -const path = require('path'); -const fs = require('fs'); -const {makeTemplate, writeFiles, cleanup} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import fs from 'fs'; +import {cleanup, makeTemplate, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../toThrowErrorMatchingSnapshot'); const TESTS_DIR = path.resolve(DIR, '__tests__'); diff --git a/e2e/__tests__/transform-linked-modules.test.js b/e2e/__tests__/transform-linked-modules.test.js index fe257ad3eb45..0d9b635f8b78 100644 --- a/e2e/__tests__/transform-linked-modules.test.js +++ b/e2e/__tests__/transform-linked-modules.test.js @@ -2,10 +2,12 @@ 'use strict'; -const runJest = require('../runJest'); +import {json as runWithJson} from '../runJest'; it('should transform linked modules', () => { - const result = runJest.json('transform-linked-modules', ['--no-cache']).json; + const {json: result} = runWithJson('transform-linked-modules', [ + '--no-cache', + ]); expect(result.success).toBe(true); expect(result.numTotalTests).toBe(2); diff --git a/e2e/__tests__/transform.test.js b/e2e/__tests__/transform.test.js index 0f1db011b9ff..78c4b52e0839 100644 --- a/e2e/__tests__/transform.test.js +++ b/e2e/__tests__/transform.test.js @@ -7,16 +7,16 @@ * @flow */ -const path = require('path'); -const { - run, +import path from 'path'; +import { cleanup, + copyDir, createEmptyPackage, linkJestPackage, - copyDir, -} = require('../Utils'); -const runJest = require('../runJest'); -const os = require('os'); + run, +} from '../Utils'; +import runJest, {json as runWithJson} from '../runJest'; +import os from 'os'; describe('babel-jest', () => { const dir = path.resolve(__dirname, '..', 'transform/babel-jest'); @@ -27,7 +27,7 @@ describe('babel-jest', () => { it('runs transpiled code', () => { // --no-cache because babel can cache stuff and result in false green - const {json} = runJest.json(dir, ['--no-cache']); + const {json} = runWithJson(dir, ['--no-cache']); expect(json.success).toBe(true); expect(json.numTotalTests).toBeGreaterThanOrEqual(1); }); @@ -83,7 +83,7 @@ describe('custom transformer', () => { ); it('proprocesses files', () => { - const {json, stderr} = runJest.json(dir, ['--no-cache']); + const {json, stderr} = runWithJson(dir, ['--no-cache']); expect(stderr).toMatch(/FAIL/); expect(stderr).toMatch(/instruments by setting.*global\.__INSTRUMENTED__/); expect(json.numTotalTests).toBe(2); @@ -107,7 +107,7 @@ describe('multiple-transformers', () => { }); it('transforms dependencies using specific transformers', () => { - const {json, stderr} = runJest.json(dir, ['--no-cache']); + const {json, stderr} = runWithJson(dir, ['--no-cache']); expect(stderr).toMatch(/PASS/); expect(json.numTotalTests).toBe(1); @@ -124,7 +124,7 @@ describe('ecmascript-modules-support', () => { it('runs transpiled code', () => { // --no-cache because babel can cache stuff and result in false green - const {json} = runJest.json(dir, ['--no-cache']); + const {json} = runWithJson(dir, ['--no-cache']); expect(json.success).toBe(true); expect(json.numTotalTests).toBeGreaterThanOrEqual(1); }); diff --git a/e2e/__tests__/typescript_coverage.test.js b/e2e/__tests__/typescript_coverage.test.js index 1ba535c33133..dcc0ed13f300 100644 --- a/e2e/__tests__/typescript_coverage.test.js +++ b/e2e/__tests__/typescript_coverage.test.js @@ -7,9 +7,9 @@ * @flow */ -const path = require('path'); -const {run} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import {run} from '../Utils'; +import runJest from '../runJest'; it('instruments and collects coverage for typescript files', () => { const dir = path.resolve(__dirname, '../typescript-coverage'); diff --git a/e2e/__tests__/unexpected-token.test.js b/e2e/__tests__/unexpected-token.test.js index b600b10ccb53..8c5038420b5e 100644 --- a/e2e/__tests__/unexpected-token.test.js +++ b/e2e/__tests__/unexpected-token.test.js @@ -12,7 +12,7 @@ import runJest from '../runJest'; import os from 'os'; import path from 'path'; -const {cleanup, writeFiles} = require('../Utils'); +import {cleanup, writeFiles} from '../Utils'; const DIR = path.resolve(os.tmpdir(), 'unexpected-token'); diff --git a/e2e/__tests__/use_stderr.test.js b/e2e/__tests__/use_stderr.test.js index fc5b14576d6a..2f678b704e39 100644 --- a/e2e/__tests__/use_stderr.test.js +++ b/e2e/__tests__/use_stderr.test.js @@ -12,7 +12,7 @@ import runJest from '../runJest'; import os from 'os'; import path from 'path'; -const {cleanup, writeFiles} = require('../Utils'); +import {cleanup, writeFiles} from '../Utils'; const DIR = path.resolve(os.tmpdir(), 'use_stderr_test'); diff --git a/e2e/__tests__/verbose.test.js b/e2e/__tests__/verbose.test.js index 01feb3ecee04..0f2131cf501c 100644 --- a/e2e/__tests__/verbose.test.js +++ b/e2e/__tests__/verbose.test.js @@ -8,7 +8,7 @@ */ 'use strict'; -const runJest = require('../runJest'); +import runJest from '../runJest'; test('Verbose Reporter', () => { const {status, stderr} = runJest('verbose-reporter'); diff --git a/e2e/__tests__/version.test.js b/e2e/__tests__/version.test.js index e852de8dcf3d..f0ba2751582c 100644 --- a/e2e/__tests__/version.test.js +++ b/e2e/__tests__/version.test.js @@ -9,10 +9,10 @@ 'use strict'; -const path = require('path'); -const os = require('os'); -const {cleanup, writeFiles} = require('../Utils'); -const runJest = require('../runJest'); +import path from 'path'; +import os from 'os'; +import {cleanup, writeFiles} from '../Utils'; +import runJest from '../runJest'; const DIR = path.resolve(os.tmpdir(), 'version_test'); diff --git a/e2e/coverage-report/__tests__/Sum.test.js b/e2e/coverage-report/__tests__/Sum.test.js index 576787764462..96f6ab6fe13a 100644 --- a/e2e/coverage-report/__tests__/Sum.test.js +++ b/e2e/coverage-report/__tests__/Sum.test.js @@ -8,7 +8,7 @@ jest.mock('../SumDependency.js'); // call mock explicitly -const sum = require('../Sum').sum; +const {sum} = require('../Sum'); if (!global.setup) { throw new Error('setup.js was not called.'); diff --git a/e2e/coverage-report/cached-duplicates/a/__tests__/Identical.test.js b/e2e/coverage-report/cached-duplicates/a/__tests__/Identical.test.js index 85ba0905484a..c0e3bdced6ef 100644 --- a/e2e/coverage-report/cached-duplicates/a/__tests__/Identical.test.js +++ b/e2e/coverage-report/cached-duplicates/a/__tests__/Identical.test.js @@ -6,7 +6,7 @@ */ 'use strict'; -const sum = require('../Identical').sum; +const {sum} = require('../Identical'); describe('sum', () => { it('adds numbers', () => { diff --git a/e2e/coverage-report/cached-duplicates/b/__tests__/Identical.test.js b/e2e/coverage-report/cached-duplicates/b/__tests__/Identical.test.js index 85ba0905484a..c0e3bdced6ef 100644 --- a/e2e/coverage-report/cached-duplicates/b/__tests__/Identical.test.js +++ b/e2e/coverage-report/cached-duplicates/b/__tests__/Identical.test.js @@ -6,7 +6,7 @@ */ 'use strict'; -const sum = require('../Identical').sum; +const {sum} = require('../Identical'); describe('sum', () => { it('adds numbers', () => { diff --git a/e2e/coverage-transform-instrumented/Preprocessor.js b/e2e/coverage-transform-instrumented/Preprocessor.js index 244c940e3be2..a708eab7bc3d 100644 --- a/e2e/coverage-transform-instrumented/Preprocessor.js +++ b/e2e/coverage-transform-instrumented/Preprocessor.js @@ -6,8 +6,8 @@ */ const jestPreset = require('babel-preset-jest'); -const babelTransform = require('babel-core').transform; -const babelIstanbulPlugin = require('babel-plugin-istanbul').default; +const {transform: babelTransform} = require('babel-core'); +const {default: babelIstanbulPlugin} = require('babel-plugin-istanbul'); const options = { presets: ['env', jestPreset], diff --git a/e2e/custom-resolver/resolver.js b/e2e/custom-resolver/resolver.js index 4d163d3e25b0..76c871ffdb61 100644 --- a/e2e/custom-resolver/resolver.js +++ b/e2e/custom-resolver/resolver.js @@ -1,4 +1,6 @@ -const defaultResolver = require('jest-resolve/build/default_resolver').default; +const { + default: defaultResolver, +} = require('jest-resolve/build/default_resolver'); const exportedModules = new Map([ ['foo', 'foo'], diff --git a/e2e/detect-open-handles/server.js b/e2e/detect-open-handles/server.js index b3ea1278e835..36737a3f1a43 100644 --- a/e2e/detect-open-handles/server.js +++ b/e2e/detect-open-handles/server.js @@ -1,7 +1,7 @@ 'use strict'; -const http = require('http'); +import {Server} from 'http'; -const app = new http.Server(); +const app = new Server(); app.listen({host: 'localhost', port: 0}); diff --git a/e2e/require-main/loader.js b/e2e/require-main/loader.js index 3a4743d92aed..09433ee01f65 100644 --- a/e2e/require-main/loader.js +++ b/e2e/require-main/loader.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -const path = require('path'); +import path from 'path'; module.exports = function load(moduleId) { return require(path.join(path.dirname(require.main.filename), moduleId)); diff --git a/e2e/runJest.js b/e2e/runJest.js index d8d4a37cdcb1..8c3c2277d02c 100644 --- a/e2e/runJest.js +++ b/e2e/runJest.js @@ -8,13 +8,11 @@ */ 'use strict'; -const path = require('path'); -const fs = require('fs'); -const execa = require('execa'); -const {Writable} = require('readable-stream'); -const {normalizeIcons} = require('./Utils'); - -const {sync: spawnSync} = execa; +import path from 'path'; +import fs from 'fs'; +import execa, {sync as spawnSync} from 'execa'; +import {Writable} from 'readable-stream'; +import {normalizeIcons} from './Utils'; const JEST_PATH = path.resolve(__dirname, '../packages/jest-cli/bin/jest.js'); @@ -26,7 +24,7 @@ type RunJestOptions = { // return the result of the spawned process: // [ 'status', 'signal', 'output', 'pid', 'stdout', 'stderr', // 'envPairs', 'options', 'args', 'file' ] -function runJest( +export default function runJest( dir: string, args?: Array, options: RunJestOptions = {}, @@ -75,9 +73,13 @@ function runJest( // 'success', 'startTime', 'numTotalTests', 'numTotalTestSuites', // 'numRuntimeErrorTestSuites', 'numPassedTests', 'numFailedTests', // 'numPendingTests', 'testResults' -runJest.json = function(dir: string, args?: Array, ...rest) { +export const json = function( + dir: string, + args?: Array, + options: RunJestOptions = {}, +) { args = [...(args || []), '--json']; - const result = runJest(dir, args, ...rest); + const result = runJest(dir, args, options); try { result.json = JSON.parse((result.stdout || '').toString()); } catch (e) { @@ -94,7 +96,7 @@ runJest.json = function(dir: string, args?: Array, ...rest) { }; // Runs `jest` until a given output is achieved, then kills it with `SIGTERM` -runJest.until = async function( +export const until = async function( dir: string, args?: Array, text: string, @@ -155,5 +157,3 @@ runJest.until = async function( return result; }; - -module.exports = runJest; diff --git a/packages/jest-circus/src/__mocks__/test_utils.js b/packages/jest-circus/src/__mocks__/test_utils.js index b26a4c4e9665..39594b009a2b 100644 --- a/packages/jest-circus/src/__mocks__/test_utils.js +++ b/packages/jest-circus/src/__mocks__/test_utils.js @@ -15,7 +15,7 @@ import fs from 'fs'; import os from 'os'; import path from 'path'; import crypto from 'crypto'; -import ConditionalTest from '../../../../scripts/ConditionalTest'; +import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest'; const CIRCUS_PATH = require.resolve('../../build/index'); const CIRCUS_RUN_PATH = require.resolve('../../build/run'); @@ -23,7 +23,7 @@ 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'); -ConditionalTest.skipSuiteOnWindows(); +skipSuiteOnWindows(); export const runTest = (source: string) => { const filename = crypto diff --git a/packages/jest-cli/src/__tests__/SearchSource.test.js b/packages/jest-cli/src/__tests__/SearchSource.test.js index d513df33d2e4..d3d2e5d1e556 100644 --- a/packages/jest-cli/src/__tests__/SearchSource.test.js +++ b/packages/jest-cli/src/__tests__/SearchSource.test.js @@ -9,11 +9,9 @@ 'use strict'; import path from 'path'; +import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest'; jest.setTimeout(15000); - -const ConditionalTest = require('../../../../scripts/ConditionalTest'); - const rootDir = path.resolve(__dirname, 'test_root'); const testRegex = path.sep + '__testtests__' + path.sep; const testMatch = ['**/__testtests__/**/*']; @@ -25,7 +23,7 @@ let findMatchingTests; let normalize; describe('SearchSource', () => { - ConditionalTest.skipSuiteOnWindows(); + skipSuiteOnWindows(); const name = 'SearchSource'; let Runtime; diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index f9a8633275a6..0374851082af 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -8,6 +8,7 @@ 'use strict'; +import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest'; const crypto = require('crypto'); function mockHashContents(contents) { @@ -102,8 +103,6 @@ jest.mock('graceful-fs', () => ({ })); jest.mock('fs', () => require('graceful-fs')); -const ConditionalTest = require('../../../../scripts/ConditionalTest'); - const cacheFilePath = '/cache-file'; const object = data => Object.assign(Object.create(null), data); const createMap = obj => new Map(Object.keys(obj).map(key => [key, obj[key]])); @@ -135,7 +134,7 @@ let mockWorker; let getCacheFilePath; describe('HasteMap', () => { - ConditionalTest.skipSuiteOnWindows(); + skipSuiteOnWindows(); beforeEach(() => { jest.resetModules(); diff --git a/packages/jest-haste-map/src/__tests__/worker.test.js b/packages/jest-haste-map/src/__tests__/worker.test.js index bda4dfa8c99b..7ea4645d0222 100644 --- a/packages/jest-haste-map/src/__tests__/worker.test.js +++ b/packages/jest-haste-map/src/__tests__/worker.test.js @@ -10,7 +10,7 @@ import path from 'path'; import fs from 'graceful-fs'; -import ConditionalTest from '../../../../scripts/ConditionalTest'; +import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest'; import H from '../constants'; @@ -22,7 +22,7 @@ let readFileSync; let readFile; describe('worker', () => { - ConditionalTest.skipSuiteOnWindows(); + skipSuiteOnWindows(); beforeEach(() => { mockFs = { diff --git a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js index d66ac25efec1..b730a6531e64 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js @@ -8,7 +8,7 @@ 'use strict'; -const ConditionalTest = require('../../../../../scripts/ConditionalTest'); +import {skipSuiteOnWindows} from '../../../../../scripts/ConditionalTest'; jest.mock('child_process', () => ({ spawn: jest.fn((cmd, args) => { @@ -76,7 +76,7 @@ let nodeCrawl; let childProcess; describe('node crawler', () => { - ConditionalTest.skipSuiteOnWindows(); + skipSuiteOnWindows(); beforeEach(() => { jest.resetModules(); diff --git a/packages/jest-repl/src/__tests__/jest_repl.test.js b/packages/jest-repl/src/__tests__/jest_repl.test.js index 48628a309e48..3f658ca65bd5 100644 --- a/packages/jest-repl/src/__tests__/jest_repl.test.js +++ b/packages/jest-repl/src/__tests__/jest_repl.test.js @@ -7,14 +7,14 @@ */ 'use strict'; -const {spawnSync} = require('child_process'); -const path = require('path'); -const ConditionalTest = require('../../../../scripts/ConditionalTest'); +import {spawnSync} from 'child_process'; +import path from 'path'; +import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest'; const JEST_RUNTIME = path.resolve(__dirname, '../../bin/jest-repl.js'); describe('Repl', () => { - ConditionalTest.skipSuiteOnWindows(); + skipSuiteOnWindows(); describe('cli', () => { it('runs without errors', () => { diff --git a/packages/jest-runtime/src/__tests__/runtime_cli.test.js b/packages/jest-runtime/src/__tests__/runtime_cli.test.js index 69277e5ae564..25068dec2f67 100644 --- a/packages/jest-runtime/src/__tests__/runtime_cli.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_cli.test.js @@ -8,11 +8,11 @@ */ 'use strict'; -const path = require('path'); -const {sync: spawnSync} = require('execa'); -const ConditionalTest = require('../../../../scripts/ConditionalTest'); +import path from 'path'; +import {sync as spawnSync} from 'execa'; +import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest'; -ConditionalTest.skipSuiteOnWindows(); +skipSuiteOnWindows(); const JEST_RUNTIME = path.resolve(__dirname, '../../bin/jest-runtime.js'); diff --git a/scripts/ConditionalTest.js b/scripts/ConditionalTest.js index d054894bcc17..7d5f2f4c4af2 100644 --- a/scripts/ConditionalTest.js +++ b/scripts/ConditionalTest.js @@ -9,34 +9,30 @@ /* eslint-disable jest/no-focused-tests */ -const ConditionalTest = { - isJestCircusRun() { - return process.env.JEST_CIRCUS === '1'; - }, +export function 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'); - }); - } - }, +export function skipSuiteOnJasmine() { + if (!isJestCircusRun()) { + test.only('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'); - }); - } - }, +export function skipSuiteOnJestCircus() { + if (isJestCircusRun()) { + test.only('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; +export function skipSuiteOnWindows() { + if (process.platform === 'win32') { + test.only('does not work on Windows', () => { + console.warn('[SKIP] Does not work on Windows'); + }); + } +}