sindresorhus / gulp-mocha

Run Mocha tests
MIT License
375 stars 91 forks source link

BigInt support (mocha v8.3+) #202

Closed chharvey closed 3 years ago

chharvey commented 3 years ago

Original comment:

I’m getting this issue with Node.js’s built-in `assert.strictEqual` function only when using with Mocha. When running **Node (v14.15.0)** on the command line, ```js assert.strictEqual(0n, 1n); ``` I get the error: > Uncaught AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: > > 0n !== 1n This is as expected, as the error reports what it should report. But when running in **Mocha** (with gulp and ts-node): ```js import * as assert from 'assert'; // Node.js describe('module', () => { it('test', () => { assert.strictEqual(0n, 1n); }); }); ``` >TypeError: Do not know how to serialize a BigInt > at JSON.stringify (<anonymous>) > at processImmediate (internal/timers.js:461:21) Any idea why `assert.strictEqual` runs differently in Mocha than in the Node.js REPL?
Configurations: (click to expand) Gulp file:
function test() {
    return gulp.src('./test/**/*.ts')
        .pipe(mocha({
            require: 'ts-node/register',
        }))
}
NPM dependencies:
  "devDependencies": {
    "@types/mocha": "^8.0.0",
    "@types/node": "^14.0.1",
    "gulp": "^4.0.2",
    "gulp-mocha": "^7.0.2",
    "gulp-typescript": "^5.0.1",
    "ts-node": "^9.0.0",
    "typescript": "~4.0.3"
  },

This seems to be fixed with https://github.com/mochajs/mocha/pull/4112, but that is in mocha v8.3.0, and this project only uses version ^6. I tried submitting a PR to retroactively apply the fix to v6, but they denied saying that LTS is not pursued.

One possible solution to this issue would be to upgrade to mocha ^8.3.