From dae3641d66a49a693476b7ec5b79998e24760fa4 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Fri, 30 Apr 2021 04:55:53 -0400 Subject: [PATCH] Move jest-get-type to ESM named exports (#11359) --- CHANGELOG.md | 1 + docs/JestPlatform.md | 2 +- packages/expect/src/matchers.ts | 5 ++--- packages/expect/src/spyMatchers.ts | 4 ++-- packages/jest-config/src/ReporterValidationErrors.ts | 2 +- packages/jest-diff/src/index.ts | 2 +- packages/jest-get-type/src/__tests__/getType.test.ts | 2 +- packages/jest-get-type/src/index.ts | 6 ++---- packages/jest-matcher-utils/src/Replaceable.ts | 2 +- packages/jest-matcher-utils/src/index.ts | 4 ++-- packages/jest-snapshot/src/printSnapshot.ts | 4 ++-- packages/jest-validate/src/errors.ts | 2 +- 12 files changed, 17 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6866c4c737f..e7e78ef1659e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ - `[jest-environment]` [**BREAKING**] Drop support for `runScript` for test environments ([#11155](https://github.com/facebook/jest/pull/11155)) - `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885)) - `[jest-environment-jsdom]` [**BREAKING**] Remove Node globals `setImmediate` and `clearImmediate` [#11222](https://github.com/facebook/jest/pull/11222) +- `[jest-get-type]` [**BREAKING**] Convert to ES Module ([#11359](https://github.com/facebook/jest/pull/11359)) - `[jest-globals]` [**BREAKING**] Disallow return values other than a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512)) - `[jest-globals]` [**BREAKING**] Disallow mixing a done callback and returning a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512)) - `[jest-haste-map]` Vendor `NodeWatcher` from `sane` ([#10919](https://github.com/facebook/jest/pull/10919)) diff --git a/docs/JestPlatform.md b/docs/JestPlatform.md index 5ed250b1ef0a..071f8a207a1b 100644 --- a/docs/JestPlatform.md +++ b/docs/JestPlatform.md @@ -77,7 +77,7 @@ Module that identifies the primitive type of any JavaScript value. Exports a fun ### Example ```javascript -const getType = require('jest-get-type'); +const {getType} = require('jest-get-type'); const array = [1, 2, 3]; const nullValue = null; diff --git a/packages/expect/src/matchers.ts b/packages/expect/src/matchers.ts index 99a3c7e9fd42..d0ec1480dab4 100644 --- a/packages/expect/src/matchers.ts +++ b/packages/expect/src/matchers.ts @@ -8,7 +8,7 @@ /* eslint-disable local/ban-types-eventually */ -import getType = require('jest-get-type'); +import {getType, isPrimitive} from 'jest-get-type'; import { DIM_COLOR, EXPECTED_COLOR, @@ -315,8 +315,7 @@ const matchers: MatchersObject = { matcherHint(matcherName, undefined, undefined, options) + '\n\n' + printExpectedConstructorName('Expected constructor', expected) + - (getType.isPrimitive(received) || - Object.getPrototypeOf(received) === null + (isPrimitive(received) || Object.getPrototypeOf(received) === null ? `\nReceived value has no prototype\nReceived value: ${printReceived( received, )}` diff --git a/packages/expect/src/spyMatchers.ts b/packages/expect/src/spyMatchers.ts index 381791368593..3c930e9e01c7 100644 --- a/packages/expect/src/spyMatchers.ts +++ b/packages/expect/src/spyMatchers.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import getType = require('jest-get-type'); +import {getType, isPrimitive} from 'jest-get-type'; import { DIM_COLOR, EXPECTED_COLOR, @@ -278,7 +278,7 @@ const isLineDiffableArg = (expected: unknown, received: unknown): boolean => { return false; } - if (getType.isPrimitive(expected)) { + if (isPrimitive(expected)) { return false; } diff --git a/packages/jest-config/src/ReporterValidationErrors.ts b/packages/jest-config/src/ReporterValidationErrors.ts index 8f15a50a0162..6b726fdf0486 100644 --- a/packages/jest-config/src/ReporterValidationErrors.ts +++ b/packages/jest-config/src/ReporterValidationErrors.ts @@ -7,7 +7,7 @@ import chalk = require('chalk'); import type {Config} from '@jest/types'; -import getType = require('jest-get-type'); +import {getType} from 'jest-get-type'; import {ValidationError} from 'jest-validate'; import {BULLET, DOCUMENTATION_NOTE} from './utils'; diff --git a/packages/jest-diff/src/index.ts b/packages/jest-diff/src/index.ts index 7046d79d3839..010af4d04f0b 100644 --- a/packages/jest-diff/src/index.ts +++ b/packages/jest-diff/src/index.ts @@ -6,7 +6,7 @@ */ import chalk = require('chalk'); -import getType = require('jest-get-type'); +import {getType} from 'jest-get-type'; import prettyFormat, {plugins as prettyFormatPlugins} from 'pretty-format'; import {DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff} from './cleanupSemantic'; import {NO_DIFF_MESSAGE, SIMILAR_MESSAGE} from './constants'; diff --git a/packages/jest-get-type/src/__tests__/getType.test.ts b/packages/jest-get-type/src/__tests__/getType.test.ts index 0f66f444316f..782f967c737e 100644 --- a/packages/jest-get-type/src/__tests__/getType.test.ts +++ b/packages/jest-get-type/src/__tests__/getType.test.ts @@ -6,7 +6,7 @@ * */ -import getType from '../'; +import {getType} from '../'; describe('.getType()', () => { test('null', () => expect(getType(null)).toBe('null')); diff --git a/packages/jest-get-type/src/index.ts b/packages/jest-get-type/src/index.ts index c2ceeaf9b604..0b6b501610b2 100644 --- a/packages/jest-get-type/src/index.ts +++ b/packages/jest-get-type/src/index.ts @@ -23,7 +23,7 @@ type ValueType = // get the type of a value with handling the edge cases like `typeof []` // and `typeof null` -function getType(value: unknown): ValueType { +export function getType(value: unknown): ValueType { if (value === undefined) { return 'undefined'; } else if (value === null) { @@ -60,6 +60,4 @@ function getType(value: unknown): ValueType { throw new Error(`value of unknown type: ${value}`); } -getType.isPrimitive = (value: unknown) => Object(value) !== value; - -export = getType; +export const isPrimitive = (value: unknown): boolean => Object(value) !== value; diff --git a/packages/jest-matcher-utils/src/Replaceable.ts b/packages/jest-matcher-utils/src/Replaceable.ts index b84194f75d62..a114b01be6a1 100644 --- a/packages/jest-matcher-utils/src/Replaceable.ts +++ b/packages/jest-matcher-utils/src/Replaceable.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import getType = require('jest-get-type'); +import {getType} from 'jest-get-type'; const supportTypes = ['map', 'array', 'object']; diff --git a/packages/jest-matcher-utils/src/index.ts b/packages/jest-matcher-utils/src/index.ts index bd4547f9b89a..d1fa946db3a0 100644 --- a/packages/jest-matcher-utils/src/index.ts +++ b/packages/jest-matcher-utils/src/index.ts @@ -17,7 +17,7 @@ import diffDefault, { diffStringsRaw, diffStringsUnified, } from 'jest-diff'; -import getType = require('jest-get-type'); +import {getType, isPrimitive} from 'jest-get-type'; import prettyFormat, {plugins as prettyFormatPlugins} from 'pretty-format'; import Replaceable from './Replaceable'; import deepCyclicCopyReplaceable from './deepCyclicCopyReplaceable'; @@ -264,7 +264,7 @@ const isLineDiffable = (expected: unknown, received: unknown): boolean => { return false; } - if (getType.isPrimitive(expected)) { + if (isPrimitive(expected)) { // Print generic line diff for strings only: // * if neither string is empty // * if either string has more than one line diff --git a/packages/jest-snapshot/src/printSnapshot.ts b/packages/jest-snapshot/src/printSnapshot.ts index 34a4370f7436..629424d3700c 100644 --- a/packages/jest-snapshot/src/printSnapshot.ts +++ b/packages/jest-snapshot/src/printSnapshot.ts @@ -24,7 +24,7 @@ import { diffStringsRaw, diffStringsUnified, } from 'jest-diff'; -import getType = require('jest-get-type'); +import {getType, isPrimitive} from 'jest-get-type'; import { BOLD_WEIGHT, EXPECTED_COLOR, @@ -171,7 +171,7 @@ const joinDiffs = ( const isLineDiffable = (received: unknown): boolean => { const receivedType = getType(received); - if (getType.isPrimitive(received)) { + if (isPrimitive(received)) { return typeof received === 'string'; } diff --git a/packages/jest-validate/src/errors.ts b/packages/jest-validate/src/errors.ts index 28e00563274e..3f4dcdcb286e 100644 --- a/packages/jest-validate/src/errors.ts +++ b/packages/jest-validate/src/errors.ts @@ -6,7 +6,7 @@ */ import chalk = require('chalk'); -import getType = require('jest-get-type'); +import {getType} from 'jest-get-type'; import {getValues} from './condition'; import type {ValidationOptions} from './types'; import {ERROR, ValidationError, formatPrettyObject} from './utils';