Skip to content

Commit

Permalink
Upgrade Flow to 0.70 (#6010)
Browse files Browse the repository at this point in the history
* Upgrade Flow to 0.70

* adjust test_worker format error type
  • Loading branch information
thymikee authored and cpojer committed Apr 17, 2018
1 parent 9e687b4 commit 3ce8743
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ include_warnings=true
emoji=true

[version]
^0.66.0
^0.70.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/spy_matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/haste_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class HasteFS {
return !!this._files[file];
}

getAllFiles() {
getAllFiles(): Array<string> {
return Object.keys(this._files);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/jest-haste-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ class HasteMap extends EventEmitter {
_cleanup() {
const worker = this._worker;

// $FlowFixMe
if (worker && typeof worker.end === 'function') {
worker.end();
}
Expand Down Expand Up @@ -726,7 +727,6 @@ class HasteMap extends EventEmitter {

if (mustCopy) {
mustCopy = false;
// $FlowFixMe
hasteMap = {
clocks: copy(hasteMap.clocks),
duplicates: copy(hasteMap.duplicates),
Expand Down Expand Up @@ -755,7 +755,6 @@ class HasteMap extends EventEmitter {
if (Object.keys(moduleMap).length === 0) {
delete hasteMap.map[moduleName];
} else {
// $FlowFixMe
hasteMap.map[moduleName] = moduleMap;
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-mock/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function getSlots(object?: Object): Array<string> {
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;
}
}
Expand Down Expand Up @@ -801,7 +801,9 @@ class ModuleMockerClass {
}

descriptor[accessType] = this._makeComponent({type: 'function'}, () => {
// $FlowFixMe
descriptor[accessType] = original;
// $FlowFixMe
Object.defineProperty(obj, propertyName, descriptor);
});

Expand Down
16 changes: 5 additions & 11 deletions packages/jest-resolve/src/default_resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-resolve/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-runner/src/test_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-runtime/src/script_transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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' &&
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-serializer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
ReactTestComponent,
} = prettyFormat.plugins;

let PLUGINS = [
let PLUGINS: Array<Plugin> = [
ReactTestComponent,
ReactElement,
DOMElement,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-util/src/deep_cyclic_copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-util/src/fake_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,6 @@ export default class FakeTimers<TimerRef> {

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;
Expand Down
13 changes: 10 additions & 3 deletions types/Argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>,
collectCoverageOnlyFrom: Array<string>,
Expand All @@ -30,19 +31,21 @@ export type Argv = {|
coveragePathIgnorePatterns: Array<string>,
coverageReporters: Array<string>,
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<string>,
moduleFileExtensions: Array<string>,
moduleLoader: string,
Expand All @@ -57,15 +60,18 @@ export type Argv = {|
onlyChanged: boolean,
outputFile: string,
preset: ?string,
projects: Array<string>,
replname: ?string,
resetMocks: boolean,
resetModules: boolean,
resolver: ?string,
restoreMocks: boolean,
rootDir: string,
roots: Array<string>,
runInBand: boolean,
setupFiles: Array<string>,
setupTestFrameworkScriptFile: string,
showConfig: boolean,
silent: boolean,
snapshotSerializers: Array<string>,
testEnvironment: string,
Expand All @@ -81,12 +87,13 @@ export type Argv = {|
timers: 'real' | 'fake',
transform: string,
transformIgnorePatterns: Array<string>,
watchPathIgnorePatterns: Array<string>,
unmockedModulePathPatterns: ?Array<string>,
updateSnapshot: boolean,
useStderr: boolean,
verbose: ?boolean,
version: boolean,
watch: boolean,
watchAll: boolean,
watchman: boolean,
watchPathIgnorePatterns: Array<string>,
|};
2 changes: 2 additions & 0 deletions types/Errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @flow
export type ErrorWithCode = Error & {code?: string};
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3ce8743

Please sign in to comment.