From ce47c6cfb140e2dc6a44fcff0fd7b7595cfac2ed Mon Sep 17 00:00:00 2001 From: Mikhail Bodrov Date: Mon, 19 Aug 2019 13:18:34 +0300 Subject: [PATCH] Get rid of Node 6 support (#8455) --- .circleci/config.yml | 16 --- CHANGELOG.md | 1 + babel.config.js | 2 +- .../__snapshots__/failures.test.ts.snap | 4 - .../moduleNameMapper.test.ts.snap | 2 +- package.json | 2 +- packages/babel-jest/package.json | 2 +- packages/babel-plugin-jest-hoist/package.json | 2 +- packages/babel-preset-jest/package.json | 2 +- packages/diff-sequences/package.json | 2 +- packages/eslint-config-fb-strict/package.json | 2 +- packages/expect/package.json | 2 +- packages/jest-changed-files/package.json | 2 +- packages/jest-circus/package.json | 2 +- packages/jest-cli/package.json | 2 +- packages/jest-config/package.json | 2 +- packages/jest-console/package.json | 2 +- packages/jest-core/package.json | 2 +- packages/jest-diff/package.json | 2 +- packages/jest-docblock/package.json | 2 +- packages/jest-each/package.json | 2 +- packages/jest-environment-jsdom/package.json | 2 +- packages/jest-environment-node/package.json | 2 +- packages/jest-environment/package.json | 2 +- packages/jest-fake-timers/package.json | 2 +- packages/jest-get-type/package.json | 2 +- packages/jest-haste-map/package.json | 2 +- packages/jest-jasmine2/package.json | 2 +- packages/jest-leak-detector/package.json | 2 +- packages/jest-matcher-utils/package.json | 2 +- packages/jest-message-util/package.json | 2 +- packages/jest-mock/package.json | 2 +- packages/jest-phabricator/package.json | 2 +- packages/jest-regex-util/package.json | 2 +- packages/jest-repl/package.json | 2 +- packages/jest-reporters/package.json | 2 +- .../jest-resolve-dependencies/package.json | 2 +- packages/jest-resolve/package.json | 2 +- packages/jest-runner/package.json | 2 +- packages/jest-runtime/package.json | 2 +- packages/jest-serializer/package.json | 2 +- .../src/__tests__/index.test.ts | 66 ++++------- packages/jest-serializer/src/index.ts | 110 +----------------- packages/jest-snapshot/package.json | 2 +- packages/jest-source-map/package.json | 2 +- packages/jest-test-result/package.json | 2 +- packages/jest-test-sequencer/package.json | 2 +- packages/jest-transform/package.json | 2 +- packages/jest-types/package.json | 2 +- packages/jest-util/package.json | 2 +- packages/jest-util/src/deepCyclicCopy.ts | 17 --- packages/jest-validate/package.json | 2 +- packages/jest-watcher/package.json | 2 +- packages/jest-worker/package.json | 2 +- packages/jest/package.json | 2 +- packages/pretty-format/package.json | 2 +- 56 files changed, 77 insertions(+), 237 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cb4fb65c20cb..9ce011e708a8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,21 +31,6 @@ jobs: - store_test_results: path: reports/junit - test-node-6: - working_directory: ~/jest - docker: - - image: circleci/node:6 - steps: - - checkout - - restore-cache: *restore-cache - - run: *install - - save-cache: *save-cache - - run: - # react-native and react-testing-library do not work with node 6 - command: rm -rf examples/react-native examples/react-testing-library && yarn test-ci-partial - - store_test_results: - path: reports/junit - test-node-8: working_directory: ~/jest docker: @@ -133,7 +118,6 @@ workflows: build-and-deploy: jobs: - lint-and-typecheck - - test-node-6 - test-node-8 - test-node-10 - test-jest-circus diff --git a/CHANGELOG.md b/CHANGELOG.md index 085cfca36103..61373cdbbccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Chore & Maintenance +- `[*]` [**BREAKING**] Drop support for Node 6 ([#8455](https://github.com/facebook/jest/pull/8455)) - `[docs]` Fix broken link pointing to legacy JS file in "Snapshot Testing". ### Performance diff --git a/babel.config.js b/babel.config.js index d536e25277bc..2339f428b527 100644 --- a/babel.config.js +++ b/babel.config.js @@ -27,7 +27,7 @@ module.exports = { '@babel/preset-env', { shippedProposals: true, - targets: {node: 6}, + targets: {node: 8}, }, ], ], diff --git a/e2e/__tests__/__snapshots__/failures.test.ts.snap b/e2e/__tests__/__snapshots__/failures.test.ts.snap index 058132cbe250..a2e434a385c4 100644 --- a/e2e/__tests__/__snapshots__/failures.test.ts.snap +++ b/e2e/__tests__/__snapshots__/failures.test.ts.snap @@ -774,10 +774,6 @@ FAIL __tests__/assertionError.test.js 82 | at Object.equal (__tests__/assertionError.test.js:80:10) - at asyncGeneratorStep (__tests__/assertionError.test.js:10:103) - at _next (__tests__/assertionError.test.js:12:194) - at __tests__/assertionError.test.js:12:364 - at Object. (__tests__/assertionError.test.js:12:97) `; exports[`works with snapshot failures 1`] = ` diff --git a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap index ea665336aff0..6e290c9ca7bc 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:493:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:468:17) at Object.require (index.js:10:1) `; diff --git a/package.json b/package.json index fe7b1c2e6eee..0c7f692bc3f4 100644 --- a/package.json +++ b/package.json @@ -139,6 +139,6 @@ "logo": "https://opencollective.com/jest/logo.txt" }, "engines": { - "node": ">= 6" + "node": ">= 8" } } diff --git a/packages/babel-jest/package.json b/packages/babel-jest/package.json index 95a195e78c81..72a2237cd1fa 100644 --- a/packages/babel-jest/package.json +++ b/packages/babel-jest/package.json @@ -27,7 +27,7 @@ "@babel/core": "^7.0.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/babel-plugin-jest-hoist/package.json b/packages/babel-plugin-jest-hoist/package.json index 741b642635f7..a8f2fd0766ef 100644 --- a/packages/babel-plugin-jest-hoist/package.json +++ b/packages/babel-plugin-jest-hoist/package.json @@ -7,7 +7,7 @@ "directory": "packages/babel-plugin-jest-hoist" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "license": "MIT", "main": "build/index.js", diff --git a/packages/babel-preset-jest/package.json b/packages/babel-preset-jest/package.json index f400d79539b7..a3f9869f12ad 100644 --- a/packages/babel-preset-jest/package.json +++ b/packages/babel-preset-jest/package.json @@ -16,7 +16,7 @@ "@babel/core": "^7.0.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/diff-sequences/package.json b/packages/diff-sequences/package.json index 21c5100b9a9f..1cd21022728e 100644 --- a/packages/diff-sequences/package.json +++ b/packages/diff-sequences/package.json @@ -16,7 +16,7 @@ "diff" ], "engines": { - "node": ">= 6" + "node": ">= 8" }, "main": "build/index.js", "types": "build/index.d.ts", diff --git a/packages/eslint-config-fb-strict/package.json b/packages/eslint-config-fb-strict/package.json index 58f399a3669f..2b097497a873 100644 --- a/packages/eslint-config-fb-strict/package.json +++ b/packages/eslint-config-fb-strict/package.json @@ -20,7 +20,7 @@ "eslint-plugin-react": "^7.1.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/expect/package.json b/packages/expect/package.json index 8bd12ae7bd10..c64c5e05d4bf 100644 --- a/packages/expect/package.json +++ b/packages/expect/package.json @@ -23,7 +23,7 @@ "immutable": "^4.0.0-rc.12" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-changed-files/package.json b/packages/jest-changed-files/package.json index 85fc45622bf1..95c842c9a12b 100644 --- a/packages/jest-changed-files/package.json +++ b/packages/jest-changed-files/package.json @@ -18,7 +18,7 @@ "@types/execa": "^0.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-circus/package.json b/packages/jest-circus/package.json index 46062bc2bebe..7e4f0b634c13 100644 --- a/packages/jest-circus/package.json +++ b/packages/jest-circus/package.json @@ -36,7 +36,7 @@ "jest-runtime": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-cli/package.json b/packages/jest-cli/package.json index a42514728e5b..f5dd3a901423 100644 --- a/packages/jest-cli/package.json +++ b/packages/jest-cli/package.json @@ -29,7 +29,7 @@ "jest": "./bin/jest.js" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "repository": { "type": "git", diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index 10f51322cd8c..cc0e89847a7a 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -34,7 +34,7 @@ "@types/micromatch": "^3.1.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-console/package.json b/packages/jest-console/package.json index 7e7277e86fc5..2147006766b9 100644 --- a/packages/jest-console/package.json +++ b/packages/jest-console/package.json @@ -18,7 +18,7 @@ "@types/slash": "^2.0.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index 8e118be75aa5..ccd64e4211de 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -46,7 +46,7 @@ "@types/strip-ansi": "^3.0.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "repository": { "type": "git", diff --git a/packages/jest-diff/package.json b/packages/jest-diff/package.json index f3dad2de2c52..6ae1b7119ae0 100644 --- a/packages/jest-diff/package.json +++ b/packages/jest-diff/package.json @@ -20,7 +20,7 @@ "strip-ansi": "^5.0.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-docblock/package.json b/packages/jest-docblock/package.json index 09384731cd0f..65371c74114a 100644 --- a/packages/jest-docblock/package.json +++ b/packages/jest-docblock/package.json @@ -15,7 +15,7 @@ "@types/detect-newline": "^2.1.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-each/package.json b/packages/jest-each/package.json index ad803fda3eed..88673dc175d4 100644 --- a/packages/jest-each/package.json +++ b/packages/jest-each/package.json @@ -25,7 +25,7 @@ "pretty-format": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-environment-jsdom/package.json b/packages/jest-environment-jsdom/package.json index b0bf311c1e83..b6cfa6e4b12d 100644 --- a/packages/jest-environment-jsdom/package.json +++ b/packages/jest-environment-jsdom/package.json @@ -21,7 +21,7 @@ "@types/jsdom": "^11.12.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-environment-node/package.json b/packages/jest-environment-node/package.json index 0ab1a69ad6c7..e5a1799c97a3 100644 --- a/packages/jest-environment-node/package.json +++ b/packages/jest-environment-node/package.json @@ -17,7 +17,7 @@ "jest-util": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-environment/package.json b/packages/jest-environment/package.json index b4a1e18d1e01..bc0712d971a6 100644 --- a/packages/jest-environment/package.json +++ b/packages/jest-environment/package.json @@ -16,7 +16,7 @@ "jest-mock": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-fake-timers/package.json b/packages/jest-fake-timers/package.json index 5f827aeba0b4..03719109627f 100644 --- a/packages/jest-fake-timers/package.json +++ b/packages/jest-fake-timers/package.json @@ -15,7 +15,7 @@ "jest-mock": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-get-type/package.json b/packages/jest-get-type/package.json index 12bd091506c9..ca35327b3584 100644 --- a/packages/jest-get-type/package.json +++ b/packages/jest-get-type/package.json @@ -8,7 +8,7 @@ "directory": "packages/jest-get-type" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "license": "MIT", "main": "build/index.js", diff --git a/packages/jest-haste-map/package.json b/packages/jest-haste-map/package.json index 26189086efc9..a0cdef2e1103 100644 --- a/packages/jest-haste-map/package.json +++ b/packages/jest-haste-map/package.json @@ -35,7 +35,7 @@ "fsevents": "^1.2.7" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-jasmine2/package.json b/packages/jest-jasmine2/package.json index 06fc2dc035a7..e87c31099b55 100644 --- a/packages/jest-jasmine2/package.json +++ b/packages/jest-jasmine2/package.json @@ -31,7 +31,7 @@ "@types/babel__traverse": "^7.0.4" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-leak-detector/package.json b/packages/jest-leak-detector/package.json index ad76f2c09fe5..6883b20ebcde 100644 --- a/packages/jest-leak-detector/package.json +++ b/packages/jest-leak-detector/package.json @@ -18,7 +18,7 @@ "weak": "^1.0.1" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-matcher-utils/package.json b/packages/jest-matcher-utils/package.json index fe7f83c4a029..b0767cecd813 100644 --- a/packages/jest-matcher-utils/package.json +++ b/packages/jest-matcher-utils/package.json @@ -8,7 +8,7 @@ "directory": "packages/jest-matcher-utils" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "license": "MIT", "main": "build/index.js", diff --git a/packages/jest-message-util/package.json b/packages/jest-message-util/package.json index 0d75a015624d..2ed953661829 100644 --- a/packages/jest-message-util/package.json +++ b/packages/jest-message-util/package.json @@ -7,7 +7,7 @@ "directory": "packages/jest-message-util" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "license": "MIT", "main": "build/index.js", diff --git a/packages/jest-mock/package.json b/packages/jest-mock/package.json index 5932c3599369..a37f7f5cd1ed 100644 --- a/packages/jest-mock/package.json +++ b/packages/jest-mock/package.json @@ -7,7 +7,7 @@ "directory": "packages/jest-mock" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "dependencies": { "@jest/types": "^24.9.0" diff --git a/packages/jest-phabricator/package.json b/packages/jest-phabricator/package.json index 1214793061ed..c0bfc8edc0b1 100644 --- a/packages/jest-phabricator/package.json +++ b/packages/jest-phabricator/package.json @@ -11,7 +11,7 @@ "@jest/test-result": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "license": "MIT", "main": "build/index.js", diff --git a/packages/jest-regex-util/package.json b/packages/jest-regex-util/package.json index af0c74a57fc8..e60229a5715f 100644 --- a/packages/jest-regex-util/package.json +++ b/packages/jest-regex-util/package.json @@ -7,7 +7,7 @@ "directory": "packages/jest-regex-util" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "license": "MIT", "main": "build/index.js", diff --git a/packages/jest-repl/package.json b/packages/jest-repl/package.json index fe1e13a4ccc9..80f8b8469ef9 100644 --- a/packages/jest-repl/package.json +++ b/packages/jest-repl/package.json @@ -25,7 +25,7 @@ "jest-repl": "./bin/jest-repl.js" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index ada02f7e286f..10eea432d2d5 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -41,7 +41,7 @@ "strip-ansi": "^5.0.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "repository": { "type": "git", diff --git a/packages/jest-resolve-dependencies/package.json b/packages/jest-resolve-dependencies/package.json index ffcdbe25aa35..0fbc13f87c6c 100644 --- a/packages/jest-resolve-dependencies/package.json +++ b/packages/jest-resolve-dependencies/package.json @@ -20,7 +20,7 @@ "jest-runtime": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index 8deef2789497..22a7662e04e0 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -21,7 +21,7 @@ "jest-haste-map": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-runner/package.json b/packages/jest-runner/package.json index 42a56cebecdf..25d049422dd8 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -36,7 +36,7 @@ "@types/source-map-support": "^0.5.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-runtime/package.json b/packages/jest-runtime/package.json index 1d21f281ff99..31ab0c5e1ab1 100644 --- a/packages/jest-runtime/package.json +++ b/packages/jest-runtime/package.json @@ -46,7 +46,7 @@ "jest-runtime": "./bin/jest-runtime.js" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-serializer/package.json b/packages/jest-serializer/package.json index 6052e3d734b8..bd1018400295 100644 --- a/packages/jest-serializer/package.json +++ b/packages/jest-serializer/package.json @@ -7,7 +7,7 @@ "directory": "packages/jest-serializer" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "license": "MIT", "main": "build/index.js", diff --git a/packages/jest-serializer/src/__tests__/index.test.ts b/packages/jest-serializer/src/__tests__/index.test.ts index 6cc3d88a73b0..bc08cf9d988d 100644 --- a/packages/jest-serializer/src/__tests__/index.test.ts +++ b/packages/jest-serializer/src/__tests__/index.test.ts @@ -10,22 +10,10 @@ import * as fs from 'fs'; import {tmpdir} from 'os'; import * as path from 'path'; -import v8 from 'v8'; import prettyFormat from 'pretty-format'; import serializer from '..'; -const v8s = [ - { - deserialize: v8.deserialize, - serialize: v8.serialize, - }, - { - deserialize: undefined, - serialize: undefined, - }, -]; - const objs = [ 3, null, @@ -48,45 +36,35 @@ afterEach(() => { } }); -// We execute the same suite of tests over multiple objects ("objs") and over -// multiple mocks of the V8 object ("v8s") so that we verify that all possible -// encodings and cases work. -v8s.forEach((mockV8, i) => { - describe('Using V8 implementation ' + i, () => { - beforeEach(() => { - v8.serialize = mockV8.serialize; - v8.deserialize = mockV8.deserialize; - }); - - it('throws the error with an invalid serialization', () => { - // No chance this is a valid serialization, neither in JSON nor V8. - const invalidBuffer = Buffer.from([0, 85, 170, 255]); +describe('Using V8 implementation', () => { + it('throws the error with an invalid serialization', () => { + // No chance this is a valid serialization, neither in JSON nor V8. + const invalidBuffer = Buffer.from([0, 85, 170, 255]); - fs.writeFileSync(file, invalidBuffer); + fs.writeFileSync(file, invalidBuffer); - expect(() => serializer.deserialize(invalidBuffer)).toThrow(); - expect(() => serializer.readFileSync(file)).toThrow(); - }); + expect(() => serializer.deserialize(invalidBuffer)).toThrow(); + expect(() => serializer.readFileSync(file)).toThrow(); + }); - objs.forEach((obj, i) => { - describe('Object ' + i, () => { - it('serializes/deserializes in memory', () => { - const buf = serializer.serialize(obj); + objs.forEach((obj, i) => { + describe('Object ' + i, () => { + it('serializes/deserializes in memory', () => { + const buf = serializer.serialize(obj); - expect(buf).toBeInstanceOf(Buffer); + expect(buf).toBeInstanceOf(Buffer); - expect(prettyFormat(serializer.deserialize(buf))).toEqual( - prettyFormat(obj), - ); - }); + expect(prettyFormat(serializer.deserialize(buf))).toEqual( + prettyFormat(obj), + ); + }); - it('serializes/deserializes in disk', () => { - serializer.writeFileSync(file, obj); + it('serializes/deserializes in disk', () => { + serializer.writeFileSync(file, obj); - expect(prettyFormat(serializer.readFileSync(file))).toEqual( - prettyFormat(obj), - ); - }); + expect(prettyFormat(serializer.readFileSync(file))).toEqual( + prettyFormat(obj), + ); }); }); }); diff --git a/packages/jest-serializer/src/index.ts b/packages/jest-serializer/src/index.ts index 5e835de75faf..dd428e899152 100644 --- a/packages/jest-serializer/src/index.ts +++ b/packages/jest-serializer/src/index.ts @@ -17,126 +17,24 @@ type Path = string; // the versions are compatible by encoding the serialization version in the own // generated buffer. -const JS_TYPE = '__$t__'; -const JS_VALUE = '__$v__'; -const JS_VF = '__$f__'; - -function replacer(_key: string, value: any): any { - // NaN cannot be in a switch statement, because NaN !== NaN. - if (Number.isNaN(value)) { - return {[JS_TYPE]: 'n'}; - } - - switch (value) { - case undefined: - return {[JS_TYPE]: 'u'}; - case +Infinity: - return {[JS_TYPE]: '+'}; - case -Infinity: - return {[JS_TYPE]: '-'}; - } - - switch (value && value.constructor) { - case Date: - return {[JS_TYPE]: 'd', [JS_VALUE]: value.getTime()}; - case RegExp: - return {[JS_TYPE]: 'r', [JS_VALUE]: value.source, [JS_VF]: value.flags}; - case Set: - return {[JS_TYPE]: 's', [JS_VALUE]: Array.from(value)}; - case Map: - return {[JS_TYPE]: 'm', [JS_VALUE]: Array.from(value)}; - case Buffer: - return {[JS_TYPE]: 'b', [JS_VALUE]: value.toString('latin1')}; - } - - return value; -} - -function reviver(_key: string, value: any): any { - if (!value || (typeof value !== 'object' && !value.hasOwnProperty(JS_TYPE))) { - return value; - } - - switch (value[JS_TYPE]) { - case 'u': - return undefined; - case 'n': - return NaN; - case '+': - return +Infinity; - case '-': - return -Infinity; - case 'd': - return new Date(value[JS_VALUE]); - case 'r': - return new RegExp(value[JS_VALUE], value[JS_VF]); - case 's': - return new Set(value[JS_VALUE]); - case 'm': - return new Map(value[JS_VALUE]); - case 'b': - return Buffer.from(value[JS_VALUE], 'latin1'); - } - - return value; -} - -function jsonStringify(content: unknown) { - // Not pretty, but the ES JSON spec says that "toJSON" will be called before - // getting into your replacer, so we have to remove them beforehand. See - // https://www.ecma-international.org/ecma-262/#sec-serializejsonproperty - // section 2.b for more information. - - const dateToJSON = Date.prototype.toJSON; - const bufferToJSON = Buffer.prototype.toJSON; - - /* eslint-disable no-extend-native */ - - try { - // @ts-ignore intentional removal of "toJSON" property. - Date.prototype.toJSON = undefined; - // @ts-ignore intentional removal of "toJSON" property. - Buffer.prototype.toJSON = undefined; - - return JSON.stringify(content, replacer); - } finally { - Date.prototype.toJSON = dateToJSON; - Buffer.prototype.toJSON = bufferToJSON; - } - - /* eslint-enable no-extend-native */ -} - -function jsonParse(content: string) { - return JSON.parse(content, reviver); -} - // In memory functions. export function deserialize(buffer: Buffer): any { - return v8.deserialize - ? v8.deserialize(buffer) - : jsonParse(buffer.toString('utf8')); + return v8.deserialize(buffer); } export function serialize(content: unknown): Buffer { - return v8.serialize - ? v8.serialize(content) - : Buffer.from(jsonStringify(content)); + return v8.serialize(content); } // Synchronous filesystem functions. export function readFileSync(filePath: Path): any { - return v8.deserialize - ? v8.deserialize(fs.readFileSync(filePath)) - : jsonParse(fs.readFileSync(filePath, 'utf8')); + return v8.deserialize(fs.readFileSync(filePath)); } export function writeFileSync(filePath: Path, content: any) { - return v8.serialize - ? fs.writeFileSync(filePath, v8.serialize(content)) - : fs.writeFileSync(filePath, jsonStringify(content), 'utf8'); + return fs.writeFileSync(filePath, v8.serialize(content)); } export default { diff --git a/packages/jest-snapshot/package.json b/packages/jest-snapshot/package.json index c4562420da55..928744797d83 100644 --- a/packages/jest-snapshot/package.json +++ b/packages/jest-snapshot/package.json @@ -34,7 +34,7 @@ "prettier": "^1.13.4" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-source-map/package.json b/packages/jest-source-map/package.json index aac97df1ff90..8e9383e10a6d 100644 --- a/packages/jest-source-map/package.json +++ b/packages/jest-source-map/package.json @@ -18,7 +18,7 @@ "@types/graceful-fs": "^4.1.2" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-test-result/package.json b/packages/jest-test-result/package.json index 5ebc8c995bd3..cf0b720e565c 100644 --- a/packages/jest-test-result/package.json +++ b/packages/jest-test-result/package.json @@ -15,7 +15,7 @@ "@types/istanbul-lib-coverage": "^2.0.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-test-sequencer/package.json b/packages/jest-test-sequencer/package.json index 13f494ce38e6..3e7c445a722e 100644 --- a/packages/jest-test-sequencer/package.json +++ b/packages/jest-test-sequencer/package.json @@ -16,7 +16,7 @@ "jest-runtime": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-transform/package.json b/packages/jest-transform/package.json index a356f905b7d2..1d9707b52dd0 100644 --- a/packages/jest-transform/package.json +++ b/packages/jest-transform/package.json @@ -35,7 +35,7 @@ "@types/write-file-atomic": "^2.1.1" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-types/package.json b/packages/jest-types/package.json index defa60c76d00..b2e3909fb047 100644 --- a/packages/jest-types/package.json +++ b/packages/jest-types/package.json @@ -7,7 +7,7 @@ "directory": "packages/jest-types" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "license": "MIT", "main": "build/index.js", diff --git a/packages/jest-util/package.json b/packages/jest-util/package.json index 31ba81f34bce..f68f14bb74b2 100644 --- a/packages/jest-util/package.json +++ b/packages/jest-util/package.json @@ -30,7 +30,7 @@ "@types/slash": "^2.0.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-util/src/deepCyclicCopy.ts b/packages/jest-util/src/deepCyclicCopy.ts index de5efab96b2b..18a1e1af1d78 100644 --- a/packages/jest-util/src/deepCyclicCopy.ts +++ b/packages/jest-util/src/deepCyclicCopy.ts @@ -12,23 +12,6 @@ export type DeepCyclicCopyOptions = { keepPrototype?: boolean; }; -// Node 6 does not have gOPDs, so we define a simple polyfill for it. -if (!Object.getOwnPropertyDescriptors) { - // @ts-ignore: polyfill - Object.getOwnPropertyDescriptors = obj => { - const list: Record = {}; - - (Object.getOwnPropertyNames(obj) as Array) - .concat(Object.getOwnPropertySymbols(obj)) - .forEach(key => { - // @ts-ignore: assignment with a Symbol is OK. - list[key] = Object.getOwnPropertyDescriptor(obj, key); - }); - - return list; - }; -} - export default function deepCyclicCopy( value: T, options: DeepCyclicCopyOptions = {blacklist: EMPTY, keepPrototype: false}, diff --git a/packages/jest-validate/package.json b/packages/jest-validate/package.json index fa4e8beb77d8..2c9974f894ed 100644 --- a/packages/jest-validate/package.json +++ b/packages/jest-validate/package.json @@ -18,7 +18,7 @@ "pretty-format": "^24.9.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest-watcher/package.json b/packages/jest-watcher/package.json index eaca9b11f669..78e33bf9dc4d 100644 --- a/packages/jest-watcher/package.json +++ b/packages/jest-watcher/package.json @@ -25,7 +25,7 @@ "url": "https://github.com/facebook/jest/issues" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "homepage": "https://jestjs.io/", "license": "MIT", diff --git a/packages/jest-worker/package.json b/packages/jest-worker/package.json index ae906f007069..304d5f30cfb6 100644 --- a/packages/jest-worker/package.json +++ b/packages/jest-worker/package.json @@ -20,7 +20,7 @@ "worker-farm": "^1.6.0" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public" diff --git a/packages/jest/package.json b/packages/jest/package.json index e631d0f78f3c..ff3d688d745b 100644 --- a/packages/jest/package.json +++ b/packages/jest/package.json @@ -12,7 +12,7 @@ "jest": "./bin/jest.js" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "repository": { "type": "git", diff --git a/packages/pretty-format/package.json b/packages/pretty-format/package.json index 086bbcf013a4..a12efa9ee35c 100644 --- a/packages/pretty-format/package.json +++ b/packages/pretty-format/package.json @@ -30,7 +30,7 @@ "react-test-renderer": "*" }, "engines": { - "node": ">= 6" + "node": ">= 8" }, "publishConfig": { "access": "public"