From 5816a575889579b2d9f610fb4e2bdf0020e3245d Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Tue, 26 Mar 2019 11:32:14 +0100 Subject: [PATCH 1/2] remove flow leftovers (#8213) --- .circleci/config.yml | 1 - e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap | 2 +- .../__snapshots__/resolveNoFileExtensions.test.ts.snap | 2 +- packages/expect/src/jasmineUtils.ts | 4 ---- packages/jest-cli/src/init/__tests__/init.test.js | 4 ---- packages/jest-config/src/setFromArgv.ts | 1 - packages/jest-jasmine2/src/assertionErrorMessage.ts | 1 - packages/jest-jasmine2/src/index.ts | 1 - packages/jest-jasmine2/src/setup_jest_globals.ts | 1 - packages/jest-resolve/src/index.ts | 3 +-- packages/jest-util/src/deepCyclicCopy.ts | 1 - packages/jest-worker/src/WorkerPool.ts | 1 - packages/jest-worker/src/workers/processChild.ts | 1 - 13 files changed, 3 insertions(+), 20 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ac2e90961811..323151353c34 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,6 @@ jobs: - restore-cache: *restore-cache - run: yarn --no-progress --frozen-lockfile - save-cache: *save-cache - - run: echo server.max_workers=1 >> .flowconfig - run: yarn lint --format junit -o reports/junit/js-lint-results.xml && yarn lint-es5-build --format junit -o reports/junit/js-es5-lint-results.xml && yarn lint:md:ci && yarn check-copyright-headers - store_test_results: path: reports/junit diff --git a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap index 5d1dc26353f5..35faae772b9c 100644 --- a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap +++ b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap @@ -30,6 +30,6 @@ FAIL __tests__/index.js 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:474:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:473:17) at Object.require (index.js:10:1) `; diff --git a/e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap b/e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap index 73905d202b50..e71f3bc23997 100644 --- a/e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap +++ b/e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap @@ -33,6 +33,6 @@ FAIL __tests__/test.js | ^ 4 | - at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:232:17) + at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:231:17) at Object.require (index.js:3:18) `; diff --git a/packages/expect/src/jasmineUtils.ts b/packages/expect/src/jasmineUtils.ts index a28db744dee1..8c98416fbd66 100644 --- a/packages/expect/src/jasmineUtils.ts +++ b/packages/expect/src/jasmineUtils.ts @@ -50,7 +50,6 @@ function asymmetricMatch(a: any, b: any) { } if (asymmetricA) { - // $FlowFixMe – Flow sees `a` as a number return a.asymmetricMatch(b); } @@ -103,7 +102,6 @@ function eq( case '[object String]': // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is // equivalent to `new String("5")`. - // $FlowFixMe – Flow sees `a` as a number return a == String(b); case '[object Number]': return Object.is(Number(a), Number(b)); @@ -119,7 +117,6 @@ function eq( a.source == b.source && a.global == b.global && a.multiline == b.multiline && - // $FlowFixMe – Flow sees `a` as a number a.ignoreCase == b.ignoreCase ); } @@ -210,7 +207,6 @@ function keys( } return keys.concat( (Object.getOwnPropertySymbols(o) as Array).filter( - //$FlowFixMe Jest complains about nullability, but we know for sure that property 'symbol' does exist. symbol => (Object.getOwnPropertyDescriptor(o, symbol) as any).enumerable, ), diff --git a/packages/jest-cli/src/init/__tests__/init.test.js b/packages/jest-cli/src/init/__tests__/init.test.js index 65a8128b36b6..73cd5168c866 100644 --- a/packages/jest-cli/src/init/__tests__/init.test.js +++ b/packages/jest-cli/src/init/__tests__/init.test.js @@ -25,17 +25,13 @@ const consoleLog = console.log; describe('init', () => { beforeEach(() => { - // $FlowFixMe mock console.log to reduce noise from the tests console.log = jest.fn(); - // $FlowFixMe mock fs.writeFileSync = jest.fn(); }); afterEach(() => { jest.clearAllMocks(); - // $FlowFixMe console.log = consoleLog; - // $FlowFixMe mock fs.writeFileSync = writeFileSync; }); diff --git a/packages/jest-config/src/setFromArgv.ts b/packages/jest-config/src/setFromArgv.ts index 8ae4aa11c4b1..b7f90b6de1d4 100644 --- a/packages/jest-config/src/setFromArgv.ts +++ b/packages/jest-config/src/setFromArgv.ts @@ -14,7 +14,6 @@ export default function setFromArgv( options: Config.InitialOptions, argv: Config.Argv, ): Config.InitialOptions { - // $FlowFixMe: Seems like flow doesn't approve of string values const argvToOptions = Object.keys(argv) .filter(key => argv[key] !== undefined && specialArgs.indexOf(key) === -1) .reduce((options: {[key: string]: unknown}, key) => { diff --git a/packages/jest-jasmine2/src/assertionErrorMessage.ts b/packages/jest-jasmine2/src/assertionErrorMessage.ts index 3a5e6761ec84..8e83b4241df9 100644 --- a/packages/jest-jasmine2/src/assertionErrorMessage.ts +++ b/packages/jest-jasmine2/src/assertionErrorMessage.ts @@ -47,7 +47,6 @@ const getOperatorName = (operator: string | null, stack: string) => { const operatorMessage = (operator: string | null) => { const niceOperatorName = getOperatorName(operator, ''); - // $FlowFixMe: we default to the operator itself, so holes in the map doesn't matter const humanReadableOperator = humanReadableOperators[niceOperatorName]; return typeof operator === 'string' diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index d1bce2deaac0..1860ad51bf96 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -127,7 +127,6 @@ async function jasmine2( if (globalConfig.errorOnDeprecated) { installErrorOnPrivate(environment.global); } else { - // $FlowFixMe Flow seems to be confused about accessors and tries to enforce having a `value` property. Object.defineProperty(jasmine, 'DEFAULT_TIMEOUT_INTERVAL', { configurable: true, enumerable: true, diff --git a/packages/jest-jasmine2/src/setup_jest_globals.ts b/packages/jest-jasmine2/src/setup_jest_globals.ts index cff86b27cb45..9da4aa850bb9 100644 --- a/packages/jest-jasmine2/src/setup_jest_globals.ts +++ b/packages/jest-jasmine2/src/setup_jest_globals.ts @@ -105,7 +105,6 @@ export default ({ expand, getBabelTraverse: () => require('@babel/traverse').default, getPrettier: () => - // $FlowFixMe dynamic require config.prettierPath ? require(config.prettierPath) : null, updateSnapshot, }); diff --git a/packages/jest-resolve/src/index.ts b/packages/jest-resolve/src/index.ts index f64be27244d2..658995ce2d0a 100644 --- a/packages/jest-resolve/src/index.ts +++ b/packages/jest-resolve/src/index.ts @@ -83,8 +83,7 @@ class Resolver { options: FindNodeModuleConfig, ): Config.Path | null { const resolver = options.resolver - ? /* $FlowFixMe */ - require(options.resolver) + ? require(options.resolver) : defaultResolver; const paths = options.paths; diff --git a/packages/jest-util/src/deepCyclicCopy.ts b/packages/jest-util/src/deepCyclicCopy.ts index 465ce9f3f1e0..f1bd4ca4f1c5 100644 --- a/packages/jest-util/src/deepCyclicCopy.ts +++ b/packages/jest-util/src/deepCyclicCopy.ts @@ -54,7 +54,6 @@ function deepCyclicCopyObject( ? Object.create(Object.getPrototypeOf(object)) : {}; - // $FlowFixMe: Object.getOwnPropertyDescriptors is polyfilled above. const descriptors = Object.getOwnPropertyDescriptors(object); cycles.set(object, newObject); diff --git a/packages/jest-worker/src/WorkerPool.ts b/packages/jest-worker/src/WorkerPool.ts index dd61ce4dfa8e..cd7159bfad9d 100644 --- a/packages/jest-worker/src/WorkerPool.ts +++ b/packages/jest-worker/src/WorkerPool.ts @@ -18,7 +18,6 @@ import { const canUseWorkerThreads = () => { try { - // $FlowFixMe: Flow doesn't know about experimental APIs require('worker_threads'); return true; } catch (_) { diff --git a/packages/jest-worker/src/workers/processChild.ts b/packages/jest-worker/src/workers/processChild.ts index beb395af1a22..6998b971f908 100644 --- a/packages/jest-worker/src/workers/processChild.ts +++ b/packages/jest-worker/src/workers/processChild.ts @@ -88,7 +88,6 @@ function reportError(error: Error, type: PARENT_MESSAGE_ERROR) { error.constructor && error.constructor.name, error.message, error.stack, - // $FlowFixMe: this is safe to just inherit from Object. typeof error === 'object' ? {...error} : error, ]); } From 54ce3f3ad11677d40af6091ce70d8afbde8ee2aa Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Tue, 26 Mar 2019 11:42:28 +0100 Subject: [PATCH 2/2] fix 1-indexed JEST_WORKER_ID (#8205) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fixes #8204 It's weird that it's 1-indexed (I looked at making our `workerId` 1-indexed too for consistency, but that would make our code really weird), but I guess it's documented, used to work like that and still does for `runInBand` 🤷‍♂️ ## Test plan --- CHANGELOG.md | 1 + packages/jest-worker/src/workers/ChildProcessWorker.ts | 2 +- packages/jest-worker/src/workers/NodeThreadsWorker.ts | 2 +- .../src/workers/__tests__/ChildProcessWorker.test.js | 6 +++--- .../src/workers/__tests__/NodeThreadsWorker.test.js | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 944c19d56f65..45fab0ee4a6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - `[pretty-format]` Print `BigInt` as a readable number instead of `{}` ([#8138](https://github.com/facebook/jest/pull/8138)) - `[jest-core]` Fix ability to transform dependencies required from globalSetup script [#8143](https://github.com/facebook/jest/pull/8143) - `[@jest/reporters]` Fix Cannot read property converageData of null ([#8168](https://github.com/facebook/jest/pull/8168)) +- `[jest-worker]` `JEST_WORKER_ID` starts at 1 ([#8205](https://github.com/facebook/jest/pull/8205)) ### Chore & Maintenance diff --git a/packages/jest-worker/src/workers/ChildProcessWorker.ts b/packages/jest-worker/src/workers/ChildProcessWorker.ts index 2b540c762c7c..d58197781cca 100644 --- a/packages/jest-worker/src/workers/ChildProcessWorker.ts +++ b/packages/jest-worker/src/workers/ChildProcessWorker.ts @@ -67,7 +67,7 @@ export default class ChildProcessWorker implements WorkerInterface { cwd: process.cwd(), env: { ...process.env, - JEST_WORKER_ID: String(this._options.workerId), + JEST_WORKER_ID: String(this._options.workerId + 1), // 0-indexed workerId, 1-indexed JEST_WORKER_ID ...forceColor, } as NodeJS.ProcessEnv, // Suppress --debug / --inspect flags while preserving others (like --harmony). diff --git a/packages/jest-worker/src/workers/NodeThreadsWorker.ts b/packages/jest-worker/src/workers/NodeThreadsWorker.ts index 45d748e40e8a..b76f1ee89037 100644 --- a/packages/jest-worker/src/workers/NodeThreadsWorker.ts +++ b/packages/jest-worker/src/workers/NodeThreadsWorker.ts @@ -54,7 +54,7 @@ export default class ExperimentalWorker implements WorkerInterface { cwd: process.cwd(), env: { ...process.env, - JEST_WORKER_ID: String(this._options.workerId), + JEST_WORKER_ID: String(this._options.workerId + 1), // 0-indexed workerId, 1-indexed JEST_WORKER_ID } as NodeJS.ProcessEnv, // Suppress --debug / --inspect flags while preserving others (like --harmony). execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)), diff --git a/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js b/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js index 8b1e2fad4c35..cce114d6f991 100644 --- a/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js +++ b/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js @@ -58,7 +58,7 @@ it('passes fork options down to child_process.fork, adding the defaults', () => execPath: 'hello', }, maxRetries: 3, - workerId: process.env.JEST_WORKER_ID, + workerId: process.env.JEST_WORKER_ID - 1, workerPath: '/tmp/foo/bar/baz.js', }); @@ -72,7 +72,7 @@ it('passes fork options down to child_process.fork, adding the defaults', () => }); }); -it('passes workerId to the child process and assign it to env.JEST_WORKER_ID', () => { +it('passes workerId to the child process and assign it to 1-indexed env.JEST_WORKER_ID', () => { new Worker({ forkOptions: {}, maxRetries: 3, @@ -80,7 +80,7 @@ it('passes workerId to the child process and assign it to env.JEST_WORKER_ID', ( workerPath: '/tmp/foo', }); - expect(childProcess.fork.mock.calls[0][2].env.JEST_WORKER_ID).toEqual('2'); + expect(childProcess.fork.mock.calls[0][2].env.JEST_WORKER_ID).toEqual('3'); }); it('initializes the child process with the given workerPath', () => { diff --git a/packages/jest-worker/src/workers/__tests__/NodeThreadsWorker.test.js b/packages/jest-worker/src/workers/__tests__/NodeThreadsWorker.test.js index 998f12c1f808..d729a7661cc6 100644 --- a/packages/jest-worker/src/workers/__tests__/NodeThreadsWorker.test.js +++ b/packages/jest-worker/src/workers/__tests__/NodeThreadsWorker.test.js @@ -63,7 +63,7 @@ it('passes fork options down to child_process.fork, adding the defaults', () => execPath: 'hello', }, maxRetries: 3, - workerId: process.env.JEST_WORKER_ID, + workerId: process.env.JEST_WORKER_ID - 1, workerPath: '/tmp/foo/bar/baz.js', }); @@ -91,7 +91,7 @@ it('passes workerId to the child process and assign it to env.JEST_WORKER_ID', ( }); expect(childProcess.mock.calls[0][1].workerData.env.JEST_WORKER_ID).toEqual( - '2', + '3', ); });