diff --git a/.flowconfig b/.flowconfig index c3c9c94963d0..e6be6588c8f1 100644 --- a/.flowconfig +++ b/.flowconfig @@ -11,4 +11,4 @@ include_warnings=true emoji=true [version] -^0.66.0 +^0.70.0 diff --git a/package.json b/package.json index e2b264d89d68..b7f57436e2fb 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "eslint-plugin-prettier": "^2.3.1", "eslint-plugin-react": "^7.1.0", "eslint-plugin-relay": "~0.0.19", - "flow-bin": "^0.66.0", + "flow-bin": "^0.70.0", "glob": "^7.1.1", "graceful-fs": "^4.1.11", "immutable": "^4.0.0-rc.7", diff --git a/packages/expect/src/spy_matchers.js b/packages/expect/src/spy_matchers.js index 9294f6de3806..1b9c44fddfe0 100644 --- a/packages/expect/src/spy_matchers.js +++ b/packages/expect/src/spy_matchers.js @@ -248,7 +248,7 @@ const formatReceivedCalls = (calls, limit, options) => { const count = calls.length - limit; const printedCalls = getPrintedCalls(calls, limit, ', ', printReceived); return ( - `${but} it was ${options && options.isLast ? 'last ' : ''}called ` + + `${but} it was called ` + `with:\n ` + printedCalls + (count > 0 diff --git a/packages/jest-haste-map/src/haste_fs.js b/packages/jest-haste-map/src/haste_fs.js index 7f09f9f40098..5c2bd588bf92 100644 --- a/packages/jest-haste-map/src/haste_fs.js +++ b/packages/jest-haste-map/src/haste_fs.js @@ -37,7 +37,7 @@ export default class HasteFS { return !!this._files[file]; } - getAllFiles() { + getAllFiles(): Array { return Object.keys(this._files); } diff --git a/packages/jest-haste-map/src/index.js b/packages/jest-haste-map/src/index.js index 74e6feb79e41..8637caa1956a 100644 --- a/packages/jest-haste-map/src/index.js +++ b/packages/jest-haste-map/src/index.js @@ -542,6 +542,7 @@ class HasteMap extends EventEmitter { _cleanup() { const worker = this._worker; + // $FlowFixMe if (worker && typeof worker.end === 'function') { worker.end(); } @@ -726,7 +727,6 @@ class HasteMap extends EventEmitter { if (mustCopy) { mustCopy = false; - // $FlowFixMe hasteMap = { clocks: copy(hasteMap.clocks), duplicates: copy(hasteMap.duplicates), @@ -755,7 +755,6 @@ class HasteMap extends EventEmitter { if (Object.keys(moduleMap).length === 0) { delete hasteMap.map[moduleName]; } else { - // $FlowFixMe hasteMap.map[moduleName] = moduleMap; } } diff --git a/packages/jest-mock/src/index.js b/packages/jest-mock/src/index.js index f99aad8c144e..69a02a4860cf 100644 --- a/packages/jest-mock/src/index.js +++ b/packages/jest-mock/src/index.js @@ -225,7 +225,7 @@ function getSlots(object?: Object): Array { const prop = ownNames[i]; if (!isReadonlyProp(object, prop)) { const propDesc = Object.getOwnPropertyDescriptor(object, prop); - if (!propDesc.get || object.__esModule) { + if ((propDesc !== undefined && !propDesc.get) || object.__esModule) { slots[prop] = true; } } @@ -801,7 +801,9 @@ class ModuleMockerClass { } descriptor[accessType] = this._makeComponent({type: 'function'}, () => { + // $FlowFixMe descriptor[accessType] = original; + // $FlowFixMe Object.defineProperty(obj, propertyName, descriptor); }); diff --git a/packages/jest-resolve/src/default_resolver.js b/packages/jest-resolve/src/default_resolver.js index 72f5706d4aa8..ae85c4e888d8 100644 --- a/packages/jest-resolve/src/default_resolver.js +++ b/packages/jest-resolve/src/default_resolver.js @@ -8,8 +8,13 @@ */ import type {Path} from 'types/Config'; +import type {ErrorWithCode} from 'types/Errors'; import browserResolve from 'browser-resolve'; +import fs from 'fs'; +import path from 'path'; +import isBuiltinModule from './is_builtin_module'; +import nodeModulesPaths from './node_modules_paths'; type ResolverOptions = {| basedir: Path, @@ -35,17 +40,6 @@ export default function defaultResolver( }); } -/* - * Adapted from: https://github.com/substack/node-resolve - */ -type ErrorWithCode = Error & {code?: string}; - -import fs from 'fs'; -import path from 'path'; -import isBuiltinModule from './is_builtin_module'; - -import nodeModulesPaths from './node_modules_paths'; - const REGEX_RELATIVE_IMPORT = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[\\\/])/; function resolveSync(target: Path, options: ResolverOptions): Path { diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index c3dba0ea3685..8687878d83e5 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -10,6 +10,7 @@ import type {Path} from 'types/Config'; import type {ModuleMap} from 'types/HasteMap'; import type {ResolveModuleConfig} from 'types/Resolve'; +import type {ErrorWithCode} from 'types/Errors'; import fs from 'fs'; import path from 'path'; @@ -194,7 +195,7 @@ class Resolver { const err = new Error( `Cannot find module '${moduleName}' from '${relativePath || '.'}'`, ); - (err: Error & {code?: string}).code = 'MODULE_NOT_FOUND'; + (err: ErrorWithCode).code = 'MODULE_NOT_FOUND'; throw err; } diff --git a/packages/jest-runner/src/test_worker.js b/packages/jest-runner/src/test_worker.js index b482756c0530..5b178df03a4b 100644 --- a/packages/jest-runner/src/test_worker.js +++ b/packages/jest-runner/src/test_worker.js @@ -10,6 +10,7 @@ import type {GlobalConfig, Path, ProjectConfig} from 'types/Config'; import type {SerializableError, TestResult} from 'types/TestResult'; import type {RawModuleMap} from 'types/HasteMap'; +import type {ErrorWithCode} from 'types/Errors'; import exit from 'exit'; import HasteMap from 'jest-haste-map'; @@ -30,7 +31,7 @@ process.on('uncaughtException', err => { exit(1); }); -const formatError = (error: string | Error): SerializableError => { +const formatError = (error: string | ErrorWithCode): SerializableError => { if (typeof error === 'string') { const {message, stack} = separateMessageFromStack(error); return { diff --git a/packages/jest-runtime/src/script_transformer.js b/packages/jest-runtime/src/script_transformer.js index 43604830a335..45026af2dd33 100644 --- a/packages/jest-runtime/src/script_transformer.js +++ b/packages/jest-runtime/src/script_transformer.js @@ -13,6 +13,7 @@ import type { TransformedSource, TransformResult, } from 'types/Transform'; +import type {ErrorWithCode} from 'types/Errors'; import crypto from 'crypto'; import path from 'path'; @@ -435,7 +436,7 @@ const writeCacheFile = (cachePath: Path, fileData: string) => { * If the target file exists we can be reasonably sure another process has * legitimately won a cache write race and ignore the error. */ -const cacheWriteErrorSafeToIgnore = (e: Error, cachePath: Path) => { +const cacheWriteErrorSafeToIgnore = (e: ErrorWithCode, cachePath: Path) => { return ( process.platform === 'win32' && e.code === 'EPERM' && diff --git a/packages/jest-serializer/src/index.js b/packages/jest-serializer/src/index.js index ff40f1c3724c..eae58cd32022 100644 --- a/packages/jest-serializer/src/index.js +++ b/packages/jest-serializer/src/index.js @@ -132,12 +132,14 @@ function jsonParse(content) { // In memory functions. export function deserialize(buffer: Buffer): any { + // $FlowFixMe - Node 8+ only return v8.deserialize ? v8.deserialize(buffer) : jsonParse(buffer.toString('utf8')); } export function serialize(content: any): Buffer { + // $FlowFixMe - Node 8+ only return v8.serialize ? v8.serialize(content) : Buffer.from(jsonStringify(content)); @@ -146,12 +148,14 @@ export function serialize(content: any): Buffer { // Synchronous filesystem functions. export function readFileSync(filePath: Path): any { + // $FlowFixMe - Node 8+ only return v8.deserialize ? v8.deserialize(fs.readFileSync(filePath)) : jsonParse(fs.readFileSync(filePath, 'utf8')); } export function writeFileSync(filePath: Path, content: any) { + // $FlowFixMe - Node 8+ only return v8.serialize ? fs.writeFileSync(filePath, v8.serialize(content)) : fs.writeFileSync(filePath, jsonStringify(content), 'utf8'); diff --git a/packages/jest-snapshot/src/plugins.js b/packages/jest-snapshot/src/plugins.js index b561f7eb88b6..de9df49e1e3a 100644 --- a/packages/jest-snapshot/src/plugins.js +++ b/packages/jest-snapshot/src/plugins.js @@ -20,7 +20,7 @@ const { ReactTestComponent, } = prettyFormat.plugins; -let PLUGINS = [ +let PLUGINS: Array = [ ReactTestComponent, ReactElement, DOMElement, diff --git a/packages/jest-snapshot/src/utils.js b/packages/jest-snapshot/src/utils.js index 39d6f0ae6bf0..13f907db3239 100644 --- a/packages/jest-snapshot/src/utils.js +++ b/packages/jest-snapshot/src/utils.js @@ -123,7 +123,7 @@ export const getSnapshotData = ( dirty = true; } - return {data, dirty}; + return ({data, dirty}: {data: any, dirty: boolean}); }; // Extra line breaks at the beginning and at the end of the snapshot are useful diff --git a/packages/jest-util/src/deep_cyclic_copy.js b/packages/jest-util/src/deep_cyclic_copy.js index 7c08cb82f9ea..12e63115ccef 100644 --- a/packages/jest-util/src/deep_cyclic_copy.js +++ b/packages/jest-util/src/deep_cyclic_copy.js @@ -14,7 +14,7 @@ export type DeepCyclicCopyOptions = {| keepPrototype: boolean, |}; -// Node 6 does not have gOPDs, so we define a simple polyfill for it. +// $FlowFixMe: Node 6 does not have gOPDs, so we define a simple polyfill for it. if (!Object.getOwnPropertyDescriptors) { // $FlowFixMe: polyfill Object.getOwnPropertyDescriptors = obj => { diff --git a/packages/jest-util/src/fake_timers.js b/packages/jest-util/src/fake_timers.js index 044449892081..e321fa8d9a3a 100644 --- a/packages/jest-util/src/fake_timers.js +++ b/packages/jest-util/src/fake_timers.js @@ -415,9 +415,6 @@ export default class FakeTimers { const cancelledTicks = this._cancelledTicks; this._timerAPIs.nextTick(() => { - if (this._blocked) { - return; - } if (!cancelledTicks.hasOwnProperty(uuid)) { // Callback may throw, so update the map prior calling. cancelledTicks[uuid] = true; diff --git a/types/Argv.js b/types/Argv.js index 71b3388b123f..81926b868cc7 100644 --- a/types/Argv.js +++ b/types/Argv.js @@ -19,8 +19,9 @@ export type Argv = {| cacheDirectory: string, changedFilesWithAncestor: boolean, changedSince: string, - clearMocks: boolean, ci: boolean, + clearCache: boolean, + clearMocks: boolean, collectCoverage: boolean, collectCoverageFrom: Array, collectCoverageOnlyFrom: Array, @@ -30,19 +31,21 @@ export type Argv = {| coveragePathIgnorePatterns: Array, coverageReporters: Array, coverageThreshold: string, + debug: boolean, env: string, expand: boolean, findRelatedTests: boolean, forceExit: boolean, + globals: string, globalSetup: ?string, globalTeardown: ?string, - globals: string, h: boolean, haste: string, help: boolean, json: boolean, lastCommit: boolean, logHeapUsage: boolean, + maxWorkers: number, moduleDirectories: Array, moduleFileExtensions: Array, moduleLoader: string, @@ -57,6 +60,7 @@ export type Argv = {| onlyChanged: boolean, outputFile: string, preset: ?string, + projects: Array, replname: ?string, resetMocks: boolean, resetModules: boolean, @@ -64,8 +68,10 @@ export type Argv = {| restoreMocks: boolean, rootDir: string, roots: Array, + runInBand: boolean, setupFiles: Array, setupTestFrameworkScriptFile: string, + showConfig: boolean, silent: boolean, snapshotSerializers: Array, testEnvironment: string, @@ -81,12 +87,13 @@ export type Argv = {| timers: 'real' | 'fake', transform: string, transformIgnorePatterns: Array, - watchPathIgnorePatterns: Array, unmockedModulePathPatterns: ?Array, updateSnapshot: boolean, useStderr: boolean, verbose: ?boolean, + version: boolean, watch: boolean, watchAll: boolean, watchman: boolean, + watchPathIgnorePatterns: Array, |}; diff --git a/types/Errors.js b/types/Errors.js new file mode 100644 index 000000000000..0a067b013f02 --- /dev/null +++ b/types/Errors.js @@ -0,0 +1,2 @@ +// @flow +export type ErrorWithCode = Error & {code?: string}; diff --git a/yarn.lock b/yarn.lock index 7a6dae4cf82f..817adcee6586 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3685,9 +3685,9 @@ flat-cache@^1.2.1: graceful-fs "^4.1.2" write "^0.2.1" -flow-bin@^0.66.0: - version "0.66.0" - resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.66.0.tgz#a96dde7015dc3343fd552a7b4963c02be705ca26" +flow-bin@^0.70.0: + version "0.70.0" + resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.70.0.tgz#080ae83a997f2b4ddb3dc2649bf13336825292b5" flow-remove-types@^1.1.0: version "1.2.3"