From 3d3015814c843eb1dd497d987e8b0b0cf7c309dc Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 14 May 2017 14:47:31 +0200 Subject: [PATCH 1/4] Convert code base to ESM import --- .babelrc | 3 +- .eslintrc.js | 9 ++++- package.json | 1 + packages/babel-jest/src/index.js | 8 ++-- packages/eslint-config-fb-strict/index.js | 1 + packages/jest-changed-files/src/git.js | 4 +- packages/jest-changed-files/src/hg.js | 4 +- packages/jest-circus/src/eventHandler.js | 2 +- packages/jest-circus/src/index.js | 2 +- .../jest-adapter-init.js | 14 +++---- .../legacy_code_todo_rewrite/jest-adapter.js | 2 +- .../legacy_code_todo_rewrite/jest-expect.js | 6 +-- packages/jest-circus/src/run.js | 6 +-- packages/jest-circus/src/state.js | 4 +- packages/jest-cli/src/PatternPrompt.js | 6 +-- packages/jest-cli/src/SearchSource.js | 12 +++--- .../jest-cli/src/TestNamePatternPrompt.js | 14 +++---- .../jest-cli/src/TestPathPatternPrompt.js | 20 +++++----- packages/jest-cli/src/TestRunner.js | 25 ++++++------ packages/jest-cli/src/TestSequencer.js | 5 ++- packages/jest-cli/src/TestWatcher.js | 2 +- packages/jest-cli/src/TestWorker.js | 11 +++--- packages/jest-cli/src/cli/args.js | 2 +- packages/jest-cli/src/cli/getJest.js | 6 +-- packages/jest-cli/src/cli/index.js | 10 ++--- packages/jest-cli/src/cli/runCLI.js | 29 +++++++------- .../jest-cli/src/generateEmptyCoverage.js | 8 ++-- packages/jest-cli/src/jest.js | 11 +++--- packages/jest-cli/src/lib/BufferedConsole.js | 7 ++-- packages/jest-cli/src/lib/Prompt.js | 2 +- packages/jest-cli/src/lib/colorize.js | 2 +- packages/jest-cli/src/lib/createContext.js | 2 +- .../src/lib/formatTestNameByPattern.js | 5 ++- packages/jest-cli/src/lib/getMaxWorkers.js | 2 +- .../jest-cli/src/lib/getTestPathPattern.js | 6 +-- .../src/lib/handleDeprecationWarnings.js | 5 ++- packages/jest-cli/src/lib/highlight.js | 7 ++-- packages/jest-cli/src/lib/isValidPath.js | 2 +- packages/jest-cli/src/lib/logDebugMessages.js | 2 +- .../jest-cli/src/lib/patternModeHelpers.js | 8 ++-- packages/jest-cli/src/lib/updateArgv.js | 2 +- packages/jest-cli/src/preRunMessage.js | 7 ++-- .../jest-cli/src/reporters/BaseReporter.js | 2 +- .../src/reporters/CoverageReporter.js | 19 +++++---- .../jest-cli/src/reporters/CoverageWorker.js | 4 +- .../jest-cli/src/reporters/DefaultReporter.js | 15 ++++--- .../jest-cli/src/reporters/NotifyReporter.js | 8 ++-- packages/jest-cli/src/reporters/Status.js | 4 +- .../jest-cli/src/reporters/SummaryReporter.js | 9 ++--- .../jest-cli/src/reporters/VerboseReporter.js | 6 +-- .../src/reporters/getConsoleOutput.js | 4 +- .../jest-cli/src/reporters/getResultHeader.js | 4 +- packages/jest-cli/src/reporters/utils.js | 6 +-- packages/jest-cli/src/runJest.js | 20 +++++----- packages/jest-cli/src/runTest.js | 13 +++---- packages/jest-cli/src/watch.js | 32 +++++++-------- packages/jest-config/src/constants.js | 2 +- packages/jest-config/src/defaults.js | 8 ++-- packages/jest-config/src/deprecated.js | 3 +- packages/jest-config/src/findConfig.js | 6 +-- packages/jest-config/src/index.js | 8 ++-- packages/jest-config/src/normalize.js | 33 ++++++++-------- .../src/reporterValidationErrors.js | 9 ++--- packages/jest-config/src/setFromArgv.js | 2 +- packages/jest-config/src/utils.js | 8 ++-- packages/jest-config/src/validConfig.js | 4 +- packages/jest-diff/src/constants.js | 2 +- packages/jest-diff/src/diffStrings.js | 17 ++++---- packages/jest-diff/src/index.js | 15 ++++--- packages/jest-editor-support/src/Process.js | 5 ++- packages/jest-editor-support/src/Runner.js | 12 +++--- packages/jest-editor-support/src/Settings.js | 8 ++-- .../jest-editor-support/src/TestReconciler.js | 2 +- packages/jest-editor-support/src/index.js | 15 +++---- .../src/parsers/BabylonParser.js | 9 +++-- packages/jest-environment-jsdom/src/index.js | 4 +- packages/jest-environment-node/src/index.js | 6 +-- packages/jest-haste-map/src/HasteFS.js | 9 ++--- packages/jest-haste-map/src/ModuleMap.js | 3 +- packages/jest-haste-map/src/crawlers/node.js | 9 ++--- .../jest-haste-map/src/crawlers/watchman.js | 6 +-- packages/jest-haste-map/src/getMockName.js | 2 +- packages/jest-haste-map/src/index.js | 39 +++++++++---------- packages/jest-haste-map/src/worker.js | 10 ++--- packages/jest-jasmine2/src/assert-support.js | 6 +-- packages/jest-jasmine2/src/index.js | 8 ++-- packages/jest-jasmine2/src/jasmine/Env.js | 5 ++- packages/jest-jasmine2/src/jasmine/Spec.js | 5 ++- .../jest-jasmine2/src/jasmine/SpyRegistry.js | 7 ++-- packages/jest-jasmine2/src/jasmine/Suite.js | 5 ++- .../jest-jasmine2/src/jasmine/createSpy.js | 5 ++- .../src/jasmine/jasmine-light.js | 16 ++++---- packages/jest-jasmine2/src/jest-expect.js | 7 ++-- packages/jest-jasmine2/src/queueRunner.js | 7 ++-- packages/jest-jasmine2/src/reporter.js | 2 +- .../jest-jasmine2/src/setup-jest-globals.js | 8 ++-- packages/jest-matcher-utils/src/index.js | 8 ++-- .../jest-matchers/src/asymmetric-matchers.js | 4 +- packages/jest-matchers/src/index.js | 14 +++---- packages/jest-matchers/src/matchers.js | 14 +++---- packages/jest-matchers/src/spyMatchers.js | 6 +-- packages/jest-matchers/src/toThrowMatchers.js | 15 +++---- packages/jest-message-util/src/index.js | 8 ++-- packages/jest-phabricator/src/index.js | 2 +- packages/jest-regex-util/src/index.js | 2 +- packages/jest-repl/src/cli/args.js | 2 +- packages/jest-repl/src/cli/index.js | 13 ++++--- packages/jest-repl/src/cli/repl.js | 6 +-- .../jest-resolve-dependencies/src/index.js | 2 +- packages/jest-resolve/src/defaultResolver.js | 4 +- packages/jest-resolve/src/index.js | 8 ++-- .../jest-runtime/src/ScriptTransformer.js | 22 +++++------ .../src/__mocks__/createRuntime.js | 2 +- packages/jest-runtime/src/cli/index.js | 17 ++++---- packages/jest-runtime/src/index.js | 19 +++++---- packages/jest-runtime/src/shouldInstrument.js | 6 +-- packages/jest-snapshot/src/State.js | 6 +-- packages/jest-snapshot/src/index.js | 17 ++++---- packages/jest-snapshot/src/plugins.js | 4 +- packages/jest-snapshot/src/utils.js | 14 +++---- .../src/TypeScriptParser.js | 7 ++-- .../jest-test-typescript-parser/src/index.js | 5 ++- packages/jest-util/src/Console.js | 7 ++-- packages/jest-util/src/FakeTimers.js | 4 +- packages/jest-util/src/NullConsole.js | 2 +- packages/jest-util/src/index.js | 18 ++++----- packages/jest-util/src/validateCLIOptions.js | 8 +--- packages/jest-validate/src/defaultConfig.js | 12 +++--- packages/jest-validate/src/deprecated.js | 2 +- packages/jest-validate/src/errors.js | 6 +-- packages/jest-validate/src/utils.js | 3 +- packages/jest-validate/src/validate.js | 2 +- packages/jest-validate/src/warnings.js | 6 +-- packages/jest/bin/jest.js | 2 +- packages/pretty-format/perf/test.js | 17 ++++---- packages/pretty-format/src/index.js | 2 +- .../pretty-format/src/plugins/ConvertAnsi.js | 2 +- .../pretty-format/src/plugins/HTMLElement.js | 2 +- .../src/plugins/ImmutableList.js | 2 +- .../pretty-format/src/plugins/ImmutableMap.js | 2 +- .../src/plugins/ImmutableOrderedMap.js | 2 +- .../src/plugins/ImmutableOrderedSet.js | 2 +- .../pretty-format/src/plugins/ImmutableSet.js | 2 +- .../src/plugins/ImmutableStack.js | 2 +- .../pretty-format/src/plugins/ReactElement.js | 2 +- .../src/plugins/ReactTestComponent.js | 2 +- yarn.lock | 9 ++++- 147 files changed, 561 insertions(+), 555 deletions(-) diff --git a/.babelrc b/.babelrc index ae49879f0aab..54c65a8e065c 100644 --- a/.babelrc +++ b/.babelrc @@ -5,7 +5,8 @@ "transform-es2015-destructuring", "transform-es2015-parameters", "transform-async-to-generator", - "transform-strict-mode" + "transform-strict-mode", + ["transform-inline-imports-commonjs", {"allowTopLevelThis": true}] ], "retainLines": true } diff --git a/.eslintrc.js b/.eslintrc.js index 254cf0588ac4..845341ed9824 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,9 +19,14 @@ module.exports = { 'flowtype/require-valid-file-annotation': 2, 'max-len': 0, 'no-multiple-empty-lines': 1, - 'import/order': 2, 'import/no-duplicates': 2, - 'import/no-unresolved': [2, { 'ignore': ['^types/'] }] + 'import/no-unresolved': [2, { 'ignore': ['^types/'] }], + // This has to be disabled until all type and module imports are combined + // https://github.com/benmosher/eslint-plugin-import/issues/645 + 'import/order': 0, + // These has to be disabled until the whole code base is converted to ESM + 'import/default': 0, + 'import/named': 0, }, 'plugins': [ 'markdown', diff --git a/package.json b/package.json index 307fa94766c1..f42d56b8bea8 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "babel-plugin-transform-es2015-destructuring": "^6.23.0", "babel-plugin-transform-es2015-parameters": "^6.23.0", "babel-plugin-transform-flow-strip-types": "^6.18.0", + "babel-plugin-transform-inline-imports-commonjs": "^1.2.0", "babel-plugin-transform-runtime": "^6.23.0", "babel-plugin-transform-strict-mode": "^6.24.1", "babel-preset-env": "^1.4.0", diff --git a/packages/babel-jest/src/index.js b/packages/babel-jest/src/index.js index 4a5b295f151d..f56b01ca8cbb 100644 --- a/packages/babel-jest/src/index.js +++ b/packages/babel-jest/src/index.js @@ -11,10 +11,10 @@ import type {Path, ProjectConfig} from 'types/Config'; import type {TransformOptions} from 'types/Transform'; -const crypto = require('crypto'); -const fs = require('fs'); -const path = require('path'); -const jestPreset = require('babel-preset-jest'); +import crypto from 'crypto'; +import fs from 'fs'; +import path from 'path'; +import jestPreset from 'babel-preset-jest'; const BABELRC_FILENAME = '.babelrc'; const BABELRC_JS_FILENAME = '.babelrc.js'; diff --git a/packages/eslint-config-fb-strict/index.js b/packages/eslint-config-fb-strict/index.js index 394220bcb9d1..b803d818043e 100644 --- a/packages/eslint-config-fb-strict/index.js +++ b/packages/eslint-config-fb-strict/index.js @@ -7,6 +7,7 @@ * */ +// Can't be ESModules as this is not transpiled const fbjsConfig = require('eslint-config-fbjs'); const variableNamePattern = String.raw`\s*[a-zA-Z_$][a-zA-Z_$\d]*\s*`; diff --git a/packages/jest-changed-files/src/git.js b/packages/jest-changed-files/src/git.js index de0a4e0bdbd2..a1b1253c1f89 100644 --- a/packages/jest-changed-files/src/git.js +++ b/packages/jest-changed-files/src/git.js @@ -10,8 +10,8 @@ import type {Path} from 'types/Config'; -const path = require('path'); -const childProcess = require('child_process'); +import path from 'path'; +import childProcess from 'child_process'; type Options = {| lastCommit?: boolean, diff --git a/packages/jest-changed-files/src/hg.js b/packages/jest-changed-files/src/hg.js index 290bd92c083e..3d92a22c8df9 100644 --- a/packages/jest-changed-files/src/hg.js +++ b/packages/jest-changed-files/src/hg.js @@ -10,8 +10,8 @@ import type {Path} from 'types/Config'; -const path = require('path'); -const childProcess = require('child_process'); +import path from 'path'; +import childProcess from 'child_process'; const env = Object.assign({}, process.env, { HGPLAIN: 1, diff --git a/packages/jest-circus/src/eventHandler.js b/packages/jest-circus/src/eventHandler.js index b05e3c02d764..789c399a209d 100644 --- a/packages/jest-circus/src/eventHandler.js +++ b/packages/jest-circus/src/eventHandler.js @@ -10,7 +10,7 @@ import type {EventHandler} from '../types'; -const {makeDescribe, getTestDuration, makeTest} = require('./utils'); +import {makeDescribe, getTestDuration, makeTest} from './utils'; // To pass this value from Runtime object to state we need to use global[sym] const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL'); diff --git a/packages/jest-circus/src/index.js b/packages/jest-circus/src/index.js index d26d37ec6ac2..0b2b1e6f911d 100644 --- a/packages/jest-circus/src/index.js +++ b/packages/jest-circus/src/index.js @@ -17,7 +17,7 @@ import type { BlockName, TestName, } from '../types'; -const {dispatch} = require('./state'); +import {dispatch} from './state'; const describe = (blockName: BlockName, blockFn: BlockFn) => _dispatchDescribe(blockFn, blockName); diff --git a/packages/jest-circus/src/legacy_code_todo_rewrite/jest-adapter-init.js b/packages/jest-circus/src/legacy_code_todo_rewrite/jest-adapter-init.js index ab68a238f146..864cd6e29b3d 100644 --- a/packages/jest-circus/src/legacy_code_todo_rewrite/jest-adapter-init.js +++ b/packages/jest-circus/src/legacy_code_todo_rewrite/jest-adapter-init.js @@ -12,13 +12,13 @@ import type {TestResult, Status} from 'types/TestResult'; import type {GlobalConfig, Path, ProjectConfig} from 'types/Config'; import type {Event, TestEntry} from '../../types'; -const {getState, setState} = require('jest-matchers'); -const {formatResultsErrors} = require('jest-message-util'); -const {SnapshotState, addSerializer} = require('jest-snapshot'); -const {addEventHandler, ROOT_DESCRIBE_BLOCK_NAME} = require('../state'); -const {getTestID} = require('../utils'); -const run = require('../run'); -const globals = require('../index'); +import {getState, setState} from 'jest-matchers'; +import {formatResultsErrors} from 'jest-message-util'; +import {SnapshotState, addSerializer} from 'jest-snapshot'; +import {addEventHandler, ROOT_DESCRIBE_BLOCK_NAME} from '../state'; +import {getTestID} from '../utils'; +import run from '../run'; +import globals from '../index'; const initialize = ({ config, diff --git a/packages/jest-circus/src/legacy_code_todo_rewrite/jest-adapter.js b/packages/jest-circus/src/legacy_code_todo_rewrite/jest-adapter.js index 2fb29c19ecf4..6047ff2b6ce4 100644 --- a/packages/jest-circus/src/legacy_code_todo_rewrite/jest-adapter.js +++ b/packages/jest-circus/src/legacy_code_todo_rewrite/jest-adapter.js @@ -14,7 +14,7 @@ import type {TestResult} from 'types/TestResult'; import type Runtime from 'jest-runtime'; const FRAMEWORK_INITIALIZER = require.resolve('./jest-adapter-init'); -const path = require('path'); +import path from 'path'; const jestAdapter = async ( globalConfig: GlobalConfig, diff --git a/packages/jest-circus/src/legacy_code_todo_rewrite/jest-expect.js b/packages/jest-circus/src/legacy_code_todo_rewrite/jest-expect.js index 40a16e3e5823..c42ac5cbf6c5 100644 --- a/packages/jest-circus/src/legacy_code_todo_rewrite/jest-expect.js +++ b/packages/jest-circus/src/legacy_code_todo_rewrite/jest-expect.js @@ -10,13 +10,13 @@ import type {RawMatcherFn} from 'types/Matchers'; -const expect = require('jest-matchers'); +import expect from 'jest-matchers'; -const { +import { addSerializer, toMatchSnapshot, toThrowErrorMatchingSnapshot, -} = require('jest-snapshot'); +} from 'jest-snapshot'; type JasmineMatcher = { (): JasmineMatcher, diff --git a/packages/jest-circus/src/run.js b/packages/jest-circus/src/run.js index 02ef2af6c782..19854ba33038 100644 --- a/packages/jest-circus/src/run.js +++ b/packages/jest-circus/src/run.js @@ -16,13 +16,13 @@ import type { DescribeBlock, } from '../types'; -const {getState, dispatch} = require('./state'); -const { +import {getState, dispatch} from './state'; +import { callAsyncFn, getAllHooksForDescribe, getEachHooksForTest, makeTestResults, -} = require('./utils'); +} from './utils'; const run = async (): Promise => { const {rootDescribeBlock} = getState(); diff --git a/packages/jest-circus/src/state.js b/packages/jest-circus/src/state.js index 67842f6a00cc..350b6e93a7b1 100644 --- a/packages/jest-circus/src/state.js +++ b/packages/jest-circus/src/state.js @@ -10,8 +10,8 @@ import type {Event, State, EventHandler} from '../types'; -const {makeDescribe} = require('./utils'); -const eventHandler = require('./eventHandler'); +import {makeDescribe} from './utils'; +import eventHandler from './eventHandler'; const eventHandlers: Array = [eventHandler]; diff --git a/packages/jest-cli/src/PatternPrompt.js b/packages/jest-cli/src/PatternPrompt.js index cef517aef5d2..19a2a0ced922 100644 --- a/packages/jest-cli/src/PatternPrompt.js +++ b/packages/jest-cli/src/PatternPrompt.js @@ -12,9 +12,9 @@ import type {ScrollOptions} from './lib/scrollList'; -const chalk = require('chalk'); -const ansiEscapes = require('ansi-escapes'); -const Prompt = require('./lib/Prompt'); +import chalk from 'chalk'; +import ansiEscapes from 'ansi-escapes'; +import Prompt from './lib/Prompt'; const usage = (entity: string) => `\n${chalk.bold('Pattern Mode Usage')}\n` + diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index 59593413804a..cadf8989e770 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -13,13 +13,11 @@ import type {Glob, Path} from 'types/Config'; import type {ResolveModuleConfig} from 'types/Resolve'; import type {Test} from 'types/TestRunner'; -const path = require('path'); - -const micromatch = require('micromatch'); - -const DependencyResolver = require('jest-resolve-dependencies'); -const changedFiles = require('jest-changed-files'); -const {escapePathForRegex, replacePathSepForRegex} = require('jest-regex-util'); +import path from 'path'; +import micromatch from 'micromatch'; +import DependencyResolver from 'jest-resolve-dependencies'; +import changedFiles from 'jest-changed-files'; +import {escapePathForRegex, replacePathSepForRegex} from 'jest-regex-util'; type SearchResult = {| noSCM?: boolean, diff --git a/packages/jest-cli/src/TestNamePatternPrompt.js b/packages/jest-cli/src/TestNamePatternPrompt.js index e9d5a9faa8c7..40e2afcfd9a7 100644 --- a/packages/jest-cli/src/TestNamePatternPrompt.js +++ b/packages/jest-cli/src/TestNamePatternPrompt.js @@ -11,11 +11,11 @@ import type {TestResult} from 'types/TestResult'; import type {ScrollOptions} from './lib/scrollList'; -const scroll = require('./lib/scrollList'); -const {getTerminalWidth} = require('./lib/terminalUtils'); -const Prompt = require('./lib/Prompt'); -const formatTestNameByPattern = require('./lib/formatTestNameByPattern'); -const { +import scroll from './lib/scrollList'; +import {getTerminalWidth} from './lib/terminalUtils'; +import Prompt from './lib/Prompt'; +import formatTestNameByPattern from './lib/formatTestNameByPattern'; +import { formatTypeaheadSelection, printMore, printPatternCaret, @@ -23,8 +23,8 @@ const { printRestoredPatternCaret, printStartTyping, printTypeaheadItem, -} = require('./lib/patternModeHelpers'); -const PatternPrompt = require('./PatternPrompt'); +} from './lib/patternModeHelpers'; +import PatternPrompt from './PatternPrompt'; module.exports = class TestNamePatternPrompt extends PatternPrompt { _cachedTestResults: Array; diff --git a/packages/jest-cli/src/TestPathPatternPrompt.js b/packages/jest-cli/src/TestPathPatternPrompt.js index 6207682be337..65137eaa6f71 100644 --- a/packages/jest-cli/src/TestPathPatternPrompt.js +++ b/packages/jest-cli/src/TestPathPatternPrompt.js @@ -14,14 +14,14 @@ import type {ScrollOptions} from './lib/scrollList'; // eslint-disable-next-line import/default import type SearchSource from './SearchSource'; -const chalk = require('chalk'); -const stringLength = require('string-length'); -const scroll = require('./lib/scrollList'); -const {getTerminalWidth} = require('./lib/terminalUtils'); -const highlight = require('./lib/highlight'); -const {trimAndFormatPath} = require('./reporters/utils'); -const Prompt = require('./lib/Prompt'); -const { +import chalk from 'chalk'; +import stringLength from 'string-length'; +import scroll from './lib/scrollList'; +import {getTerminalWidth} from './lib/terminalUtils'; +import highlight from './lib/highlight'; +import {trimAndFormatPath} from './reporters/utils'; +import Prompt from './lib/Prompt'; +import { formatTypeaheadSelection, printMore, printPatternCaret, @@ -29,8 +29,8 @@ const { printRestoredPatternCaret, printStartTyping, printTypeaheadItem, -} = require('./lib/patternModeHelpers'); -const PatternPrompt = require('./PatternPrompt'); +} from './lib/patternModeHelpers'; +import PatternPrompt from './PatternPrompt'; type SearchSources = Array<{| context: Context, diff --git a/packages/jest-cli/src/TestRunner.js b/packages/jest-cli/src/TestRunner.js index cf9359200768..f9e8ed29d9cc 100644 --- a/packages/jest-cli/src/TestRunner.js +++ b/packages/jest-cli/src/TestRunner.js @@ -18,19 +18,18 @@ import type {Context} from 'types/Context'; import type {Reporter, Test} from 'types/TestRunner'; import type {PathPattern} from './SearchSource'; -const {formatExecError} = require('jest-message-util'); -const snapshot = require('jest-snapshot'); -const pify = require('pify'); -const throat = require('throat'); -const workerFarm = require('worker-farm'); - -const DefaultReporter = require('./reporters/DefaultReporter'); -const NotifyReporter = require('./reporters/NotifyReporter'); -const SummaryReporter = require('./reporters/SummaryReporter'); -const VerboseReporter = require('./reporters/VerboseReporter'); -const runTest = require('./runTest'); -const TestWatcher = require('./TestWatcher'); -const ReporterDispatcher = require('./ReporterDispatcher'); +import {formatExecError} from 'jest-message-util'; +import snapshot from 'jest-snapshot'; +import pify from 'pify'; +import throat from 'throat'; +import workerFarm from 'worker-farm'; +import DefaultReporter from './reporters/DefaultReporter'; +import NotifyReporter from './reporters/NotifyReporter'; +import SummaryReporter from './reporters/SummaryReporter'; +import VerboseReporter from './reporters/VerboseReporter'; +import runTest from './runTest'; +import TestWatcher from './TestWatcher'; +import ReporterDispatcher from './ReporterDispatcher'; const SLOW_TEST_TIME = 3000; diff --git a/packages/jest-cli/src/TestSequencer.js b/packages/jest-cli/src/TestSequencer.js index 15e53a8d7537..3b1ea9d9d0e7 100644 --- a/packages/jest-cli/src/TestSequencer.js +++ b/packages/jest-cli/src/TestSequencer.js @@ -12,8 +12,9 @@ import type {AggregatedResult} from 'types/TestResult'; import type {Context} from 'types/Context'; import type {Test} from 'types/TestRunner'; -const fs = require('fs'); -const getCacheFilePath = require('jest-haste-map').getCacheFilePath; +import fs from 'fs'; +// $FlowFixMe: Missing ESM export +import {getCacheFilePath} from 'jest-haste-map'; const FAIL = 0; const SUCCESS = 1; diff --git a/packages/jest-cli/src/TestWatcher.js b/packages/jest-cli/src/TestWatcher.js index 9b6b49781537..380e40ed6489 100644 --- a/packages/jest-cli/src/TestWatcher.js +++ b/packages/jest-cli/src/TestWatcher.js @@ -8,7 +8,7 @@ * @flow */ -const {EventEmitter} = require('events'); +import EventEmitter from 'events'; type State = {| interrupted: boolean, diff --git a/packages/jest-cli/src/TestWorker.js b/packages/jest-cli/src/TestWorker.js index 8a1cdd3b91a0..b59c460d4709 100644 --- a/packages/jest-cli/src/TestWorker.js +++ b/packages/jest-cli/src/TestWorker.js @@ -18,11 +18,11 @@ process.on('uncaughtException', err => { process.exit(1); }); -const {ModuleMap} = require('jest-haste-map'); -const {separateMessageFromStack} = require('jest-message-util'); - -const Runtime = require('jest-runtime'); -const runTest = require('./runTest'); +// $FlowFixMe: Missing ESM export +import {ModuleMap} from 'jest-haste-map'; +import {separateMessageFromStack} from 'jest-message-util'; +import Runtime from 'jest-runtime'; +import runTest from './runTest'; type WorkerData = {| config: ProjectConfig, @@ -59,6 +59,7 @@ const getResolver = (config, rawModuleMap) => { if (rawModuleMap) { return Runtime.createResolver( config, + // $FlowFixMe: Missing ESM export new ModuleMap(rawModuleMap.map, rawModuleMap.mocks), ); } else { diff --git a/packages/jest-cli/src/cli/args.js b/packages/jest-cli/src/cli/args.js index c28aa0d46270..548bea151abe 100644 --- a/packages/jest-cli/src/cli/args.js +++ b/packages/jest-cli/src/cli/args.js @@ -10,7 +10,7 @@ import type {Argv} from 'types/Argv'; -const isCI = require('is-ci'); +import isCI from 'is-ci'; const check = (argv: Argv) => { if (argv.runInBand && argv.hasOwnProperty('maxWorkers')) { diff --git a/packages/jest-cli/src/cli/getJest.js b/packages/jest-cli/src/cli/getJest.js index c4770abada53..5562a3d968d9 100644 --- a/packages/jest-cli/src/cli/getJest.js +++ b/packages/jest-cli/src/cli/getJest.js @@ -10,9 +10,9 @@ import type {Path} from 'types/Config'; -const path = require('path'); -const chalk = require('chalk'); -const fs = require('graceful-fs'); +import path from 'path'; +import chalk from 'chalk'; +import fs from 'graceful-fs'; function getJest(packageRoot: Path) { const packageJSONPath = path.join(packageRoot, 'package.json'); diff --git a/packages/jest-cli/src/cli/index.js b/packages/jest-cli/src/cli/index.js index c746747a3240..1b5d4d718ccc 100644 --- a/packages/jest-cli/src/cli/index.js +++ b/packages/jest-cli/src/cli/index.js @@ -11,11 +11,11 @@ import type {Path} from 'types/Config'; import type {Argv} from 'types/Argv'; -const {validateCLIOptions} = require('jest-util'); -const yargs = require('yargs'); -const args = require('./args'); -const getJest = require('./getJest'); -const runCLI = require('./runCLI'); +import {validateCLIOptions} from 'jest-util'; +import yargs from 'yargs'; +import args from './args'; +import getJest from './getJest'; +import runCLI from './runCLI'; function run(argv?: Argv, project?: Path) { argv = yargs(argv || process.argv.slice(2)) diff --git a/packages/jest-cli/src/cli/runCLI.js b/packages/jest-cli/src/cli/runCLI.js index 62d88431bdaa..62e93ef97d90 100644 --- a/packages/jest-cli/src/cli/runCLI.js +++ b/packages/jest-cli/src/cli/runCLI.js @@ -12,22 +12,19 @@ import type {Argv} from 'types/Argv'; import type {AggregatedResult} from 'types/TestResult'; import type {Path} from 'types/Config'; -const Runtime = require('jest-runtime'); - -const {Console, clearLine} = require('jest-util'); -const {createDirectory} = require('jest-util'); -const {readConfig} = require('jest-config'); -const chalk = require('chalk'); -const createContext = require('../lib/createContext'); -const getMaxWorkers = require('../lib/getMaxWorkers'); -const handleDeprecationWarnings = require('../lib/handleDeprecationWarnings'); -const logDebugMessages = require('../lib/logDebugMessages'); -const preRunMessage = require('../preRunMessage'); -const runJest = require('../runJest'); -const TestWatcher = require('../TestWatcher'); -const watch = require('../watch'); - -const VERSION = require('../../package.json').version; +import Runtime from 'jest-runtime'; +import {Console, clearLine, createDirectory} from 'jest-util'; +import {readConfig} from 'jest-config'; +import chalk from 'chalk'; +import createContext from '../lib/createContext'; +import getMaxWorkers from '../lib/getMaxWorkers'; +import handleDeprecationWarnings from '../lib/handleDeprecationWarnings'; +import logDebugMessages from '../lib/logDebugMessages'; +import preRunMessage from '../preRunMessage'; +import runJest from '../runJest'; +import TestWatcher from '../TestWatcher'; +import watch from '../watch'; +import {version as VERSION} from '../../package.json'; module.exports = async ( argv: Argv, diff --git a/packages/jest-cli/src/generateEmptyCoverage.js b/packages/jest-cli/src/generateEmptyCoverage.js index 9312009e4d9b..993bf29a916c 100644 --- a/packages/jest-cli/src/generateEmptyCoverage.js +++ b/packages/jest-cli/src/generateEmptyCoverage.js @@ -10,9 +10,9 @@ import type {GlobalConfig, ProjectConfig, Path} from 'types/Config'; -const IstanbulInstrument = require('istanbul-lib-instrument'); - -const {ScriptTransformer, shouldInstrument} = require('jest-runtime'); +import {createInstrumenter} from 'istanbul-lib-instrument'; +// $FlowFixMe: Missing ESM export +import {ScriptTransformer, shouldInstrument} from 'jest-runtime'; module.exports = function( source: string, @@ -35,7 +35,7 @@ module.exports = function( false, globalConfig.mapCoverage, ); - const instrumenter = IstanbulInstrument.createInstrumenter(); + const instrumenter = createInstrumenter(); instrumenter.instrumentSync(transformResult.code, filename); return { coverage: instrumenter.fileCoverage, diff --git a/packages/jest-cli/src/jest.js b/packages/jest-cli/src/jest.js index 30a77aab8ce0..bced97273c0a 100644 --- a/packages/jest-cli/src/jest.js +++ b/packages/jest-cli/src/jest.js @@ -8,13 +8,12 @@ * @flow */ -const VERSION = require('../package.json').version; +import {version as VERSION} from '../package.json'; -const SearchSource = require('./SearchSource'); -const TestRunner = require('./TestRunner'); -const TestWatcher = require('./TestWatcher'); - -const {run, runCLI} = require('./cli'); +import SearchSource from './SearchSource'; +import TestRunner from './TestRunner'; +import TestWatcher from './TestWatcher'; +import {run, runCLI} from './cli'; module.exports = { SearchSource, diff --git a/packages/jest-cli/src/lib/BufferedConsole.js b/packages/jest-cli/src/lib/BufferedConsole.js index 44152ebc3c47..cc601f724cc6 100644 --- a/packages/jest-cli/src/lib/BufferedConsole.js +++ b/packages/jest-cli/src/lib/BufferedConsole.js @@ -10,10 +10,9 @@ import type {ConsoleBuffer, LogMessage, LogType} from 'types/Console'; -const {Console} = require('console'); - -const {format} = require('util'); -const callsites = require('callsites'); +import {Console} from 'console'; +import {format} from 'util'; +import callsites from 'callsites'; class BufferedConsole extends Console { _buffer: ConsoleBuffer; diff --git a/packages/jest-cli/src/lib/Prompt.js b/packages/jest-cli/src/lib/Prompt.js index 6065f5f1dccf..d1e48f415863 100644 --- a/packages/jest-cli/src/lib/Prompt.js +++ b/packages/jest-cli/src/lib/Prompt.js @@ -10,7 +10,7 @@ import type {ScrollOptions} from './scrollList'; -const {KEYS} = require('../constants'); +import {KEYS} from '../constants'; class Prompt { _entering: boolean; diff --git a/packages/jest-cli/src/lib/colorize.js b/packages/jest-cli/src/lib/colorize.js index 74d2c5222721..c5afc67aca10 100644 --- a/packages/jest-cli/src/lib/colorize.js +++ b/packages/jest-cli/src/lib/colorize.js @@ -8,7 +8,7 @@ * @flow */ -const chalk = require('chalk'); +import chalk from 'chalk'; module.exports = (str: string, start: number, end: number) => chalk.dim(str.slice(0, start)) + diff --git a/packages/jest-cli/src/lib/createContext.js b/packages/jest-cli/src/lib/createContext.js index 0a2ef2f541d2..f87414537905 100644 --- a/packages/jest-cli/src/lib/createContext.js +++ b/packages/jest-cli/src/lib/createContext.js @@ -12,7 +12,7 @@ import type {ProjectConfig} from 'types/Config'; import type {Context} from 'types/Context'; import type {HasteMap} from 'types/HasteMap'; -const Runtime = require('jest-runtime'); +import Runtime from 'jest-runtime'; module.exports = ( config: ProjectConfig, diff --git a/packages/jest-cli/src/lib/formatTestNameByPattern.js b/packages/jest-cli/src/lib/formatTestNameByPattern.js index ff82293eb9e2..1d2d8bddf312 100644 --- a/packages/jest-cli/src/lib/formatTestNameByPattern.js +++ b/packages/jest-cli/src/lib/formatTestNameByPattern.js @@ -8,8 +8,9 @@ * @flow */ -const chalk = require('chalk'); -const colorize = require('./colorize'); +import chalk from 'chalk'; + +import colorize from './colorize'; const DOTS = '...'; const ENTER = '⏎'; diff --git a/packages/jest-cli/src/lib/getMaxWorkers.js b/packages/jest-cli/src/lib/getMaxWorkers.js index 7e7d569b4e1d..617077f5618b 100644 --- a/packages/jest-cli/src/lib/getMaxWorkers.js +++ b/packages/jest-cli/src/lib/getMaxWorkers.js @@ -10,7 +10,7 @@ import type {Argv} from 'types/Argv'; -const os = require('os'); +import os from 'os'; const getMaxWorkers = (argv: Argv): number => { if (argv.runInBand) { diff --git a/packages/jest-cli/src/lib/getTestPathPattern.js b/packages/jest-cli/src/lib/getTestPathPattern.js index ec2d326d70bf..6463e726f66d 100644 --- a/packages/jest-cli/src/lib/getTestPathPattern.js +++ b/packages/jest-cli/src/lib/getTestPathPattern.js @@ -11,9 +11,9 @@ import type {Argv} from 'types/Argv'; import type {PathPattern} from '../SearchSource'; -const {clearLine} = require('jest-util'); -const chalk = require('chalk'); -const validatePattern = require('./validatePattern'); +import {clearLine} from 'jest-util'; +import chalk from 'chalk'; +import validatePattern from './validatePattern'; const DEFAULT_PATTERN_INFO = { input: '', diff --git a/packages/jest-cli/src/lib/handleDeprecationWarnings.js b/packages/jest-cli/src/lib/handleDeprecationWarnings.js index 86adebf39b51..32dcc01f4ab1 100644 --- a/packages/jest-cli/src/lib/handleDeprecationWarnings.js +++ b/packages/jest-cli/src/lib/handleDeprecationWarnings.js @@ -8,8 +8,9 @@ * @flow */ -const chalk = require('chalk'); -const {KEYS} = require('../constants'); +import chalk from 'chalk'; + +import {KEYS} from '../constants'; module.exports = ( pipe: stream$Writable | tty$WriteStream, diff --git a/packages/jest-cli/src/lib/highlight.js b/packages/jest-cli/src/lib/highlight.js index 542133a52bee..d9374821f902 100644 --- a/packages/jest-cli/src/lib/highlight.js +++ b/packages/jest-cli/src/lib/highlight.js @@ -8,9 +8,10 @@ * @flow */ -const path = require('path'); -const chalk = require('chalk'); -const colorize = require('./colorize'); +import path from 'path'; + +import chalk from 'chalk'; +import colorize from './colorize'; const trim = '...'; const relativePathHead = './'; diff --git a/packages/jest-cli/src/lib/isValidPath.js b/packages/jest-cli/src/lib/isValidPath.js index 1d5b30bf1283..cad082e6727b 100644 --- a/packages/jest-cli/src/lib/isValidPath.js +++ b/packages/jest-cli/src/lib/isValidPath.js @@ -10,7 +10,7 @@ import type {GlobalConfig, ProjectConfig} from 'types/Config'; -const path = require('path'); +import path from 'path'; const SNAPSHOT_EXTENSION = 'snap'; diff --git a/packages/jest-cli/src/lib/logDebugMessages.js b/packages/jest-cli/src/lib/logDebugMessages.js index 530c43bd4593..ab06e8ebee32 100644 --- a/packages/jest-cli/src/lib/logDebugMessages.js +++ b/packages/jest-cli/src/lib/logDebugMessages.js @@ -11,7 +11,7 @@ import type {GlobalConfig, ProjectConfig} from 'types/Config'; import type {TestFramework} from 'types/TestRunner'; -const VERSION = require('../../package.json').version; +import {version as VERSION} from '../../package.json'; const logDebugMessages = ( globalConfig: GlobalConfig, diff --git a/packages/jest-cli/src/lib/patternModeHelpers.js b/packages/jest-cli/src/lib/patternModeHelpers.js index ed0eb2334874..82de807d6c4a 100644 --- a/packages/jest-cli/src/lib/patternModeHelpers.js +++ b/packages/jest-cli/src/lib/patternModeHelpers.js @@ -10,10 +10,10 @@ 'use strict'; -const chalk = require('chalk'); -const ansiEscapes = require('ansi-escapes'); -const stringLength = require('string-length'); -const Prompt = require('./Prompt'); +import chalk from 'chalk'; +import ansiEscapes from 'ansi-escapes'; +import stringLength from 'string-length'; +import Prompt from './Prompt'; const pluralize = (count: number, text: string) => count === 1 ? text : text + 's'; diff --git a/packages/jest-cli/src/lib/updateArgv.js b/packages/jest-cli/src/lib/updateArgv.js index 73e02284b7c5..969887c3d89e 100644 --- a/packages/jest-cli/src/lib/updateArgv.js +++ b/packages/jest-cli/src/lib/updateArgv.js @@ -10,7 +10,7 @@ import type {Argv} from 'types/Argv'; -const getTestPathPattern = require('./getTestPathPattern'); +import getTestPathPattern from './getTestPathPattern'; type Options = {| testNamePattern?: string, diff --git a/packages/jest-cli/src/preRunMessage.js b/packages/jest-cli/src/preRunMessage.js index 6cbc145f4e63..a4155c193b52 100644 --- a/packages/jest-cli/src/preRunMessage.js +++ b/packages/jest-cli/src/preRunMessage.js @@ -8,9 +8,10 @@ * @flow */ -const {clearLine} = require('jest-util'); -const chalk = require('chalk'); -const isCI = require('is-ci'); +import {clearLine} from 'jest-util'; + +import chalk from 'chalk'; +import isCI from 'is-ci'; const print = (stream: stream$Writable | tty$WriteStream) => { if (process.stdout.isTTY && !isCI) { diff --git a/packages/jest-cli/src/reporters/BaseReporter.js b/packages/jest-cli/src/reporters/BaseReporter.js index e1e3b8d36b4f..27c14dd8452e 100644 --- a/packages/jest-cli/src/reporters/BaseReporter.js +++ b/packages/jest-cli/src/reporters/BaseReporter.js @@ -13,7 +13,7 @@ import type {Context} from 'types/Context'; import type {Test} from 'types/TestRunner'; import type {ReporterOnStartOptions} from 'types/Reporters'; -const preRunMessage = require('../preRunMessage'); +import preRunMessage from '../preRunMessage'; class BaseReporter { _error: ?Error; diff --git a/packages/jest-cli/src/reporters/CoverageReporter.js b/packages/jest-cli/src/reporters/CoverageReporter.js index e10b34751589..a2c827866526 100644 --- a/packages/jest-cli/src/reporters/CoverageReporter.js +++ b/packages/jest-cli/src/reporters/CoverageReporter.js @@ -22,16 +22,15 @@ type CoverageReporterOptions = { maxWorkers: number, }; -const {clearLine} = require('jest-util'); -const {createReporter} = require('istanbul-api'); -const chalk = require('chalk'); -const isCI = require('is-ci'); -const istanbulCoverage = require('istanbul-lib-coverage'); -const libSourceMaps = require('istanbul-lib-source-maps'); -const pify = require('pify'); -const workerFarm = require('worker-farm'); - -const BaseReporter = require('./BaseReporter'); +import {clearLine} from 'jest-util'; +import {createReporter} from 'istanbul-api'; +import chalk from 'chalk'; +import isCI from 'is-ci'; +import istanbulCoverage from 'istanbul-lib-coverage'; +import libSourceMaps from 'istanbul-lib-source-maps'; +import pify from 'pify'; +import workerFarm from 'worker-farm'; +import BaseReporter from './BaseReporter'; const FAIL_COLOR = chalk.bold.red; const RUNNING_TEST_COLOR = chalk.bold.dim; diff --git a/packages/jest-cli/src/reporters/CoverageWorker.js b/packages/jest-cli/src/reporters/CoverageWorker.js index dbffe28a2e63..0f92532a887b 100644 --- a/packages/jest-cli/src/reporters/CoverageWorker.js +++ b/packages/jest-cli/src/reporters/CoverageWorker.js @@ -11,8 +11,8 @@ import type {GlobalConfig, ProjectConfig, Path} from 'types/Config'; import type {SerializableError} from 'types/TestResult'; -const fs = require('fs'); -const generateEmptyCoverage = require('../generateEmptyCoverage'); +import fs from 'fs'; +import generateEmptyCoverage from '../generateEmptyCoverage'; type CoverageWorkerData = {| globalConfig: GlobalConfig, diff --git a/packages/jest-cli/src/reporters/DefaultReporter.js b/packages/jest-cli/src/reporters/DefaultReporter.js index 9e8706d1fed1..ee713c92ab01 100644 --- a/packages/jest-cli/src/reporters/DefaultReporter.js +++ b/packages/jest-cli/src/reporters/DefaultReporter.js @@ -15,14 +15,13 @@ import type {GlobalConfig, Path, ProjectConfig} from 'types/Config'; import type {Test} from 'types/TestRunner'; import type {ReporterOnStartOptions} from 'types/Reporters'; -const {clearLine} = require('jest-util'); -const chalk = require('chalk'); -const isCI = require('is-ci'); - -const BaseReporter = require('./BaseReporter'); -const Status = require('./Status'); -const getConsoleOutput = require('./getConsoleOutput'); -const getResultHeader = require('./getResultHeader'); +import {clearLine} from 'jest-util'; +import chalk from 'chalk'; +import isCI from 'is-ci'; +import BaseReporter from './BaseReporter'; +import Status from './Status'; +import getConsoleOutput from './getConsoleOutput'; +import getResultHeader from './getResultHeader'; type write = (chunk: string, enc?: any, cb?: () => void) => boolean; diff --git a/packages/jest-cli/src/reporters/NotifyReporter.js b/packages/jest-cli/src/reporters/NotifyReporter.js index f3ed6db5bb3e..5deb6603327b 100644 --- a/packages/jest-cli/src/reporters/NotifyReporter.js +++ b/packages/jest-cli/src/reporters/NotifyReporter.js @@ -11,10 +11,10 @@ import type {AggregatedResult} from 'types/TestResult'; import type {Context} from 'types/Context'; -const path = require('path'); -const util = require('util'); -const notifier = require('node-notifier'); -const BaseReporter = require('./BaseReporter'); +import path from 'path'; +import util from 'util'; +import notifier from 'node-notifier'; +import BaseReporter from './BaseReporter'; const isDarwin = process.platform === 'darwin'; diff --git a/packages/jest-cli/src/reporters/Status.js b/packages/jest-cli/src/reporters/Status.js index e7713a10cd0f..428a8b35e77f 100644 --- a/packages/jest-cli/src/reporters/Status.js +++ b/packages/jest-cli/src/reporters/Status.js @@ -12,8 +12,8 @@ import type {AggregatedResult, TestResult} from 'types/TestResult'; import type {ProjectConfig, Path} from 'types/Config'; import type {ReporterOnStartOptions} from 'types/Reporters'; -const chalk = require('chalk'); -const {getSummary, trimAndFormatPath, wrapAnsiString} = require('./utils'); +import chalk from 'chalk'; +import {getSummary, trimAndFormatPath, wrapAnsiString} from './utils'; const RUNNING_TEXT = ' RUNS '; const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' '; diff --git a/packages/jest-cli/src/reporters/SummaryReporter.js b/packages/jest-cli/src/reporters/SummaryReporter.js index f5d48ee114f7..b6a3224ecd98 100644 --- a/packages/jest-cli/src/reporters/SummaryReporter.js +++ b/packages/jest-cli/src/reporters/SummaryReporter.js @@ -20,11 +20,10 @@ type SummaryReporterOptions = {| testPathPattern: string, |}; -const chalk = require('chalk'); - -const BaseReporter = require('./BaseReporter'); -const {getSummary, pluralize} = require('./utils'); -const getResultHeader = require('./getResultHeader'); +import chalk from 'chalk'; +import BaseReporter from './BaseReporter'; +import {getSummary, pluralize} from './utils'; +import getResultHeader from './getResultHeader'; const ARROW = ' \u203A '; const FAIL_COLOR = chalk.bold.red; diff --git a/packages/jest-cli/src/reporters/VerboseReporter.js b/packages/jest-cli/src/reporters/VerboseReporter.js index 6bba136be48b..0b27d48c8454 100644 --- a/packages/jest-cli/src/reporters/VerboseReporter.js +++ b/packages/jest-cli/src/reporters/VerboseReporter.js @@ -17,9 +17,9 @@ import type { } from 'types/TestResult'; import type {Test} from 'types/TestRunner'; -const chalk = require('chalk'); -const {ICONS} = require('../constants'); -const DefaultReporter = require('./DefaultReporter'); +import chalk from 'chalk'; +import {ICONS} from '../constants'; +import DefaultReporter from './DefaultReporter'; class VerboseReporter extends DefaultReporter { _globalConfig: GlobalConfig; diff --git a/packages/jest-cli/src/reporters/getConsoleOutput.js b/packages/jest-cli/src/reporters/getConsoleOutput.js index e3895e57d385..1177d2a7baf3 100644 --- a/packages/jest-cli/src/reporters/getConsoleOutput.js +++ b/packages/jest-cli/src/reporters/getConsoleOutput.js @@ -10,8 +10,8 @@ import type {ConsoleBuffer} from 'types/Console'; -const path = require('path'); -const chalk = require('chalk'); +import path from 'path'; +import chalk from 'chalk'; module.exports = (root: string, verbose: boolean, buffer: ConsoleBuffer) => { const TITLE_INDENT = verbose ? ' ' : ' '; diff --git a/packages/jest-cli/src/reporters/getResultHeader.js b/packages/jest-cli/src/reporters/getResultHeader.js index cdcb32ad7216..949a8d2e7032 100644 --- a/packages/jest-cli/src/reporters/getResultHeader.js +++ b/packages/jest-cli/src/reporters/getResultHeader.js @@ -11,8 +11,8 @@ import type {Path} from 'types/Config'; import type {TestResult} from 'types/TestResult'; -const chalk = require('chalk'); -const {formatTestPath} = require('./utils'); +import chalk from 'chalk'; +import {formatTestPath} from './utils'; const LONG_TEST_COLOR = chalk.reset.bold.bgRed; // Explicitly reset for these messages since they can get written out in the diff --git a/packages/jest-cli/src/reporters/utils.js b/packages/jest-cli/src/reporters/utils.js index 425c568e78c6..37a4abebebe0 100644 --- a/packages/jest-cli/src/reporters/utils.js +++ b/packages/jest-cli/src/reporters/utils.js @@ -11,9 +11,9 @@ import type {Path} from 'types/Config'; import type {AggregatedResult} from 'types/TestResult'; -const path = require('path'); -const chalk = require('chalk'); -const slash = require('slash'); +import path from 'path'; +import chalk from 'chalk'; +import slash from 'slash'; type SummaryOptions = {| estimatedTime?: number, diff --git a/packages/jest-cli/src/runJest.js b/packages/jest-cli/src/runJest.js index 172275f5be9f..1d656b817fa6 100644 --- a/packages/jest-cli/src/runJest.js +++ b/packages/jest-cli/src/runJest.js @@ -14,16 +14,16 @@ import type {GlobalConfig} from 'types/Config'; import type {AggregatedResult} from 'types/TestResult'; import type TestWatcher from './TestWatcher'; -const path = require('path'); -const {Console, formatTestResults} = require('jest-util'); -const chalk = require('chalk'); -const fs = require('graceful-fs'); -const getMaxWorkers = require('./lib/getMaxWorkers'); -const getTestPathPattern = require('./lib/getTestPathPattern'); -const SearchSource = require('./SearchSource'); -const updateArgv = require('./lib/updateArgv'); -const TestRunner = require('./TestRunner'); -const TestSequencer = require('./TestSequencer'); +import path from 'path'; +import {Console, formatTestResults} from 'jest-util'; +import chalk from 'chalk'; +import fs from 'graceful-fs'; +import getMaxWorkers from './lib/getMaxWorkers'; +import getTestPathPattern from './lib/getTestPathPattern'; +import SearchSource from './SearchSource'; +import updateArgv from './lib/updateArgv'; +import TestRunner from './TestRunner'; +import TestSequencer from './TestSequencer'; const setConfig = (contexts, newConfig) => contexts.forEach( diff --git a/packages/jest-cli/src/runTest.js b/packages/jest-cli/src/runTest.js index 11b35b3d9d5c..a7f47d1a8af4 100644 --- a/packages/jest-cli/src/runTest.js +++ b/packages/jest-cli/src/runTest.js @@ -15,13 +15,12 @@ import type {TestFramework} from 'types/TestRunner'; import type {TestResult} from 'types/TestResult'; import type RuntimeClass from 'jest-runtime'; -const fs = require('fs'); -const {Console, NullConsole, setGlobal} = require('jest-util'); -const {getTestEnvironment} = require('jest-config'); -const docblock = require('jest-docblock'); - -const BufferedConsole = require('./lib/BufferedConsole'); -const getConsoleOutput = require('./reporters/getConsoleOutput'); +import fs from 'fs'; +import {Console, NullConsole, setGlobal} from 'jest-util'; +import {getTestEnvironment} from 'jest-config'; +import docblock from 'jest-docblock'; +import BufferedConsole from './lib/BufferedConsole'; +import getConsoleOutput from './reporters/getConsoleOutput'; function runTest( path: Path, diff --git a/packages/jest-cli/src/watch.js b/packages/jest-cli/src/watch.js index 98ab73a53905..26a9156e78b6 100644 --- a/packages/jest-cli/src/watch.js +++ b/packages/jest-cli/src/watch.js @@ -12,22 +12,22 @@ import type {Argv} from 'types/Argv'; import type {GlobalConfig} from 'types/Config'; import type {Context} from 'types/Context'; -const ansiEscapes = require('ansi-escapes'); -const chalk = require('chalk'); -const {replacePathSepForRegex} = require('jest-regex-util'); -const HasteMap = require('jest-haste-map'); -const isCI = require('is-ci'); -const isValidPath = require('./lib/isValidPath'); -const preRunMessage = require('./preRunMessage'); -const createContext = require('./lib/createContext'); -const runJest = require('./runJest'); -const updateArgv = require('./lib/updateArgv'); -const SearchSource = require('./SearchSource'); -const TestWatcher = require('./TestWatcher'); -const Prompt = require('./lib/Prompt'); -const TestPathPatternPrompt = require('./TestPathPatternPrompt'); -const TestNamePatternPrompt = require('./TestNamePatternPrompt'); -const {KEYS, CLEAR} = require('./constants'); +import ansiEscapes from 'ansi-escapes'; +import chalk from 'chalk'; +import {replacePathSepForRegex} from 'jest-regex-util'; +import HasteMap from 'jest-haste-map'; +import isCI from 'is-ci'; +import isValidPath from './lib/isValidPath'; +import preRunMessage from './preRunMessage'; +import createContext from './lib/createContext'; +import runJest from './runJest'; +import updateArgv from './lib/updateArgv'; +import SearchSource from './SearchSource'; +import TestWatcher from './TestWatcher'; +import Prompt from './lib/Prompt'; +import TestPathPatternPrompt from './TestPathPatternPrompt'; +import TestNamePatternPrompt from './TestNamePatternPrompt'; +import {KEYS, CLEAR} from './constants'; const isInteractive = process.stdout.isTTY && !isCI; let hasExitListener = false; diff --git a/packages/jest-config/src/constants.js b/packages/jest-config/src/constants.js index f9d13cf05a88..3579cd7299d3 100644 --- a/packages/jest-config/src/constants.js +++ b/packages/jest-config/src/constants.js @@ -8,7 +8,7 @@ * @flow */ -const path = require('path'); +import path from 'path'; exports.NODE_MODULES = path.sep + 'node_modules' + path.sep; exports.DEFAULT_JS_PATTERN = '^.+\\.jsx?$'; diff --git a/packages/jest-config/src/defaults.js b/packages/jest-config/src/defaults.js index dc6f528e9e8a..5e29c41fda12 100644 --- a/packages/jest-config/src/defaults.js +++ b/packages/jest-config/src/defaults.js @@ -10,10 +10,10 @@ import type {DefaultOptions} from 'types/Config'; -const os = require('os'); -const path = require('path'); -const {replacePathSepForRegex} = require('jest-regex-util'); -const constants = require('./constants'); +import os from 'os'; +import path from 'path'; +import {replacePathSepForRegex} from 'jest-regex-util'; +import constants from './constants'; const NODE_MODULES_REGEXP = replacePathSepForRegex(constants.NODE_MODULES); diff --git a/packages/jest-config/src/deprecated.js b/packages/jest-config/src/deprecated.js index 80b3de232db8..a9065b09808e 100644 --- a/packages/jest-config/src/deprecated.js +++ b/packages/jest-config/src/deprecated.js @@ -8,7 +8,8 @@ * @flow */ -const chalk = require('chalk'); +import chalk from 'chalk'; + const format = (value: mixed) => require('pretty-format')(value, {min: true}); const deprecatedOptions = { diff --git a/packages/jest-config/src/findConfig.js b/packages/jest-config/src/findConfig.js index e10f5618a011..096e6072a03f 100644 --- a/packages/jest-config/src/findConfig.js +++ b/packages/jest-config/src/findConfig.js @@ -10,9 +10,9 @@ import type {InitialOptions, Path} from 'types/Config'; -const fs = require('fs'); -const path = require('path'); -const jsonlint = require('./vendor/jsonlint'); +import fs from 'fs'; +import path from 'path'; +import jsonlint from './vendor/jsonlint'; const JEST_CONFIG = 'jest.config.js'; const PACKAGE_JSON = 'package.json'; diff --git a/packages/jest-config/src/index.js b/packages/jest-config/src/index.js index f5c865377e12..21bfc5e2afd1 100644 --- a/packages/jest-config/src/index.js +++ b/packages/jest-config/src/index.js @@ -11,10 +11,10 @@ import type {Argv} from 'types/Argv'; import type {GlobalConfig, ProjectConfig} from 'types/Config'; -const path = require('path'); -const {getTestEnvironment, isJSONString} = require('./utils'); -const findConfig = require('./findConfig'); -const normalize = require('./normalize'); +import path from 'path'; +import {getTestEnvironment, isJSONString} from './utils'; +import findConfig from './findConfig'; +import normalize from './normalize'; function readConfig( argv: Argv, diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 9660596dbcbb..e9b596f951ba 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -11,32 +11,31 @@ import type {Argv} from 'types/Argv'; import type {InitialOptions, ReporterConfig} from 'types/Config'; -const crypto = require('crypto'); -const path = require('path'); -const {ValidationError, validate} = require('jest-validate'); -const chalk = require('chalk'); -const glob = require('glob'); -const Resolver = require('jest-resolve'); -const utils = require('jest-regex-util'); - -const { +import crypto from 'crypto'; +import path from 'path'; +import {ValidationError, validate} from 'jest-validate'; +import chalk from 'chalk'; +import glob from 'glob'; +import Resolver from 'jest-resolve'; +import utils from 'jest-regex-util'; +import { BULLET, DOCUMENTATION_NOTE, _replaceRootDirInPath, _replaceRootDirTags, getTestEnvironment, resolve, -} = require('./utils'); -const { +} from './utils'; +import { NODE_MODULES, DEFAULT_JS_PATTERN, DEFAULT_REPORTER_LABEL, -} = require('./constants'); -const {validateReporters} = require('./reporterValidationErrors'); -const DEFAULT_CONFIG = require('./defaults'); -const DEPRECATED_CONFIG = require('./deprecated'); -const setFromArgv = require('./setFromArgv'); -const VALID_CONFIG = require('./validConfig'); +} from './constants'; +import {validateReporters} from './reporterValidationErrors'; +import DEFAULT_CONFIG from './defaults'; +import DEPRECATED_CONFIG from './deprecated'; +import setFromArgv from './setFromArgv'; +import VALID_CONFIG from './validConfig'; const ERROR = `${BULLET}Validation Error`; const JSON_EXTENSION = '.json'; const PRESET_NAME = 'jest-preset' + JSON_EXTENSION; diff --git a/packages/jest-config/src/reporterValidationErrors.js b/packages/jest-config/src/reporterValidationErrors.js index 41cfed7e9ffd..8965b87fbd94 100644 --- a/packages/jest-config/src/reporterValidationErrors.js +++ b/packages/jest-config/src/reporterValidationErrors.js @@ -9,11 +9,10 @@ import type {ReporterConfig} from 'types/Config'; -const {ValidationError} = require('jest-validate'); - -const chalk = require('chalk'); -const getType = require('jest-get-type'); -const {DOCUMENTATION_NOTE, BULLET} = require('./utils'); +import {ValidationError} from 'jest-validate'; +import chalk from 'chalk'; +import getType from 'jest-get-type'; +import {DOCUMENTATION_NOTE, BULLET} from './utils'; const validReporterTypes = ['array', 'string']; const ERROR = `${BULLET}Reporter Validation Error`; diff --git a/packages/jest-config/src/setFromArgv.js b/packages/jest-config/src/setFromArgv.js index 9ed736e4b696..9da083d39ae6 100644 --- a/packages/jest-config/src/setFromArgv.js +++ b/packages/jest-config/src/setFromArgv.js @@ -12,7 +12,7 @@ import type {InitialOptions} from 'types/Config'; import type {Argv} from 'types/Argv'; const specialArgs = ['_', '$0', 'h', 'help', 'config']; -const {isJSONString} = require('./utils'); +import {isJSONString} from './utils'; function setFromArgv(options: InitialOptions, argv: Argv): InitialOptions { const argvToOptions = Object.keys(argv) diff --git a/packages/jest-config/src/utils.js b/packages/jest-config/src/utils.js index 8e51ed1bb46f..2d34430a20a9 100644 --- a/packages/jest-config/src/utils.js +++ b/packages/jest-config/src/utils.js @@ -10,10 +10,10 @@ import type {Path} from 'types/Config'; -const path = require('path'); -const {ValidationError} = require('jest-validate'); -const Resolver = require('jest-resolve'); -const chalk = require('chalk'); +import path from 'path'; +import {ValidationError} from 'jest-validate'; +import Resolver from 'jest-resolve'; +import chalk from 'chalk'; const BULLET: string = chalk.bold('\u25cf '); const DOCUMENTATION_NOTE = ` ${chalk.bold('Configuration Documentation:')} https://facebook.github.io/jest/docs/configuration.html diff --git a/packages/jest-config/src/validConfig.js b/packages/jest-config/src/validConfig.js index 05196030b5da..3feb3fa07a71 100644 --- a/packages/jest-config/src/validConfig.js +++ b/packages/jest-config/src/validConfig.js @@ -10,8 +10,8 @@ import type {InitialOptions} from 'types/Config'; -const {replacePathSepForRegex} = require('jest-regex-util'); -const constants = require('./constants'); +import {replacePathSepForRegex} from 'jest-regex-util'; +import constants from './constants'; const NODE_MODULES_REGEXP = replacePathSepForRegex(constants.NODE_MODULES); diff --git a/packages/jest-diff/src/constants.js b/packages/jest-diff/src/constants.js index 0ca0afd61062..9c41e0883686 100644 --- a/packages/jest-diff/src/constants.js +++ b/packages/jest-diff/src/constants.js @@ -8,7 +8,7 @@ * @flow */ -const chalk = require('chalk'); +import chalk from 'chalk'; exports.NO_DIFF_MESSAGE = chalk.dim( 'Compared values have no visual difference.', diff --git a/packages/jest-diff/src/diffStrings.js b/packages/jest-diff/src/diffStrings.js index cbf6da7a3a07..c7602f0a5246 100644 --- a/packages/jest-diff/src/diffStrings.js +++ b/packages/jest-diff/src/diffStrings.js @@ -8,10 +8,13 @@ * @flow */ -const chalk = require('chalk'); -const diff = require('diff'); +import chalk from 'chalk'; +import { + diffLines as diffLinesDiffer, + structuredPatch as structuredPatchDiffer, +} from 'diff'; -const {NO_DIFF_MESSAGE} = require('./constants.js'); +import {NO_DIFF_MESSAGE} from './constants.js'; const DIFF_CONTEXT = 5; export type DiffOptions = {| @@ -48,8 +51,7 @@ const getAnnotation = (options: ?DiffOptions): string => const diffLines = (a: string, b: string): Diff => { let isDifferent = false; return { - diff: diff - .diffLines(a, b) + diff: diffLinesDiffer(a, b) .map(part => { const {added, removed} = part; if (part.added || part.removed) { @@ -106,9 +108,8 @@ const structuredPatch = (a: string, b: string): Diff => { const oldLinesCount = (a.match(/\n/g) || []).length; return { - diff: diff - .structuredPatch('', '', a, b, '', '', options) - .hunks.map((hunk: Hunk) => { + diff: structuredPatchDiffer('', '', a, b, '', '', options).hunks + .map((hunk: Hunk) => { const lines = hunk.lines .map(line => { const added = line[0] === '+'; diff --git a/packages/jest-diff/src/index.js b/packages/jest-diff/src/index.js index 76d881276281..0d56f9374cdd 100644 --- a/packages/jest-diff/src/index.js +++ b/packages/jest-diff/src/index.js @@ -10,20 +10,19 @@ import type {DiffOptions} from './diffStrings'; +import prettyFormat from 'pretty-format'; +import chalk from 'chalk'; +import getType from 'jest-get-type'; +import diffStrings from './diffStrings'; +import {NO_DIFF_MESSAGE, SIMILAR_MESSAGE} from './constants'; + const { ReactElement, ReactTestComponent, AsymmetricMatcher, HTMLElement, Immutable, -} = require('pretty-format').plugins; - -const chalk = require('chalk'); -const getType = require('jest-get-type'); -const prettyFormat = require('pretty-format'); -const diffStrings = require('./diffStrings'); - -const {NO_DIFF_MESSAGE, SIMILAR_MESSAGE} = require('./constants'); +} = prettyFormat.plugins; const PLUGINS = [ ReactTestComponent, diff --git a/packages/jest-editor-support/src/Process.js b/packages/jest-editor-support/src/Process.js index f0a3a8cb9e7f..5e75f47d6424 100644 --- a/packages/jest-editor-support/src/Process.js +++ b/packages/jest-editor-support/src/Process.js @@ -8,8 +8,9 @@ * @flow */ -const {ChildProcess, spawn} = require('child_process'); -const ProjectWorkspace = require('./ProjectWorkspace'); +import {ChildProcess, spawn} from 'child_process'; + +import ProjectWorkspace from './ProjectWorkspace'; /** * Spawns and returns a Jest process with specific args diff --git a/packages/jest-editor-support/src/Runner.js b/packages/jest-editor-support/src/Runner.js index cae4f7b58c86..4643b94fd0a2 100644 --- a/packages/jest-editor-support/src/Runner.js +++ b/packages/jest-editor-support/src/Runner.js @@ -10,12 +10,12 @@ import type {Options} from './types'; -const {ChildProcess, spawn} = require('child_process'); -const {readFile} = require('fs'); -const {tmpdir} = require('os'); -const {EventEmitter} = require('events'); -const ProjectWorkspace = require('./ProjectWorkspace'); -const {createProcess} = require('./Process'); +import {ChildProcess, spawn} from 'child_process'; +import {readFile} from 'fs'; +import {tmpdir} from 'os'; +import EventEmitter from 'events'; +import ProjectWorkspace from './ProjectWorkspace'; +import {createProcess} from './Process'; // This class represents the running process, and // passes out events when it understands what data is being diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index e53be3ca28d2..9f7eda88c31d 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -10,10 +10,10 @@ import type {Options} from './types'; -const {ChildProcess} = require('child_process'); -const EventEmitter = require('events'); -const ProjectWorkspace = require('./ProjectWorkspace'); -const {createProcess} = require('./Process'); +import {ChildProcess} from 'child_process'; +import EventEmitter from 'events'; +import ProjectWorkspace from './ProjectWorkspace'; +import {createProcess} from './Process'; // This class represents the the configuration of Jest's process // we want to start with the defaults then override whatever they output diff --git a/packages/jest-editor-support/src/TestReconciler.js b/packages/jest-editor-support/src/TestReconciler.js index fe72044dfec4..1ff8152ab761 100644 --- a/packages/jest-editor-support/src/TestReconciler.js +++ b/packages/jest-editor-support/src/TestReconciler.js @@ -16,7 +16,7 @@ import type { TestReconciliationState, } from './types'; -const path = require('path'); +import path from 'path'; /** * You have a Jest test runner watching for changes, and you have diff --git a/packages/jest-editor-support/src/index.js b/packages/jest-editor-support/src/index.js index 3c70e7b0cee1..d17e7137e03d 100644 --- a/packages/jest-editor-support/src/index.js +++ b/packages/jest-editor-support/src/index.js @@ -8,13 +8,14 @@ * @flow */ -const Process = require('./Process'); -const ProjectWorkspace = require('./ProjectWorkspace'); -const Runner = require('./Runner'); -const Settings = require('./Settings'); -const {Expect, ItBlock, Node} = require('./parsers/ParserNodes'); -const {parse} = require('./parsers/BabylonParser'); -const TestReconciler = require('./TestReconciler'); +import Process from './Process'; + +import ProjectWorkspace from './ProjectWorkspace'; +import Runner from './Runner'; +import Settings from './Settings'; +import {Expect, ItBlock, Node} from './parsers/ParserNodes'; +import {parse} from './parsers/BabylonParser'; +import TestReconciler from './TestReconciler'; module.exports = { Expect, diff --git a/packages/jest-editor-support/src/parsers/BabylonParser.js b/packages/jest-editor-support/src/parsers/BabylonParser.js index e1a899809c68..75c921beb607 100644 --- a/packages/jest-editor-support/src/parsers/BabylonParser.js +++ b/packages/jest-editor-support/src/parsers/BabylonParser.js @@ -8,9 +8,10 @@ * @flow */ -const {readFileSync} = require('fs'); -const babylon = require('babylon'); -const {Expect, ItBlock} = require('./ParserNodes'); +import {readFileSync} from 'fs'; + +import {parse as babylonParse} from 'babylon'; +import {Expect, ItBlock} from './ParserNodes'; export type BabylonParserResult = { expects: Array, @@ -24,7 +25,7 @@ const parse = (file: string): BabylonParserResult => { const data = readFileSync(file).toString(); const config = {plugins: ['*'], sourceType: 'module'}; - const ast = babylon.parse(data, config); + const ast = babylonParse(data, config); // An `it`/`test` was found in the AST // So take the AST node and create an object for us diff --git a/packages/jest-environment-jsdom/src/index.js b/packages/jest-environment-jsdom/src/index.js index 96b662a1aed2..8b495bc4d457 100644 --- a/packages/jest-environment-jsdom/src/index.js +++ b/packages/jest-environment-jsdom/src/index.js @@ -12,8 +12,8 @@ import type {ProjectConfig} from 'types/Config'; import type {Global} from 'types/Global'; import type {ModuleMocker} from 'jest-mock'; -const {FakeTimers, installCommonGlobals} = require('jest-util'); -const mock = require('jest-mock'); +import {FakeTimers, installCommonGlobals} from 'jest-util'; +import mock from 'jest-mock'; class JSDOMEnvironment { document: ?Object; diff --git a/packages/jest-environment-node/src/index.js b/packages/jest-environment-node/src/index.js index 0d55e0fe37d1..e7093ee1ad81 100644 --- a/packages/jest-environment-node/src/index.js +++ b/packages/jest-environment-node/src/index.js @@ -13,9 +13,9 @@ import type {ProjectConfig} from 'types/Config'; import type {Global} from 'types/Global'; import type {ModuleMocker} from 'jest-mock'; -const vm = require('vm'); -const {FakeTimers, installCommonGlobals} = require('jest-util'); -const mock = require('jest-mock'); +import vm from 'vm'; +import {FakeTimers, installCommonGlobals} from 'jest-util'; +import mock from 'jest-mock'; class NodeEnvironment { context: ?vm$Context; diff --git a/packages/jest-haste-map/src/HasteFS.js b/packages/jest-haste-map/src/HasteFS.js index 585d8128cf73..fcd12ec95d4f 100644 --- a/packages/jest-haste-map/src/HasteFS.js +++ b/packages/jest-haste-map/src/HasteFS.js @@ -9,12 +9,11 @@ */ import type {Glob, Path} from 'types/Config'; -import type {FileData, HType} from 'types/HasteMap'; +import type {FileData} from 'types/HasteMap'; -const path = require('path'); -const micromatch = require('micromatch'); - -const H: HType = require('./constants'); +import path from 'path'; +import micromatch from 'micromatch'; +import H from './constants'; class HasteFS { _files: FileData; diff --git a/packages/jest-haste-map/src/ModuleMap.js b/packages/jest-haste-map/src/ModuleMap.js index 1dbf3a504904..16467978c633 100644 --- a/packages/jest-haste-map/src/ModuleMap.js +++ b/packages/jest-haste-map/src/ModuleMap.js @@ -10,14 +10,13 @@ import type {Path} from 'types/Config'; import type { - HType, HTypeValue, MockData, ModuleMapData, RawModuleMap, } from 'types/HasteMap'; -const H: HType = require('./constants'); +import H from './constants'; class ModuleMap { _map: ModuleMapData; diff --git a/packages/jest-haste-map/src/crawlers/node.js b/packages/jest-haste-map/src/crawlers/node.js index a121ba236080..64459f100248 100644 --- a/packages/jest-haste-map/src/crawlers/node.js +++ b/packages/jest-haste-map/src/crawlers/node.js @@ -11,11 +11,10 @@ import type {InternalHasteMap} from 'types/HasteMap'; import type {IgnoreMatcher, CrawlerOptions} from '../types'; -const fs = require('fs'); -const path = require('path'); -const {spawn} = require('child_process'); - -const H = require('../constants'); +import fs from 'fs'; +import path from 'path'; +import {spawn} from 'child_process'; +import H from '../constants'; type Callback = (result: Array<[/* id */ string, /* mtime */ number]>) => void; diff --git a/packages/jest-haste-map/src/crawlers/watchman.js b/packages/jest-haste-map/src/crawlers/watchman.js index eace542c32f9..2c79d289d5cf 100644 --- a/packages/jest-haste-map/src/crawlers/watchman.js +++ b/packages/jest-haste-map/src/crawlers/watchman.js @@ -11,9 +11,9 @@ import type {InternalHasteMap} from 'types/HasteMap'; import type {CrawlerOptions} from '../types'; -const path = require('path'); -const watchman = require('fb-watchman'); -const H = require('../constants'); +import path from 'path'; +import watchman from 'fb-watchman'; +import H from '../constants'; const watchmanURL = 'https://facebook.github.io/watchman/docs/troubleshooting.html'; diff --git a/packages/jest-haste-map/src/getMockName.js b/packages/jest-haste-map/src/getMockName.js index a2a2a4f834e6..7ca2b9b5db67 100644 --- a/packages/jest-haste-map/src/getMockName.js +++ b/packages/jest-haste-map/src/getMockName.js @@ -8,7 +8,7 @@ * @flow */ -const path = require('path'); +import path from 'path'; const MOCKS_PATTERN = path.sep + '__mocks__' + path.sep; diff --git a/packages/jest-haste-map/src/index.js b/packages/jest-haste-map/src/index.js index 882325dc2495..b24004a94c7e 100644 --- a/packages/jest-haste-map/src/index.js +++ b/packages/jest-haste-map/src/index.js @@ -19,28 +19,27 @@ import type { MockData, } from 'types/HasteMap'; import type {WorkerMessage, WorkerMetadata, WorkerCallback} from './types'; +// eslint-disable-next-line import/no-duplicates import typeof HType from './constants'; -const EventEmitter = require('events'); -const os = require('os'); -const path = require('path'); -const crypto = require('crypto'); -const {execSync} = require('child_process'); -const fs = require('graceful-fs'); -const sane = require('sane'); -const workerFarm = require('worker-farm'); - -const VERSION = require('../package.json').version; - -const H = require('./constants'); -const HasteFS = require('./HasteFS'); -const HasteModuleMap = require('./ModuleMap'); -const getMockName = require('./getMockName'); - -const getPlatformExtension = require('./lib/getPlatformExtension'); -const nodeCrawl = require('./crawlers/node'); -const watchmanCrawl = require('./crawlers/watchman'); -const worker = require('./worker'); +import EventEmitter from 'events'; +import os from 'os'; +import path from 'path'; +import crypto from 'crypto'; +import {execSync} from 'child_process'; +import fs from 'graceful-fs'; +import sane from 'sane'; +import workerFarm from 'worker-farm'; +import {version as VERSION} from '../package.json'; +// eslint-disable-next-line import/no-duplicates +import H from './constants'; +import HasteFS from './HasteFS'; +import HasteModuleMap from './ModuleMap'; +import getMockName from './getMockName'; +import getPlatformExtension from './lib/getPlatformExtension'; +import nodeCrawl from './crawlers/node'; +import watchmanCrawl from './crawlers/watchman'; +import worker from './worker'; type Options = { cacheDirectory?: string, diff --git a/packages/jest-haste-map/src/worker.js b/packages/jest-haste-map/src/worker.js index d25bcf90d59c..e35bb9db6f12 100644 --- a/packages/jest-haste-map/src/worker.js +++ b/packages/jest-haste-map/src/worker.js @@ -11,11 +11,11 @@ import type {SerializableError} from 'types/TestResult'; import type {HasteImpl, WorkerMessage, WorkerCallback} from './types'; -const path = require('path'); -const docblock = require('jest-docblock'); -const fs = require('graceful-fs'); -const H = require('./constants'); -const extractRequires = require('./lib/extractRequires'); +import path from 'path'; +import docblock from 'jest-docblock'; +import fs from 'graceful-fs'; +import H from './constants'; +import extractRequires from './lib/extractRequires'; const JSON_EXTENSION = '.json'; const PACKAGE_JSON = path.sep + 'package' + JSON_EXTENSION; diff --git a/packages/jest-jasmine2/src/assert-support.js b/packages/jest-jasmine2/src/assert-support.js index 0c20461b79f1..342acc751bd5 100644 --- a/packages/jest-jasmine2/src/assert-support.js +++ b/packages/jest-jasmine2/src/assert-support.js @@ -10,9 +10,9 @@ import type {DiffOptions} from 'jest-diff/src/diffStrings'; -const {printReceived, printExpected} = require('jest-matcher-utils'); -const chalk = require('chalk'); -const diff = require('jest-diff'); +import {printReceived, printExpected} from 'jest-matcher-utils'; +import chalk from 'chalk'; +import diff from 'jest-diff'; type AssertionError = {| actual: ?string, diff --git a/packages/jest-jasmine2/src/index.js b/packages/jest-jasmine2/src/index.js index b5e63287e963..525a965044e5 100644 --- a/packages/jest-jasmine2/src/index.js +++ b/packages/jest-jasmine2/src/index.js @@ -14,11 +14,9 @@ import type {SnapshotState} from 'jest-snapshot'; import type {TestResult} from 'types/TestResult'; import type Runtime from 'jest-runtime'; -const path = require('path'); - -const JasmineReporter = require('./reporter'); - -const jasmineAsync = require('./jasmine-async'); +import path from 'path'; +import JasmineReporter from './reporter'; +import jasmineAsync from './jasmine-async'; const JASMINE = require.resolve('./jasmine/jasmine-light.js'); diff --git a/packages/jest-jasmine2/src/jasmine/Env.js b/packages/jest-jasmine2/src/jasmine/Env.js index af37cc2b18da..e77ceeb2dcdf 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.js +++ b/packages/jest-jasmine2/src/jasmine/Env.js @@ -31,8 +31,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* eslint-disable sort-keys */ -const queueRunner = require('../queueRunner'); -const treeProcessor = require('../treeProcessor'); +import queueRunner from '../queueRunner'; + +import treeProcessor from '../treeProcessor'; module.exports = function(j$) { function Env(options) { diff --git a/packages/jest-jasmine2/src/jasmine/Spec.js b/packages/jest-jasmine2/src/jasmine/Spec.js index 036b863dabc7..b8a36726d5e8 100644 --- a/packages/jest-jasmine2/src/jasmine/Spec.js +++ b/packages/jest-jasmine2/src/jasmine/Spec.js @@ -32,8 +32,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* @flow */ /* eslint-disable sort-keys */ -const ExpectationFailed = require('../ExpectationFailed'); -const expectationResultFactory = require('../expectationResultFactory'); +import ExpectationFailed from '../ExpectationFailed'; + +import expectationResultFactory from '../expectationResultFactory'; function Spec(attrs: Object) { this.resultCallback = attrs.resultCallback || function() {}; diff --git a/packages/jest-jasmine2/src/jasmine/SpyRegistry.js b/packages/jest-jasmine2/src/jasmine/SpyRegistry.js index d4d3b7396881..7667f68b2c48 100644 --- a/packages/jest-jasmine2/src/jasmine/SpyRegistry.js +++ b/packages/jest-jasmine2/src/jasmine/SpyRegistry.js @@ -31,9 +31,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* @flow */ -const CallTracker = require('./CallTracker'); -const createSpy = require('./createSpy'); -const SpyStrategy = require('./SpyStrategy'); +import CallTracker from './CallTracker'; + +import createSpy from './createSpy'; +import SpyStrategy from './SpyStrategy'; const formatErrorMsg = (domain: string, usage?: string) => { const usageDefinition = usage ? '\nUsage: ' + usage : ''; diff --git a/packages/jest-jasmine2/src/jasmine/Suite.js b/packages/jest-jasmine2/src/jasmine/Suite.js index c21a61d74f01..83449e3573cf 100644 --- a/packages/jest-jasmine2/src/jasmine/Suite.js +++ b/packages/jest-jasmine2/src/jasmine/Suite.js @@ -32,8 +32,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* @flow */ /* eslint-disable sort-keys */ -const ExpectationFailed = require('../ExpectationFailed'); -const expectationResultFactory = require('../expectationResultFactory'); +import ExpectationFailed from '../ExpectationFailed'; + +import expectationResultFactory from '../expectationResultFactory'; function Suite(attrs: Object) { this.id = attrs.id; diff --git a/packages/jest-jasmine2/src/jasmine/createSpy.js b/packages/jest-jasmine2/src/jasmine/createSpy.js index ce36e04c497e..8af4ed56bc06 100644 --- a/packages/jest-jasmine2/src/jasmine/createSpy.js +++ b/packages/jest-jasmine2/src/jasmine/createSpy.js @@ -31,8 +31,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* eslint-disable sort-keys */ -const CallTracker = require('./CallTracker'); -const SpyStrategy = require('./SpyStrategy'); +import CallTracker from './CallTracker'; + +import SpyStrategy from './SpyStrategy'; function createSpy(name, originalFn) { const spyStrategy = new SpyStrategy({ diff --git a/packages/jest-jasmine2/src/jasmine/jasmine-light.js b/packages/jest-jasmine2/src/jasmine/jasmine-light.js index c496b1df8813..abb2f7cb5f11 100644 --- a/packages/jest-jasmine2/src/jasmine/jasmine-light.js +++ b/packages/jest-jasmine2/src/jasmine/jasmine-light.js @@ -34,14 +34,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import type {Jasmine} from 'types/Jasmine'; -const createSpy = require('./createSpy'); -const Env = require('./Env'); -const JsApiReporter = require('./JsApiReporter'); -const ReportDispatcher = require('./ReportDispatcher'); -const Spec = require('./Spec'); -const SpyRegistry = require('./SpyRegistry'); -const Suite = require('./Suite'); -const Timer = require('./Timer'); +import createSpy from './createSpy'; +import Env from './Env'; +import JsApiReporter from './JsApiReporter'; +import ReportDispatcher from './ReportDispatcher'; +import Spec from './Spec'; +import SpyRegistry from './SpyRegistry'; +import Suite from './Suite'; +import Timer from './Timer'; exports.create = function() { const j$ = {}; diff --git a/packages/jest-jasmine2/src/jest-expect.js b/packages/jest-jasmine2/src/jest-expect.js index a16256c9aacc..188ecfbc20b1 100644 --- a/packages/jest-jasmine2/src/jest-expect.js +++ b/packages/jest-jasmine2/src/jest-expect.js @@ -10,13 +10,12 @@ import type {RawMatcherFn} from 'types/Matchers'; -const expect = require('jest-matchers'); - -const { +import expect from 'jest-matchers'; +import { addSerializer, toMatchSnapshot, toThrowErrorMatchingSnapshot, -} = require('jest-snapshot'); +} from 'jest-snapshot'; type JasmineMatcher = { (matchersUtil: any, context: any): JasmineMatcher, diff --git a/packages/jest-jasmine2/src/queueRunner.js b/packages/jest-jasmine2/src/queueRunner.js index ed421f89eb71..b6f97f7ea26b 100644 --- a/packages/jest-jasmine2/src/queueRunner.js +++ b/packages/jest-jasmine2/src/queueRunner.js @@ -8,9 +8,10 @@ * @flow */ -const once = require('once'); -const pMap = require('p-map'); -const pTimeout = require('./p-timeout'); +import once from 'once'; + +import pMap from 'p-map'; +import pTimeout from './p-timeout'; type Options = { clearTimeout: (timeoutID: number) => void, diff --git a/packages/jest-jasmine2/src/reporter.js b/packages/jest-jasmine2/src/reporter.js index b952931a328e..2a0aa38d1599 100644 --- a/packages/jest-jasmine2/src/reporter.js +++ b/packages/jest-jasmine2/src/reporter.js @@ -18,7 +18,7 @@ import type { TestResult, } from 'types/TestResult'; -const {formatResultsErrors} = require('jest-message-util'); +import {formatResultsErrors} from 'jest-message-util'; type Suite = { description: string, diff --git a/packages/jest-jasmine2/src/setup-jest-globals.js b/packages/jest-jasmine2/src/setup-jest-globals.js index 3a172bca90c1..c738708f5a28 100644 --- a/packages/jest-jasmine2/src/setup-jest-globals.js +++ b/packages/jest-jasmine2/src/setup-jest-globals.js @@ -11,14 +11,14 @@ import type {GlobalConfig, Path, ProjectConfig} from 'types/Config'; import type {Plugin} from 'types/PrettyFormat'; -const {getState, setState} = require('jest-matchers'); -const {SnapshotState, addSerializer} = require('jest-snapshot'); -const { +import {getState, setState} from 'jest-matchers'; +import {SnapshotState, addSerializer} from 'jest-snapshot'; +import { EXPECTED_COLOR, RECEIVED_COLOR, matcherHint, pluralize, -} = require('jest-matcher-utils'); +} from 'jest-matcher-utils'; export type SetupOptions = {| config: ProjectConfig, diff --git a/packages/jest-matcher-utils/src/index.js b/packages/jest-matcher-utils/src/index.js index c6c9ca548879..01ad33d4c29a 100644 --- a/packages/jest-matcher-utils/src/index.js +++ b/packages/jest-matcher-utils/src/index.js @@ -8,15 +8,15 @@ * @flow */ -const chalk = require('chalk'); -const getType = require('jest-get-type'); -const prettyFormat = require('pretty-format'); +import chalk from 'chalk'; +import getType from 'jest-get-type'; +import prettyFormat from 'pretty-format'; const { AsymmetricMatcher, ReactElement, HTMLElement, Immutable, -} = require('pretty-format').plugins; +} = prettyFormat.plugins; const PLUGINS = [AsymmetricMatcher, ReactElement, HTMLElement].concat( Immutable, diff --git a/packages/jest-matchers/src/asymmetric-matchers.js b/packages/jest-matchers/src/asymmetric-matchers.js index 60c0716d54cf..e71f49ce0740 100644 --- a/packages/jest-matchers/src/asymmetric-matchers.js +++ b/packages/jest-matchers/src/asymmetric-matchers.js @@ -8,13 +8,13 @@ * @flow */ -const { +import { equals, fnNameFor, hasProperty, isA, isUndefined, -} = require('./jasmine-utils'); +} from './jasmine-utils'; class AsymmetricMatcher { $$typeof: Symbol; diff --git a/packages/jest-matchers/src/index.js b/packages/jest-matchers/src/index.js index 45d5b8d95b2d..5ab860407f2f 100644 --- a/packages/jest-matchers/src/index.js +++ b/packages/jest-matchers/src/index.js @@ -19,19 +19,19 @@ import type { PromiseMatcherFn, } from 'types/Matchers'; -const utils = require('jest-matcher-utils'); -const matchers = require('./matchers'); -const spyMatchers = require('./spyMatchers'); -const toThrowMatchers = require('./toThrowMatchers'); -const {equals} = require('./jasmine-utils'); -const { +import utils from 'jest-matcher-utils'; +import matchers from './matchers'; +import spyMatchers from './spyMatchers'; +import toThrowMatchers from './toThrowMatchers'; +import {equals} from './jasmine-utils'; +import { any, anything, arrayContaining, objectContaining, stringContaining, stringMatching, -} = require('./asymmetric-matchers'); +} from './asymmetric-matchers'; const GLOBAL_STATE = Symbol.for('$$jest-matchers-object'); diff --git a/packages/jest-matchers/src/matchers.js b/packages/jest-matchers/src/matchers.js index add029abfa6a..67c40656bfcb 100644 --- a/packages/jest-matchers/src/matchers.js +++ b/packages/jest-matchers/src/matchers.js @@ -10,10 +10,10 @@ import type {MatchersObject} from 'types/Matchers'; -const diff = require('jest-diff'); -const getType = require('jest-get-type'); -const {escapeStrForRegex} = require('jest-regex-util'); -const { +import diff from 'jest-diff'; +import getType from 'jest-get-type'; +import {escapeStrForRegex} from 'jest-regex-util'; +import { EXPECTED_COLOR, RECEIVED_COLOR, ensureNoExpected, @@ -22,9 +22,9 @@ const { printReceived, printExpected, printWithType, -} = require('jest-matcher-utils'); -const {getObjectSubset, getPath, hasOwnProperty} = require('./utils'); -const {equals} = require('./jasmine-utils'); +} from 'jest-matcher-utils'; +import {getObjectSubset, getPath, hasOwnProperty} from './utils'; +import {equals} from './jasmine-utils'; type ContainIterable = | Array diff --git a/packages/jest-matchers/src/spyMatchers.js b/packages/jest-matchers/src/spyMatchers.js index 0b38721f703b..035f79ce82bf 100644 --- a/packages/jest-matchers/src/spyMatchers.js +++ b/packages/jest-matchers/src/spyMatchers.js @@ -12,7 +12,7 @@ import type {MatchersObject} from 'types/Matchers'; const CALL_PRINT_LIMIT = 3; const LAST_CALL_PRINT_LIMIT = 1; -const { +import { ensureExpectedIsNumber, ensureNoExpected, EXPECTED_COLOR, @@ -22,8 +22,8 @@ const { printReceived, printWithType, RECEIVED_COLOR, -} = require('jest-matcher-utils'); -const {equals} = require('./jasmine-utils'); +} from 'jest-matcher-utils'; +import {equals} from './jasmine-utils'; const RECEIVED_NAME = { 'mock function': 'jest.fn()', diff --git a/packages/jest-matchers/src/toThrowMatchers.js b/packages/jest-matchers/src/toThrowMatchers.js index cb32eb35fbc0..9673395b1332 100644 --- a/packages/jest-matchers/src/toThrowMatchers.js +++ b/packages/jest-matchers/src/toThrowMatchers.js @@ -10,21 +10,18 @@ import type {MatchersObject} from 'types/Matchers'; -const getType = require('jest-get-type'); -const {escapeStrForRegex} = require('jest-regex-util'); -const { - formatStackTrace, - separateMessageFromStack, -} = require('jest-message-util'); -const { +import getType from 'jest-get-type'; +import {escapeStrForRegex} from 'jest-regex-util'; +import {formatStackTrace, separateMessageFromStack} from 'jest-message-util'; +import { RECEIVED_BG, RECEIVED_COLOR, highlightTrailingWhitespace, matcherHint, printExpected, printWithType, -} = require('jest-matcher-utils'); -const {equals} = require('./jasmine-utils'); +} from 'jest-matcher-utils'; +import {equals} from './jasmine-utils'; const createMatcher = matcherName => ( actual: Function, diff --git a/packages/jest-message-util/src/index.js b/packages/jest-message-util/src/index.js index 906480e87096..dd6bda51aedc 100644 --- a/packages/jest-message-util/src/index.js +++ b/packages/jest-message-util/src/index.js @@ -11,10 +11,10 @@ import type {Glob, Path} from 'types/Config'; import type {AssertionResult, TestResult} from 'types/TestResult'; -const path = require('path'); -const chalk = require('chalk'); -const micromatch = require('micromatch'); -const slash = require('slash'); +import path from 'path'; +import chalk from 'chalk'; +import micromatch from 'micromatch'; +import slash from 'slash'; type StackTraceConfig = { rootDir: string, diff --git a/packages/jest-phabricator/src/index.js b/packages/jest-phabricator/src/index.js index ea3314b4cf14..6ce4fe2024f5 100644 --- a/packages/jest-phabricator/src/index.js +++ b/packages/jest-phabricator/src/index.js @@ -17,7 +17,7 @@ type PhabricatorReport = AggregatedResult & { phabricatorReport: Array, }; -const {formatTestResults} = require('jest-util'); +import {formatTestResults} from 'jest-util'; function summarize(coverageMap: CoverageMap) { const summaries = Object.create(null); diff --git a/packages/jest-regex-util/src/index.js b/packages/jest-regex-util/src/index.js index 4eb38e2d372a..5a6a0b8828ee 100644 --- a/packages/jest-regex-util/src/index.js +++ b/packages/jest-regex-util/src/index.js @@ -8,7 +8,7 @@ * @flow */ -const path = require('path'); +import path from 'path'; const escapePathForRegex = (dir: string) => { if (path.sep === '\\') { diff --git a/packages/jest-repl/src/cli/args.js b/packages/jest-repl/src/cli/args.js index fe1010e2a505..7b5f13b955a1 100644 --- a/packages/jest-repl/src/cli/args.js +++ b/packages/jest-repl/src/cli/args.js @@ -8,7 +8,7 @@ * @flow */ -const Runtime = require('jest-runtime'); +import Runtime from 'jest-runtime'; const usage = 'Usage: $0 [--config=]'; diff --git a/packages/jest-repl/src/cli/index.js b/packages/jest-repl/src/cli/index.js index e0142ce53c19..7a43faf87029 100644 --- a/packages/jest-repl/src/cli/index.js +++ b/packages/jest-repl/src/cli/index.js @@ -9,12 +9,13 @@ * @flow */ -const path = require('path'); -const Runtime = require('jest-runtime'); -const yargs = require('yargs'); -const {validateCLIOptions} = require('jest-util'); -const VERSION = require('../../package.json').version; -const args = require('./args'); +import path from 'path'; + +import Runtime from 'jest-runtime'; +import yargs from 'yargs'; +import {validateCLIOptions} from 'jest-util'; +import {version as VERSION} from '../../package.json'; +import args from './args'; const REPL_SCRIPT = path.resolve(__dirname, './repl.js'); diff --git a/packages/jest-repl/src/cli/repl.js b/packages/jest-repl/src/cli/repl.js index 0016d1444ddd..6d7705183c17 100644 --- a/packages/jest-repl/src/cli/repl.js +++ b/packages/jest-repl/src/cli/repl.js @@ -15,9 +15,9 @@ declare var jestGlobalConfig: GlobalConfig; declare var jestProjectConfig: ProjectConfig; declare var jest: Object; -const path = require('path'); -const repl = require('repl'); -const vm = require('vm'); +import path from 'path'; +import repl from 'repl'; +import vm from 'vm'; let transformer; diff --git a/packages/jest-resolve-dependencies/src/index.js b/packages/jest-resolve-dependencies/src/index.js index f3b428c9c1c6..a24bd003b29c 100644 --- a/packages/jest-resolve-dependencies/src/index.js +++ b/packages/jest-resolve-dependencies/src/index.js @@ -12,7 +12,7 @@ import type {HasteFS} from 'types/HasteMap'; import type {Path} from 'types/Config'; import type {Resolver, ResolveModuleConfig} from 'types/Resolve'; -const {replacePathSepForRegex} = require('jest-regex-util'); +import {replacePathSepForRegex} from 'jest-regex-util'; const snapshotDirRegex = new RegExp( replacePathSepForRegex('\/__snapshots__\/'), diff --git a/packages/jest-resolve/src/defaultResolver.js b/packages/jest-resolve/src/defaultResolver.js index 42c4a3223658..a4799d07aeb1 100644 --- a/packages/jest-resolve/src/defaultResolver.js +++ b/packages/jest-resolve/src/defaultResolver.js @@ -10,8 +10,8 @@ import type {Path} from 'types/Config'; -const resolve = require('resolve'); -const browserResolve = require('browser-resolve'); +import resolve from 'resolve'; +import browserResolve from 'browser-resolve'; type ResolverOptions = {| basedir: Path, diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index 06407663bc5e..74a3fd7290ce 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -11,10 +11,10 @@ import type {Path} from 'types/Config'; import type {ModuleMap} from 'types/HasteMap'; -const fs = require('fs'); -const path = require('path'); -const nodeModulesPaths = require('resolve/lib/node-modules-paths'); -const isBuiltinModule = require('is-builtin-module'); +import fs from 'fs'; +import path from 'path'; +import nodeModulesPaths from 'resolve/lib/node-modules-paths'; +import isBuiltinModule from 'is-builtin-module'; type ResolverConfig = {| browser?: boolean, diff --git a/packages/jest-runtime/src/ScriptTransformer.js b/packages/jest-runtime/src/ScriptTransformer.js index f171b51b32b2..46b94d97cb1a 100644 --- a/packages/jest-runtime/src/ScriptTransformer.js +++ b/packages/jest-runtime/src/ScriptTransformer.js @@ -15,17 +15,17 @@ import type { TransformResult, } from 'types/Transform'; -const crypto = require('crypto'); -const path = require('path'); -const vm = require('vm'); -const {createDirectory} = require('jest-util'); -const fs = require('graceful-fs'); -const {getCacheFilePath} = require('jest-haste-map'); -const stableStringify = require('json-stable-stringify'); -const slash = require('slash'); - -const VERSION = require('../package.json').version; -const shouldInstrument = require('./shouldInstrument'); +import crypto from 'crypto'; +import path from 'path'; +import vm from 'vm'; +import {createDirectory} from 'jest-util'; +import fs from 'graceful-fs'; +// $FlowFixMe: Missing ESM export +import {getCacheFilePath} from 'jest-haste-map'; +import stableStringify from 'json-stable-stringify'; +import slash from 'slash'; +import {version as VERSION} from '../package.json'; +import shouldInstrument from './shouldInstrument'; export type Options = {| collectCoverage: boolean, diff --git a/packages/jest-runtime/src/__mocks__/createRuntime.js b/packages/jest-runtime/src/__mocks__/createRuntime.js index c2399172c146..5d665afbaa63 100644 --- a/packages/jest-runtime/src/__mocks__/createRuntime.js +++ b/packages/jest-runtime/src/__mocks__/createRuntime.js @@ -6,7 +6,7 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -const path = require('path'); +import path from 'path'; module.exports = function createRuntime(filename, config) { const NodeEnvironment = require('jest-environment-node'); diff --git a/packages/jest-runtime/src/cli/index.js b/packages/jest-runtime/src/cli/index.js index fe12dd8cc4e1..7a8d2808448b 100644 --- a/packages/jest-runtime/src/cli/index.js +++ b/packages/jest-runtime/src/cli/index.js @@ -11,16 +11,15 @@ import type {Argv} from 'types/Argv'; import type {EnvironmentClass} from 'types/Environment'; -const os = require('os'); -const path = require('path'); -const chalk = require('chalk'); -const yargs = require('yargs'); - -const {Console, setGlobal, validateCLIOptions} = require('jest-util'); -const {readConfig} = require('jest-config'); +import os from 'os'; +import path from 'path'; +import chalk from 'chalk'; +import yargs from 'yargs'; +import {Console, setGlobal, validateCLIOptions} from 'jest-util'; +import {readConfig} from 'jest-config'; const VERSION = (require('../../package.json').version: string); -const Runtime = require('../'); -const args = require('./args'); +import Runtime from '../'; +import args from './args'; function run(cliArgv?: Argv, cliInfo?: Array) { let argv; diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 4fe5634c89e4..07233b4bbae9 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -16,16 +16,15 @@ import type {Context} from 'types/Context'; import type {ModuleMap} from 'jest-haste-map'; import type {MockFunctionMetadata, ModuleMocker} from 'types/Mock'; -const path = require('path'); -const HasteMap = require('jest-haste-map'); -const Resolver = require('jest-resolve'); - -const {createDirectory} = require('jest-util'); -const {escapePathForRegex} = require('jest-regex-util'); -const fs = require('graceful-fs'); -const stripBOM = require('strip-bom'); -const ScriptTransformer = require('./ScriptTransformer'); -const shouldInstrument = require('./shouldInstrument'); +import path from 'path'; +import HasteMap from 'jest-haste-map'; +import Resolver from 'jest-resolve'; +import {createDirectory} from 'jest-util'; +import {escapePathForRegex} from 'jest-regex-util'; +import fs from 'graceful-fs'; +import stripBOM from 'strip-bom'; +import ScriptTransformer from './ScriptTransformer'; +import shouldInstrument from './shouldInstrument'; type Module = {| children?: Array, diff --git a/packages/jest-runtime/src/shouldInstrument.js b/packages/jest-runtime/src/shouldInstrument.js index 4868acf226d2..102ada2b3f97 100644 --- a/packages/jest-runtime/src/shouldInstrument.js +++ b/packages/jest-runtime/src/shouldInstrument.js @@ -11,9 +11,9 @@ import type {Path, ProjectConfig} from 'types/Config'; import type {Options} from './ScriptTransformer'; -const path = require('path'); -const {escapePathForRegex} = require('jest-regex-util'); -const micromatch = require('micromatch'); +import path from 'path'; +import {escapePathForRegex} from 'jest-regex-util'; +import micromatch from 'micromatch'; const MOCKS_PATTERN = new RegExp( escapePathForRegex(path.sep + '__mocks__' + path.sep), diff --git a/packages/jest-snapshot/src/State.js b/packages/jest-snapshot/src/State.js index 4e91712b7f94..7161a5f8140d 100644 --- a/packages/jest-snapshot/src/State.js +++ b/packages/jest-snapshot/src/State.js @@ -10,8 +10,8 @@ import type {Path, SnapshotUpdateState} from 'types/Config'; -const fs = require('fs'); -const { +import fs from 'fs'; +import { saveSnapshotFile, getSnapshotData, getSnapshotPath, @@ -19,7 +19,7 @@ const { serialize, testNameToKey, unescape, -} = require('./utils'); +} from './utils'; export type SnapshotStateOptions = {| updateSnapshot: SnapshotUpdateState, diff --git a/packages/jest-snapshot/src/index.js b/packages/jest-snapshot/src/index.js index bbcb1ea90cd6..15863996e8ef 100644 --- a/packages/jest-snapshot/src/index.js +++ b/packages/jest-snapshot/src/index.js @@ -12,19 +12,18 @@ import type {HasteFS} from 'types/HasteMap'; import type {MatcherState} from 'types/Matchers'; import type {Path, SnapshotUpdateState} from 'types/Config'; -const fs = require('fs'); -const path = require('path'); -const diff = require('jest-diff'); -const { +import fs from 'fs'; +import path from 'path'; +import diff from 'jest-diff'; +import { EXPECTED_COLOR, ensureNoExpected, matcherHint, RECEIVED_COLOR, -} = require('jest-matcher-utils'); - -const SnapshotState = require('./State'); -const {addSerializer, getSerializers} = require('./plugins'); -const {SNAPSHOT_EXTENSION} = require('./utils'); +} from 'jest-matcher-utils'; +import SnapshotState from './State'; +import {addSerializer, getSerializers} from './plugins'; +import {SNAPSHOT_EXTENSION} from './utils'; const fileExists = (filePath: Path, hasteFS: HasteFS): boolean => hasteFS.exists(filePath) || fs.existsSync(filePath); diff --git a/packages/jest-snapshot/src/plugins.js b/packages/jest-snapshot/src/plugins.js index 350cd01df9ba..58bf77c5624d 100644 --- a/packages/jest-snapshot/src/plugins.js +++ b/packages/jest-snapshot/src/plugins.js @@ -10,12 +10,14 @@ import type {Plugin} from 'types/PrettyFormat'; +import prettyFormat from 'pretty-format'; + const { HTMLElement, Immutable, ReactElement, ReactTestComponent, -} = require('pretty-format').plugins; +} = prettyFormat.plugins; let PLUGINS = [ReactTestComponent, ReactElement, HTMLElement].concat(Immutable); diff --git a/packages/jest-snapshot/src/utils.js b/packages/jest-snapshot/src/utils.js index b2d32cb6f14f..6c9975c2ffa3 100644 --- a/packages/jest-snapshot/src/utils.js +++ b/packages/jest-snapshot/src/utils.js @@ -10,13 +10,13 @@ import type {Path, SnapshotUpdateState} from 'types/Config'; -const fs = require('fs'); -const path = require('path'); -const chalk = require('chalk'); -const {createDirectory} = require('jest-util'); -const prettyFormat = require('pretty-format'); -const naturalCompare = require('natural-compare'); -const {getSerializers} = require('./plugins'); +import fs from 'fs'; +import path from 'path'; +import chalk from 'chalk'; +import {createDirectory} from 'jest-util'; +import prettyFormat from 'pretty-format'; +import naturalCompare from 'natural-compare'; +import {getSerializers} from './plugins'; const SNAPSHOT_EXTENSION = 'snap'; const SNAPSHOT_VERSION = '1'; diff --git a/packages/jest-test-typescript-parser/src/TypeScriptParser.js b/packages/jest-test-typescript-parser/src/TypeScriptParser.js index c62b27c80a4a..6c84d462efd4 100644 --- a/packages/jest-test-typescript-parser/src/TypeScriptParser.js +++ b/packages/jest-test-typescript-parser/src/TypeScriptParser.js @@ -8,9 +8,10 @@ * @flow */ -const {readFileSync} = require('fs'); -const ts = require('typescript'); -const {Expect, ItBlock, Node} = require('jest-editor-support'); +import {readFileSync} from 'fs'; + +import ts from 'typescript'; +import {Expect, ItBlock, Node} from 'jest-editor-support'; function parse(file: string) { const sourceFile = ts.createSourceFile( diff --git a/packages/jest-test-typescript-parser/src/index.js b/packages/jest-test-typescript-parser/src/index.js index ee559a39562e..b847a586df47 100644 --- a/packages/jest-test-typescript-parser/src/index.js +++ b/packages/jest-test-typescript-parser/src/index.js @@ -8,8 +8,9 @@ * @flow */ -const {parse: babylonParser, ItBlock, Expect} = require('jest-editor-support'); -const TypeScriptParser = require('./TypeScriptParser'); +import {parse as babylonParser, ItBlock, Expect} from 'jest-editor-support'; +import TypeScriptParser from './TypeScriptParser'; + export type ParserReturn = { itBlocks: Array, expects: Array, diff --git a/packages/jest-util/src/Console.js b/packages/jest-util/src/Console.js index 7d8ff6b04aa4..b284a753d810 100644 --- a/packages/jest-util/src/Console.js +++ b/packages/jest-util/src/Console.js @@ -11,10 +11,9 @@ import type {LogType, LogMessage} from 'types/Console'; -const {format} = require('util'); -const {Console} = require('console'); - -const clearLine = require('./clearLine'); +import {format} from 'util'; +import {Console} from 'console'; +import clearLine from './clearLine'; type Formatter = (type: LogType, message: LogMessage) => string; diff --git a/packages/jest-util/src/FakeTimers.js b/packages/jest-util/src/FakeTimers.js index 3a93af5cf699..5c9144bc14a5 100644 --- a/packages/jest-util/src/FakeTimers.js +++ b/packages/jest-util/src/FakeTimers.js @@ -12,8 +12,8 @@ import type {ProjectConfig} from 'types/Config'; import type {Global} from 'types/Global'; import type {ModuleMocker} from 'jest-mock'; -const {formatStackTrace} = require('jest-message-util'); -const setGlobal = require('./setGlobal'); +import {formatStackTrace} from 'jest-message-util'; +import setGlobal from './setGlobal'; /** * We don't know the type of arguments for a callback ahead of time which is why diff --git a/packages/jest-util/src/NullConsole.js b/packages/jest-util/src/NullConsole.js index b26ed0ef77ee..c54d2f5ec5b8 100644 --- a/packages/jest-util/src/NullConsole.js +++ b/packages/jest-util/src/NullConsole.js @@ -8,7 +8,7 @@ * @flow */ -const Console = require('./Console'); +import Console from './Console'; class NullConsole extends Console { assert() {} diff --git a/packages/jest-util/src/index.js b/packages/jest-util/src/index.js index aced58512512..ac3177f2586a 100644 --- a/packages/jest-util/src/index.js +++ b/packages/jest-util/src/index.js @@ -8,16 +8,16 @@ * @flow */ -const mkdirp = require('mkdirp'); -const Console = require('./Console'); -const FakeTimers = require('./FakeTimers'); -const NullConsole = require('./NullConsole'); +import mkdirp from 'mkdirp'; -const clearLine = require('./clearLine'); -const formatTestResults = require('./formatTestResults'); -const installCommonGlobals = require('./installCommonGlobals'); -const setGlobal = require('./setGlobal'); -const validateCLIOptions = require('./validateCLIOptions'); +import Console from './Console'; +import FakeTimers from './FakeTimers'; +import NullConsole from './NullConsole'; +import clearLine from './clearLine'; +import formatTestResults from './formatTestResults'; +import installCommonGlobals from './installCommonGlobals'; +import setGlobal from './setGlobal'; +import validateCLIOptions from './validateCLIOptions'; const createDirectory = (path: string) => { try { diff --git a/packages/jest-util/src/validateCLIOptions.js b/packages/jest-util/src/validateCLIOptions.js index 6f481ad79829..9e54f458a8b5 100644 --- a/packages/jest-util/src/validateCLIOptions.js +++ b/packages/jest-util/src/validateCLIOptions.js @@ -10,12 +10,8 @@ import type {Argv} from 'types/Argv'; -const chalk = require('chalk'); -const { - ValidationError, - format, - createDidYouMeanMessage, -} = require('jest-validate'); +import chalk from 'chalk'; +import {ValidationError, format, createDidYouMeanMessage} from 'jest-validate'; const BULLET: string = chalk.bold('\u25cf'); diff --git a/packages/jest-validate/src/defaultConfig.js b/packages/jest-validate/src/defaultConfig.js index 7b18afaf6332..11a56d9e9dbe 100644 --- a/packages/jest-validate/src/defaultConfig.js +++ b/packages/jest-validate/src/defaultConfig.js @@ -10,12 +10,12 @@ import type {ValidationOptions} from './types'; -const {deprecationWarning} = require('./deprecated'); -const {unknownOptionWarning} = require('./warnings'); -const {errorMessage} = require('./errors'); -const exampleConfig = require('./exampleConfig'); -const validationCondition = require('./condition'); -const {ERROR, DEPRECATION, WARNING} = require('./utils'); +import {deprecationWarning} from './deprecated'; +import {unknownOptionWarning} from './warnings'; +import {errorMessage} from './errors'; +import exampleConfig from './exampleConfig'; +import validationCondition from './condition'; +import {ERROR, DEPRECATION, WARNING} from './utils'; module.exports = ({ comment: '', diff --git a/packages/jest-validate/src/deprecated.js b/packages/jest-validate/src/deprecated.js index 2d782eacc66a..22f42c1e0dad 100644 --- a/packages/jest-validate/src/deprecated.js +++ b/packages/jest-validate/src/deprecated.js @@ -10,7 +10,7 @@ import type {ValidationOptions} from './types'; -const {logValidationWarning, DEPRECATION} = require('./utils'); +import {logValidationWarning, DEPRECATION} from './utils'; const deprecationMessage = (message: string, options: ValidationOptions) => { const comment = options.comment; diff --git a/packages/jest-validate/src/errors.js b/packages/jest-validate/src/errors.js index d76b92b98b62..fe34f56167b1 100644 --- a/packages/jest-validate/src/errors.js +++ b/packages/jest-validate/src/errors.js @@ -10,9 +10,9 @@ import type {ValidationOptions} from './types'; -const chalk = require('chalk'); -const getType = require('jest-get-type'); -const {format, ValidationError, ERROR} = require('./utils'); +import chalk from 'chalk'; +import getType from 'jest-get-type'; +import {format, ValidationError, ERROR} from './utils'; const errorMessage = ( option: string, diff --git a/packages/jest-validate/src/utils.js b/packages/jest-validate/src/utils.js index 0ebe0cc2af0d..ffdd4ac8a7d5 100644 --- a/packages/jest-validate/src/utils.js +++ b/packages/jest-validate/src/utils.js @@ -8,7 +8,8 @@ * @flow */ -const chalk = require('chalk'); +import chalk from 'chalk'; + const BULLET: string = chalk.bold('\u25cf'); const DEPRECATION = `${BULLET} Deprecation Warning`; const ERROR = `${BULLET} Validation Error`; diff --git a/packages/jest-validate/src/validate.js b/packages/jest-validate/src/validate.js index 4ebf7fae8bc0..3074cd12bb3d 100644 --- a/packages/jest-validate/src/validate.js +++ b/packages/jest-validate/src/validate.js @@ -10,7 +10,7 @@ import type {ValidationOptions} from './types'; -const defaultConfig = require('./defaultConfig'); +import defaultConfig from './defaultConfig'; const _validate = (config: Object, options: ValidationOptions) => { let hasDeprecationWarnings = false; diff --git a/packages/jest-validate/src/warnings.js b/packages/jest-validate/src/warnings.js index a093230f3017..f5d184d7f70a 100644 --- a/packages/jest-validate/src/warnings.js +++ b/packages/jest-validate/src/warnings.js @@ -10,13 +10,13 @@ import type {ValidationOptions} from './types'; -const chalk = require('chalk'); -const { +import chalk from 'chalk'; +import { format, logValidationWarning, createDidYouMeanMessage, WARNING, -} = require('./utils'); +} from './utils'; const unknownOptionWarning = ( config: Object, diff --git a/packages/jest/bin/jest.js b/packages/jest/bin/jest.js index c37fdf60b25c..d97816d84280 100755 --- a/packages/jest/bin/jest.js +++ b/packages/jest/bin/jest.js @@ -7,4 +7,4 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -require('jest-cli/bin/jest'); +import 'jest-cli/bin/jest'; diff --git a/packages/pretty-format/perf/test.js b/packages/pretty-format/perf/test.js index 52e73dc15438..44ef79c29c0f 100644 --- a/packages/pretty-format/perf/test.js +++ b/packages/pretty-format/perf/test.js @@ -6,14 +6,15 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -const util = require('util'); -const chalk = require('chalk'); -const React = require('react'); -const ReactTestRenderer = require('react-test-renderer'); -const leftPad = require('left-pad'); -const prettyFormat = require('../build'); -const ReactTestComponent = require('../build/plugins/ReactTestComponent'); -const worldGeoJson = require('./world.geo.json'); +import util from 'util'; + +import chalk from 'chalk'; +import React from 'react'; +import ReactTestRenderer from 'react-test-renderer'; +import leftPad from 'left-pad'; +import prettyFormat from '../build'; +import ReactTestComponent from '../build/plugins/ReactTestComponent'; +import worldGeoJson from './world.geo.json'; const NANOSECONDS = 1000000000; let TIMES_TO_RUN = 100000; diff --git a/packages/pretty-format/src/index.js b/packages/pretty-format/src/index.js index fff2a626832e..f01fdba64168 100644 --- a/packages/pretty-format/src/index.js +++ b/packages/pretty-format/src/index.js @@ -16,7 +16,7 @@ import type { Options, } from 'types/PrettyFormat'; -const style = require('ansi-styles'); +import style from 'ansi-styles'; type Theme = {| comment?: string, diff --git a/packages/pretty-format/src/plugins/ConvertAnsi.js b/packages/pretty-format/src/plugins/ConvertAnsi.js index eb6f83e1a6b6..27011715c574 100644 --- a/packages/pretty-format/src/plugins/ConvertAnsi.js +++ b/packages/pretty-format/src/plugins/ConvertAnsi.js @@ -10,7 +10,7 @@ import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; -const ansiRegex = require('ansi-regex'); +import ansiRegex from 'ansi-regex'; const toHumanReadableAnsi = text => { const style = require('ansi-styles'); diff --git a/packages/pretty-format/src/plugins/HTMLElement.js b/packages/pretty-format/src/plugins/HTMLElement.js index 620fe91e1b54..a30fb88f4c35 100644 --- a/packages/pretty-format/src/plugins/HTMLElement.js +++ b/packages/pretty-format/src/plugins/HTMLElement.js @@ -10,7 +10,7 @@ import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; -const escapeHTML = require('./lib/escapeHTML'); +import escapeHTML from './lib/escapeHTML'; type Attribute = { name: string, diff --git a/packages/pretty-format/src/plugins/ImmutableList.js b/packages/pretty-format/src/plugins/ImmutableList.js index 6af8dda5ec08..a9a957d415ba 100644 --- a/packages/pretty-format/src/plugins/ImmutableList.js +++ b/packages/pretty-format/src/plugins/ImmutableList.js @@ -10,7 +10,7 @@ import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; -const printImmutable = require('./lib/printImmutable'); +import printImmutable from './lib/printImmutable'; const IS_LIST = '@@__IMMUTABLE_LIST__@@'; const test = (maybeList: any) => !!(maybeList && maybeList[IS_LIST]); diff --git a/packages/pretty-format/src/plugins/ImmutableMap.js b/packages/pretty-format/src/plugins/ImmutableMap.js index b12fe5a8eea5..e311985aada8 100644 --- a/packages/pretty-format/src/plugins/ImmutableMap.js +++ b/packages/pretty-format/src/plugins/ImmutableMap.js @@ -10,7 +10,7 @@ import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; -const printImmutable = require('./lib/printImmutable'); +import printImmutable from './lib/printImmutable'; const IS_MAP = '@@__IMMUTABLE_MAP__@@'; const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@'; diff --git a/packages/pretty-format/src/plugins/ImmutableOrderedMap.js b/packages/pretty-format/src/plugins/ImmutableOrderedMap.js index 0d16e21e98fd..c51199ed2882 100644 --- a/packages/pretty-format/src/plugins/ImmutableOrderedMap.js +++ b/packages/pretty-format/src/plugins/ImmutableOrderedMap.js @@ -10,7 +10,7 @@ import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; -const printImmutable = require('./lib/printImmutable'); +import printImmutable from './lib/printImmutable'; const IS_MAP = '@@__IMMUTABLE_MAP__@@'; const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@'; diff --git a/packages/pretty-format/src/plugins/ImmutableOrderedSet.js b/packages/pretty-format/src/plugins/ImmutableOrderedSet.js index 4fe8f5c8e81b..88763fd78866 100644 --- a/packages/pretty-format/src/plugins/ImmutableOrderedSet.js +++ b/packages/pretty-format/src/plugins/ImmutableOrderedSet.js @@ -10,7 +10,7 @@ import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; -const printImmutable = require('./lib/printImmutable'); +import printImmutable from './lib/printImmutable'; const IS_SET = '@@__IMMUTABLE_SET__@@'; const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@'; diff --git a/packages/pretty-format/src/plugins/ImmutableSet.js b/packages/pretty-format/src/plugins/ImmutableSet.js index 21cf405503c6..74005a69c471 100644 --- a/packages/pretty-format/src/plugins/ImmutableSet.js +++ b/packages/pretty-format/src/plugins/ImmutableSet.js @@ -10,7 +10,7 @@ import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; -const printImmutable = require('./lib/printImmutable'); +import printImmutable from './lib/printImmutable'; const IS_SET = '@@__IMMUTABLE_SET__@@'; const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@'; diff --git a/packages/pretty-format/src/plugins/ImmutableStack.js b/packages/pretty-format/src/plugins/ImmutableStack.js index 06a54a3ee099..110400e8a996 100644 --- a/packages/pretty-format/src/plugins/ImmutableStack.js +++ b/packages/pretty-format/src/plugins/ImmutableStack.js @@ -10,7 +10,7 @@ import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; -const printImmutable = require('./lib/printImmutable'); +import printImmutable from './lib/printImmutable'; const IS_STACK = '@@__IMMUTABLE_STACK__@@'; const test = (maybeStack: any) => !!(maybeStack && maybeStack[IS_STACK]); diff --git a/packages/pretty-format/src/plugins/ReactElement.js b/packages/pretty-format/src/plugins/ReactElement.js index efd8abe4f477..899e46e9824f 100644 --- a/packages/pretty-format/src/plugins/ReactElement.js +++ b/packages/pretty-format/src/plugins/ReactElement.js @@ -10,7 +10,7 @@ import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; -const escapeHTML = require('./lib/escapeHTML'); +import escapeHTML from './lib/escapeHTML'; const reactElement = Symbol.for('react.element'); diff --git a/packages/pretty-format/src/plugins/ReactTestComponent.js b/packages/pretty-format/src/plugins/ReactTestComponent.js index 21a0abc3a480..97ca3be3d53e 100644 --- a/packages/pretty-format/src/plugins/ReactTestComponent.js +++ b/packages/pretty-format/src/plugins/ReactTestComponent.js @@ -18,7 +18,7 @@ import type { ReactTestChild, } from 'types/PrettyFormat'; -const escapeHTML = require('./lib/escapeHTML'); +import escapeHTML from './lib/escapeHTML'; const reactTestInstance = Symbol.for('react.test.json'); diff --git a/yarn.lock b/yarn.lock index cb4621e295ac..41f0bdecf7e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -611,6 +611,13 @@ babel-plugin-transform-flow-strip-types@^6.18.0, babel-plugin-transform-flow-str babel-plugin-syntax-flow "^6.18.0" babel-runtime "^6.22.0" +babel-plugin-transform-inline-imports-commonjs@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-imports-commonjs/-/babel-plugin-transform-inline-imports-commonjs-1.2.0.tgz#20c7d192bafc54c8727386e3387d8ee4ef19e6a5" + dependencies: + babel-plugin-transform-strict-mode "^6.8.0" + builtin-modules "^1.1.1" + babel-plugin-transform-object-assign@^6.5.0: version "6.22.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-assign/-/babel-plugin-transform-object-assign-6.22.0.tgz#f99d2f66f1a0b0d498e346c5359684740caa20ba" @@ -664,7 +671,7 @@ babel-plugin-transform-runtime@^6.23.0: dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-strict-mode@^6.24.1: +babel-plugin-transform-strict-mode@^6.24.1, babel-plugin-transform-strict-mode@^6.8.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" dependencies: From 5d928b17a1815f770c8fca60c37be93eb20aa3ea Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 9 Jun 2017 16:17:53 +0200 Subject: [PATCH 2/4] [squash] specify correct babel plugin for import transpilation --- package.json | 2 +- yarn.lock | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index f42d56b8bea8..78f706f9574b 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "babel-plugin-syntax-trailing-function-commas": "^6.13.0", "babel-plugin-transform-async-to-generator": "^6.16.0", "babel-plugin-transform-es2015-destructuring": "^6.23.0", + "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1", "babel-plugin-transform-es2015-parameters": "^6.23.0", "babel-plugin-transform-flow-strip-types": "^6.18.0", - "babel-plugin-transform-inline-imports-commonjs": "^1.2.0", "babel-plugin-transform-runtime": "^6.23.0", "babel-plugin-transform-strict-mode": "^6.24.1", "babel-preset-env": "^1.4.0", diff --git a/yarn.lock b/yarn.lock index 41f0bdecf7e3..cb4621e295ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -611,13 +611,6 @@ babel-plugin-transform-flow-strip-types@^6.18.0, babel-plugin-transform-flow-str babel-plugin-syntax-flow "^6.18.0" babel-runtime "^6.22.0" -babel-plugin-transform-inline-imports-commonjs@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-imports-commonjs/-/babel-plugin-transform-inline-imports-commonjs-1.2.0.tgz#20c7d192bafc54c8727386e3387d8ee4ef19e6a5" - dependencies: - babel-plugin-transform-strict-mode "^6.8.0" - builtin-modules "^1.1.1" - babel-plugin-transform-object-assign@^6.5.0: version "6.22.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-assign/-/babel-plugin-transform-object-assign-6.22.0.tgz#f99d2f66f1a0b0d498e346c5359684740caa20ba" @@ -671,7 +664,7 @@ babel-plugin-transform-runtime@^6.23.0: dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-strict-mode@^6.24.1, babel-plugin-transform-strict-mode@^6.8.0: +babel-plugin-transform-strict-mode@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" dependencies: From ecdef174b8cab53abd1c42d383c3b8251210bf06 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 9 Jun 2017 16:26:57 +0200 Subject: [PATCH 3/4] [squash] specify correct babel plugin for import transpilation in babelrc --- .babelrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.babelrc b/.babelrc index 54c65a8e065c..d3202c6557ea 100644 --- a/.babelrc +++ b/.babelrc @@ -6,7 +6,7 @@ "transform-es2015-parameters", "transform-async-to-generator", "transform-strict-mode", - ["transform-inline-imports-commonjs", {"allowTopLevelThis": true}] + ["transform-es2015-modules-commonjs", {"allowTopLevelThis": true}] ], "retainLines": true } From ca3b650a2c2e1e9a55fd40a85f17a3d32f6a1999 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 9 Jun 2017 16:52:58 +0200 Subject: [PATCH 4/4] trigger ci