Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: BigInt Support #8382

Merged
merged 52 commits into from Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1941be0
feat(jest-get-type) include bigint
JoshRosenstein Apr 25, 2019
d39a157
(jest-matcher-utils) add ensureActualIsNumberOrBigInit
JoshRosenstein Apr 26, 2019
16a2312
(expect) add biginit support
JoshRosenstein Apr 26, 2019
3ccbce4
Revert gettype to ifelse
JoshRosenstein Apr 26, 2019
2995d69
Add tests mixing numbers and bigint
JoshRosenstein Apr 26, 2019
ff21d21
bigDumbTypo
JoshRosenstein Apr 26, 2019
4128975
babel-plugin-jest-hoist add to whitelist
JoshRosenstein Apr 26, 2019
2488c34
Wrap BigInt Tests with guard
JoshRosenstein Apr 26, 2019
9c68a16
temp fix test suite must contain at least one test
JoshRosenstein Apr 26, 2019
3e33530
remove MatchingSnapshot tests due to unsupported env having obsoletes
JoshRosenstein Apr 26, 2019
50b3bb4
remove unnecessary bigint check in equals
JoshRosenstein Apr 29, 2019
cde6327
Remove ensure*NumbersOrBigInt, include BigInt in originals, add `or b…
JoshRosenstein Apr 29, 2019
8e0656a
Update snapshots with new error message `number or bigint`
JoshRosenstein Apr 29, 2019
d1e1b88
add bigint support to toBeCloseTo, replace ensureNumbersOrBigInt to e…
JoshRosenstein Apr 29, 2019
1a2ff60
tests(expect) remove temp_test, add bigint tests to matchers.test
JoshRosenstein Apr 29, 2019
0c594cf
tests(jest-matcher-utils) remove temp_tests, add bigint tests to inde…
JoshRosenstein Apr 29, 2019
b122b02
Update CHANGELOG.md
JoshRosenstein Apr 29, 2019
c640ec3
Merge branch 'master' into BigInt
JoshRosenstein Apr 29, 2019
f5cec2a
Update CHANGELOG.md
JoshRosenstein Apr 30, 2019
5bf3acc
(babel-preset-jest)-add @babel/plugin-syntax-bigint
JoshRosenstein Apr 30, 2019
be5cbb6
Add tests for bigint syntax
JoshRosenstein Apr 30, 2019
8c1d55c
Update CHANGELOG.md
JoshRosenstein Apr 30, 2019
3459c44
:rage2: :abc:
JoshRosenstein Apr 30, 2019
592d6f3
Checking if node6 breaks with lookup
JoshRosenstein Apr 30, 2019
c2c771a
Revert "Checking if node6 breaks with lookup"
JoshRosenstein Apr 30, 2019
fb6655d
Revert "Add tests for bigint syntax"
JoshRosenstein Apr 30, 2019
0646729
Update CHANGELOG.md
pedrottimark Apr 30, 2019
9390440
Remove Default Precision Value and update error msg via code review
JoshRosenstein May 1, 2019
52d110d
Replace ensureExpectedIsNumber with ensureExpectedIsNonNegativeIntege…
JoshRosenstein May 1, 2019
5430e1a
Update Matchers interface
JoshRosenstein May 1, 2019
42e4e89
Revert Bigint Support for 'toBeCloseTo'
JoshRosenstein May 1, 2019
67d1ad8
Update CHANGELOG.md
JoshRosenstein May 1, 2019
aba6474
pedrottimark's CR fixes in tests :eyes: :dart:
JoshRosenstein May 1, 2019
b4884f5
Merge branch 'master' into BigInt
JoshRosenstein May 5, 2019
c4aea47
Merge remote-tracking branch 'upstream/master' into BigInt
JoshRosenstein May 13, 2019
f2a5745
Update CHANGELOG.md
JoshRosenstein May 13, 2019
99642be
Merge branch 'master' into BigInt
thymikee Jun 14, 2019
f0d73f8
Merge commit '1749aeab92e33fe1ae65196c75aebd2d1f366ab2' into BigInt
SimenB Sep 1, 2019
0bdddfd
Merge commit 'b64d35d127ba41a8233ded35a52a9a70981d9d53' into BigInt
SimenB Sep 1, 2019
d22ed48
Merge commit 'b2c9fe3726d81c7ea6d71115352f177afd6210ba' into BigInt
SimenB Sep 1, 2019
46d64de
Merge commit '798891208e752e084c7935e2e52e0f765a758c1e' into BigInt
SimenB Sep 1, 2019
1d9e41a
Merge commit 'a1e30075ca60fb720ae1ba9a66ba1e4837c67428' into BigInt
SimenB Sep 1, 2019
e8d9411
Merge commit '88ccda0910c83b92bcb5671dc9b0de94e5250054' into BigInt
SimenB Sep 1, 2019
615b2c4
Merge branch 'master' into BigInt
SimenB Sep 1, 2019
6164740
move changelog entries
SimenB Sep 1, 2019
ad3c832
fix changelog formatting
SimenB Sep 1, 2019
c30ae9c
Delete unnecessary disable of eslint rules
pedrottimark Sep 3, 2019
de4d01c
Update ExpectAPI.md
pedrottimark Sep 3, 2019
0e2ef7d
Update CHANGELOG.md
pedrottimark Sep 3, 2019
007919d
Edit ExpectAPI.md
pedrottimark Sep 4, 2019
2d026e9
Merge branch 'master' into BigInt
SimenB Sep 6, 2019
89b1538
Merge branch 'master' into BigInt
SimenB Sep 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions CHANGELOG.md
Expand Up @@ -3,12 +3,17 @@
### Features

- `[babel-plugin-jest-hoist]` Show codeframe on static hoisting issues ([#8865](https://github.com/facebook/jest/pull/8865))
- `[babel-plugin-jest-hoist]` Add `BigInt` to `WHITELISTED_IDENTIFIERS` ([#8382](https://github.com/facebook/jest/pull/8382))
- `[babel-preset-jest]` Add `@babel/plugin-syntax-bigint` ([#8382](https://github.com/facebook/jest/pull/8382))
- `[expect]` Add `BigInt` support to `toBeGreaterThan`, `toBeGreaterThanOrEqual`, `toBeLessThan` and `toBeLessThanOrEqual` ([#8382](https://github.com/facebook/jest/pull/8382))
- `[jest-config]` [**BREAKING**] Set default display name color based on runner ([#8689](https://github.com/facebook/jest/pull/8689))
- `[jest-diff]` Add options for colors and symbols ([#8841](https://github.com/facebook/jest/pull/8841))
- `[jest-diff]` [**BREAKING**] Export as ECMAScript module ([#8873](https://github.com/facebook/jest/pull/8873))
- `[jest-diff]` Add `includeChangeCounts` and rename `Indicator` options ([#8881](https://github.com/facebook/jest/pull/8881))
- `[jest-diff]` Add `changeColor` and `patchColor` options ([#8911](https://github.com/facebook/jest/pull/8911))
- `[@jest/fake-timers]` Add Lolex as implementation of fake timers ([#8897](https://github.com/facebook/jest/pull/8897))
- `[jest-get-type]` Add `BigInt` support. ([#8382](https://github.com/facebook/jest/pull/8382))
- `[jest-matcher-utils]` Add `BigInt` support to `ensureNumbers` `ensureActualIsNumber`, `ensureExpectedIsNumber` ([#8382](https://github.com/facebook/jest/pull/8382))
- `[jest-runner]` Warn if a worker had to be force exited ([#8206](https://github.com/facebook/jest/pull/8206))
- `[@jest/test-result]` Create method to create empty `TestResult` ([#8867](https://github.com/facebook/jest/pull/8867))
- `[jest-worker]` [**BREAKING**] Return a promise from `end()`, resolving with the information whether workers exited gracefully ([#8206](https://github.com/facebook/jest/pull/8206))
Expand Down Expand Up @@ -447,7 +452,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0
- `[jest-haste-map]` Add `getCacheFilePath` to get the path to the cache file for a `HasteMap` instance ([#7217](https://github.com/facebook/jest/pull/7217))
- `[jest-runtime]` Remove `cacheDirectory` from `ignorePattern` for `HasteMap` if not necessary ([#7166](https://github.com/facebook/jest/pull/7166))
- `[jest-validate]` Add syntax to validate multiple permitted types ([#7207](https://github.com/facebook/jest/pull/7207))
- `[jest-config]` Accept an array as as well as a string for `testRegex`([#7209]https://github.com/facebook/jest/pull/7209))
- `[jest-config]` Accept an array as as well as a string for `testRegex` ([#7209]https://github.com/facebook/jest/pull/7209))
- `[expect/jest-matcher-utils]` Improve report when assertion fails, part 4 ([#7241](https://github.com/facebook/jest/pull/7241))
- `[expect/jest-matcher-utils]` Improve report when assertion fails, part 5 ([#7557](https://github.com/facebook/jest/pull/7557))
- `[expect]` Check constructor equality in .toStrictEqual() ([#7005](https://github.com/facebook/jest/pull/7005))
Expand Down Expand Up @@ -496,7 +501,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0
- `[jest-jasmine2]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372))
- `[jest-jasmine2]` Pending calls inside async tests are reported as pending not failed ([#6782](https://github.com/facebook/jest/pull/6782))
- `[jest-circus]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372))
- `[jest-jasmine2]` Add missing testLocationResults for `xit` and `fit`([#6482](https://github.com/facebook/jest/pull/6482))
- `[jest-jasmine2]` Add missing testLocationResults for `xit` and `fit` ([#6482](https://github.com/facebook/jest/pull/6482))
- `[expect]` Return false from asymmetric matchers if received value isn’t string ([#7107](https://github.com/facebook/jest/pull/7107))
- `[jest-cli]` Fix unhandled error when a bad revision is provided to `changedSince` ([#7115](https://github.com/facebook/jest/pull/7115))
- `[jest-config]` Moved dynamically assigned `cwd` from `jest-cli` to default configuration in `jest-config` ([#7146](https://github.com/facebook/jest/pull/7146))
Expand Down
28 changes: 16 additions & 12 deletions docs/ExpectAPI.md
Expand Up @@ -831,25 +831,29 @@ test('this house has my desired features', () => {

### `.toBeCloseTo(number, numDigits?)`

Using exact equality with floating point numbers is a bad idea. Rounding means that intuitive things fail. For example, this test fails:
Use `toBeCloseTo` to compare floating point numbers for approximate equality.

The optional `numDigits` argument limits the number of digits to check **after** the decimal point. For the default value `2`, the test criterion is `Math.abs(expected - received) < 0.005` (that is, `10 ** -2 / 2`).

Intuitive equality comparisons often fail, because arithmetic on decimal (base 10) values often have rounding errors in limited precision binary (base 2) representation. For example, this test fails:

```js
test('adding works sanely with simple decimals', () => {
expect(0.2 + 0.1).toBe(0.3); // Fails!
});
```

It fails because in JavaScript, `0.2 + 0.1` is actually `0.30000000000000004`. Sorry.
It fails because in JavaScript, `0.2 + 0.1` is actually `0.30000000000000004`.

Instead, use `.toBeCloseTo`. Use `numDigits` to control how many digits after the decimal point to check. For example, if you want to be sure that `0.2 + 0.1` is equal to `0.3` with a precision of 5 decimal digits, you can use this test:
For example, this test passes with a precision of 5 digits:

```js
test('adding works sanely with simple decimals', () => {
expect(0.2 + 0.1).toBeCloseTo(0.3, 5);
});
```

The optional `numDigits` argument has default value `2` which means the criterion is `Math.abs(expected - received) < 0.005` (that is, `10 ** -2 / 2`).
Because floating point errors are the problem that `toBeCloseTo` solves, it does not support big integer values.

### `.toBeDefined()`

Expand Down Expand Up @@ -885,39 +889,39 @@ test('drinking La Croix does not lead to errors', () => {

In JavaScript, there are six falsy values: `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.

### `.toBeGreaterThan(number)`
### `.toBeGreaterThan(number | bigint)`

To compare floating point numbers, you can use `toBeGreaterThan`. For example, if you want to test that `ouncesPerCan()` returns a value of more than 10 ounces, write:
Use `toBeGreaterThan` to compare `received > expected` for number or big integer values. For example, test that `ouncesPerCan()` returns a value of more than 10 ounces:

```js
test('ounces per can is more than 10', () => {
expect(ouncesPerCan()).toBeGreaterThan(10);
});
```

### `.toBeGreaterThanOrEqual(number)`
### `.toBeGreaterThanOrEqual(number | bigint)`

To compare floating point numbers, you can use `toBeGreaterThanOrEqual`. For example, if you want to test that `ouncesPerCan()` returns a value of at least 12 ounces, write:
Use `toBeGreaterThanOrEqual` to compare `received >= expected` for number or big integer values. For example, test that `ouncesPerCan()` returns a value of at least 12 ounces:

```js
test('ounces per can is at least 12', () => {
expect(ouncesPerCan()).toBeGreaterThanOrEqual(12);
});
```

### `.toBeLessThan(number)`
### `.toBeLessThan(number | bigint)`

To compare floating point numbers, you can use `toBeLessThan`. For example, if you want to test that `ouncesPerCan()` returns a value of less than 20 ounces, write:
Use `toBeLessThan` to compare `received < expected` for number or big integer values. For example, test that `ouncesPerCan()` returns a value of less than 20 ounces:

```js
test('ounces per can is less than 20', () => {
expect(ouncesPerCan()).toBeLessThan(20);
});
```

### `.toBeLessThanOrEqual(number)`
### `.toBeLessThanOrEqual(number | bigint)`

To compare floating point numbers, you can use `toBeLessThanOrEqual`. For example, if you want to test that `ouncesPerCan()` returns a value of at most 12 ounces, write:
Use `toBeLessThanOrEqual` to compare `received <= expected` for number or big integer values. For example, test that `ouncesPerCan()` returns a value of at most 12 ounces:

```js
test('ounces per can is at most 12', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/babel-plugin-jest-hoist/src/index.ts
Expand Up @@ -20,6 +20,7 @@ const WHITELISTED_IDENTIFIERS = new Set<string>(
'Array',
'ArrayBuffer',
'Boolean',
'BigInt',
'DataView',
'Date',
'Error',
Expand Down
1 change: 1 addition & 0 deletions packages/babel-preset-jest/index.js
Expand Up @@ -9,5 +9,6 @@ module.exports = () => ({
plugins: [
require.resolve('babel-plugin-jest-hoist'),
require.resolve('@babel/plugin-syntax-object-rest-spread'),
require.resolve('@babel/plugin-syntax-bigint'),
],
});
1 change: 1 addition & 0 deletions packages/babel-preset-jest/package.json
Expand Up @@ -9,6 +9,7 @@
"license": "MIT",
"main": "index.js",
"dependencies": {
"@babel/plugin-syntax-bigint": "^7.0.0",
JoshRosenstein marked this conversation as resolved.
Show resolved Hide resolved
"@babel/plugin-syntax-object-rest-spread": "^7.0.0",
"babel-plugin-jest-hoist": "^24.9.0"
},
Expand Down