Skip to content

Commit dae3641

Browse files
authored
Move jest-get-type to ESM named exports (#11359)
1 parent d13e177 commit dae3641

12 files changed

Lines changed: 17 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
- `[jest-environment]` [**BREAKING**] Drop support for `runScript` for test environments ([#11155](https://github.com/facebook/jest/pull/11155))
6363
- `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885))
6464
- `[jest-environment-jsdom]` [**BREAKING**] Remove Node globals `setImmediate` and `clearImmediate` [#11222](https://github.com/facebook/jest/pull/11222)
65+
- `[jest-get-type]` [**BREAKING**] Convert to ES Module ([#11359](https://github.com/facebook/jest/pull/11359))
6566
- `[jest-globals]` [**BREAKING**] Disallow return values other than a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
6667
- `[jest-globals]` [**BREAKING**] Disallow mixing a done callback and returning a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
6768
- `[jest-haste-map]` Vendor `NodeWatcher` from `sane` ([#10919](https://github.com/facebook/jest/pull/10919))

docs/JestPlatform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Module that identifies the primitive type of any JavaScript value. Exports a fun
7777
### Example
7878

7979
```javascript
80-
const getType = require('jest-get-type');
80+
const {getType} = require('jest-get-type');
8181

8282
const array = [1, 2, 3];
8383
const nullValue = null;

packages/expect/src/matchers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* eslint-disable local/ban-types-eventually */
1010

11-
import getType = require('jest-get-type');
11+
import {getType, isPrimitive} from 'jest-get-type';
1212
import {
1313
DIM_COLOR,
1414
EXPECTED_COLOR,
@@ -315,8 +315,7 @@ const matchers: MatchersObject = {
315315
matcherHint(matcherName, undefined, undefined, options) +
316316
'\n\n' +
317317
printExpectedConstructorName('Expected constructor', expected) +
318-
(getType.isPrimitive(received) ||
319-
Object.getPrototypeOf(received) === null
318+
(isPrimitive(received) || Object.getPrototypeOf(received) === null
320319
? `\nReceived value has no prototype\nReceived value: ${printReceived(
321320
received,
322321
)}`

packages/expect/src/spyMatchers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import getType = require('jest-get-type');
8+
import {getType, isPrimitive} from 'jest-get-type';
99
import {
1010
DIM_COLOR,
1111
EXPECTED_COLOR,
@@ -278,7 +278,7 @@ const isLineDiffableArg = (expected: unknown, received: unknown): boolean => {
278278
return false;
279279
}
280280

281-
if (getType.isPrimitive(expected)) {
281+
if (isPrimitive(expected)) {
282282
return false;
283283
}
284284

packages/jest-config/src/ReporterValidationErrors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import chalk = require('chalk');
99
import type {Config} from '@jest/types';
10-
import getType = require('jest-get-type');
10+
import {getType} from 'jest-get-type';
1111
import {ValidationError} from 'jest-validate';
1212
import {BULLET, DOCUMENTATION_NOTE} from './utils';
1313

packages/jest-diff/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import chalk = require('chalk');
9-
import getType = require('jest-get-type');
9+
import {getType} from 'jest-get-type';
1010
import prettyFormat, {plugins as prettyFormatPlugins} from 'pretty-format';
1111
import {DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff} from './cleanupSemantic';
1212
import {NO_DIFF_MESSAGE, SIMILAR_MESSAGE} from './constants';

packages/jest-get-type/src/__tests__/getType.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import getType from '../';
9+
import {getType} from '../';
1010

1111
describe('.getType()', () => {
1212
test('null', () => expect(getType(null)).toBe('null'));

packages/jest-get-type/src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type ValueType =
2323

2424
// get the type of a value with handling the edge cases like `typeof []`
2525
// and `typeof null`
26-
function getType(value: unknown): ValueType {
26+
export function getType(value: unknown): ValueType {
2727
if (value === undefined) {
2828
return 'undefined';
2929
} else if (value === null) {
@@ -60,6 +60,4 @@ function getType(value: unknown): ValueType {
6060
throw new Error(`value of unknown type: ${value}`);
6161
}
6262

63-
getType.isPrimitive = (value: unknown) => Object(value) !== value;
64-
65-
export = getType;
63+
export const isPrimitive = (value: unknown): boolean => Object(value) !== value;

packages/jest-matcher-utils/src/Replaceable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import getType = require('jest-get-type');
8+
import {getType} from 'jest-get-type';
99

1010
const supportTypes = ['map', 'array', 'object'];
1111

packages/jest-matcher-utils/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import diffDefault, {
1717
diffStringsRaw,
1818
diffStringsUnified,
1919
} from 'jest-diff';
20-
import getType = require('jest-get-type');
20+
import {getType, isPrimitive} from 'jest-get-type';
2121
import prettyFormat, {plugins as prettyFormatPlugins} from 'pretty-format';
2222
import Replaceable from './Replaceable';
2323
import deepCyclicCopyReplaceable from './deepCyclicCopyReplaceable';
@@ -264,7 +264,7 @@ const isLineDiffable = (expected: unknown, received: unknown): boolean => {
264264
return false;
265265
}
266266

267-
if (getType.isPrimitive(expected)) {
267+
if (isPrimitive(expected)) {
268268
// Print generic line diff for strings only:
269269
// * if neither string is empty
270270
// * if either string has more than one line

0 commit comments

Comments
 (0)