Skip to content

Commit

Permalink
Move jest-get-type to ESM named exports (#11359)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS authored Apr 30, 2021
1 parent d13e177 commit dae3641
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion docs/JestPlatform.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions packages/expect/src/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)}`
Expand Down
4 changes: 2 additions & 2 deletions packages/expect/src/spyMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -278,7 +278,7 @@ const isLineDiffableArg = (expected: unknown, received: unknown): boolean => {
return false;
}

if (getType.isPrimitive(expected)) {
if (isPrimitive(expected)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/ReporterValidationErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-diff/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-get-type/src/__tests__/getType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

import getType from '../';
import {getType} from '../';

describe('.getType()', () => {
test('null', () => expect(getType(null)).toBe('null'));
Expand Down
6 changes: 2 additions & 4 deletions packages/jest-get-type/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion packages/jest-matcher-utils/src/Replaceable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-matcher-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-snapshot/src/printSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-validate/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit dae3641

Please sign in to comment.