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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ts-jest breaks when using native Big Integers #1684

Closed
orbmis opened this issue May 26, 2020 · 3 comments
Closed

Ts-jest breaks when using native Big Integers #1684

orbmis opened this issue May 26, 2020 · 3 comments

Comments

@orbmis
Copy link

orbmis commented May 26, 2020

馃悰 Bug Report

When running unit tests on a module that uses native JavaScript bigints, the following error is generated:

SyntaxError: /calculate.ts: Identifier directly after number (8:18)

    >  8 | const EXPONENT = 5n;

To Reproduce

Steps to reproduce the behavior:

Run any test that declares a native JavaScript bigint, e.g.:

const someValue = 3n

Expected behavior

Expected tests to handle native JavaScript bigint types. When running and building the application, bigints don't pose a problem.

Link to repo (highly encouraged)

Debug log:

The stacktrace seems to point to babel as the cuprit:

at Parser._raise (node_modules/@babel/parser/src/parser/location.js:233:45)
      at Parser.raiseWithData (node_modules/@babel/parser/src/parser/location.js:228:17)
      at Parser.raise (node_modules/@babel/parser/src/parser/location.js:212:17)
      at Parser.readNumber (node_modules/@babel/parser/src/tokenizer/index.js:1092:18)
      at Parser.getTokenFromCode (node_modules/@babel/parser/src/tokenizer/index.js:752:14)
      at Parser.nextToken (node_modules/@babel/parser/src/tokenizer/index.js:240:12)
      at Parser.next (node_modules/@babel/parser/src/tokenizer/index.js:154:10)
      at Parser.eat (node_modules/@babel/parser/src/tokenizer/index.js:161:12)
      at Parser.parseVar (node_modules/@babel/parser/src/parser/statement.js:974:16)
      at Parser.parseVarStatement (node_modules/@babel/parser/src/parser/statement.js:688:10)

envinfo

System:
    OS: MacOS Mojave 10.14.6

Npm packages:
    jest: ^25.1.0
    ts-jest: ^25.2.1
    typescript: ^3.8.3
    babel(optional): ^7.8.7
    babel-typescript: ^7.8.3
@orbmis orbmis added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels May 26, 2020
@orbmis
Copy link
Author

orbmis commented May 26, 2020

Just to update: the problem seems to be explicitly with collecting coverage, if I exclude the specified file from coverage collection, the error disappears. However, I found an easy workaround in using the following syntax:

const someValue = BigInt(3)

instead of:

const someValue = 3n

Using this workaround works perfectly for me, with caveats for other developers obviously, so I'm happy to close to the issue if you feel that's suitable.

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 26, 2020

I think jestjs/jest#9774 fixed your issue, which is available in jest 25.3

I will close the issue as not ts-jest problem :)

@ahnpnl ahnpnl closed this as completed May 26, 2020
@orbmis
Copy link
Author

orbmis commented May 26, 2020

Thanks @ahnpnl

@ahnpnl ahnpnl added 馃挰 Question and removed Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants