setInterval(...).unref is not a function when testing @google-cloud/firestore
See original GitHub issue🐛 Bug Report
When I use Jest to test data retieval from google-cloud firestore I get the error :
TypeError: setInterval(…).unref is not a function at new unref (…/…/node_modules/.pnpm/registry.npmjs.org/@grpc/grpc-js/0.6.6/node_modules/@grpc/grpc-js/build/src/subchannel-pool.js:55:36) at Object.<anonymous> (…/…/node_modules/.pnpm/registry.npmjs.org/@grpc/grpc-js/0.6.6/node_modules/@grpc/grpc-js/build/src/subchannel-pool.js:99:30) at Object.require (…/…/node_modules/.pnpm/registry.npmjs.org/@grpc/grpc-js/0.6.6/node_modules/@grpc/grpc-js/build/src/channel.js:21:27) at Object.require (…/…/node_modules/.pnpm/registry.npmjs.org/@grpc/grpc-js/0.6.6/node_modules/@grpc/grpc-js/build/src/index.js:22:19) at Object.require (…/…/node_modules/.pnpm/registry.npmjs.org/google-gax/1.7.0/node_modules/google-gax/build/src/grpc.js:37:14) at Object.require (…/…/node_modules/.pnpm/registry.npmjs.org/google-gax/1.7.0/node_modules/google-gax/build/src/index.js:33:16) at Object.require (…/…/node_modules/.pnpm/registry.npmjs.org/@google-cloud/firestore/2.4.0/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:16:13) at Object.require (…/…/node_modules/.pnpm/registry.npmjs.org/@google-cloud/firestore/2.4.0/node_modules/@google-cloud/firestore/build/src/v1/index.js:15:25) at Function.require (…/…/node_modules/.pnpm/registry.npmjs.org/@google-cloud/firestore/2.4.0/node_modules/@google-cloud/firestore/build/src/index.js:1154:18) at ClientPool.v1 [as clientFactory] (…/…/node_modules/.pnpm/registry.npmjs.org/@google-cloud/firestore/2.4.0/node_modules/@google-cloud/firestore/build/src/index.js:315:45) at ClientPool.clientFactory [as acquire] (…/…/node_modules/.pnpm/registry.npmjs.org/@google-cloud/firestore/2.4.0/node_modules/@google-cloud/firestore/build/src/pool.js:64:35) at ClientPool.acquire [as run] (…/…/node_modules/.pnpm/registry.npmjs.org/@google-cloud/firestore/2.4.0/node_modules/@google-cloud/firestore/build/src/pool.js:121:29) at Firestore.run [as request] (…/…/node_modules/.pnpm/registry.npmjs.org/@google-cloud/firestore/2.4.0/node_modules/@google-cloud/firestore/build/src/index.js:962:33) at request (…/…/node_modules/.pnpm/registry.npmjs.org/@google-cloud/firestore/2.4.0/node_modules/@google-cloud/firestore/build/src/reference.js:1706:18)
To Reproduce
- install package ’ @google-cloud/firestore ’ (version 2.4.0 )
- Obviously you need a google account, and a firestore database with some data in it.
Test Code
import { Firestore } from '@google-cloud/firestore';
describe('my bugy tests', () => {
it('test bugy test', () => {
expect.hasAssertions();
// Monkey Patch
//setInterval().__proto__.unref = function () {}
const firestore = new Firestore({
projectId: 'dummy-project',
keyFilename: '/Users/igor/proj1/gcp-credentials.json'
});
return firestore.collection('testCollection').listDocuments().then(r => {
return firestore.getAll(...r).then(r2 => {
console.log(r2)
expect(
r2
).toHaveLength(2)
})
})
});
});
Workaround
I was able to code an ungly workaround by using this line of code
setInterval().__proto__.unref = function () {}
If you uncomment this line of code in the code example below, the test executes as expected.
Jest Debug output
{
"configs": [
{
"automock": false,
"browser": false,
"cache": true,
"cacheDirectory": "/var/folders/zm/bcn7tz5157j76dhskz618z4c0000gn/T/jest-cache-services",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"cwd": "/Users/igor/proj1/packages/wear-services",
"dependencyExtractor": null,
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"filter": null,
"forceCoverageMatch": [],
"globalSetup": null,
"globalTeardown": null,
"globals": {},
"haste": {
"computeSha1": false,
"providesModuleNodeModules": [],
"throwOnModuleCollision": false
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"moduleNameMapper": {},
"modulePathIgnorePatterns": [],
"name": "b5e7db77dc957df263fa613d7f9236aa",
"prettierPath": "prettier",
"resetMocks": false,
"resetModules": false,
"resolver": null,
"restoreMocks": false,
"rootDir": "/Users/igor/proj1/packages/wear-services",
"roots": [
"/Users/igor/proj1/packages/wear-services/test"
],
"runner": "jest-runner",
"setupFiles": [],
"setupFilesAfterEnv": [],
"skipFilter": false,
"snapshotSerializers": [],
"testEnvironment": "/Users/igor/proj1/node_modules/.pnpm/registry.npmjs.org/jest-environment-jsdom/24.9.0/node_modules/jest-environment-jsdom/build/index.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": [],
"testRunner": "/Users/igor/proj1/node_modules/.pnpm/registry.npmjs.org/jest-jasmine2/24.9.0/node_modules/jest-jasmine2/build/index.js",
"testURL": "http://localhost",
"timers": "real",
"transform": [
[
"^.+\\.jsx?$",
"/Users/igor/proj1/node_modules/.pnpm/registry.npmjs.org/babel-jest/24.9.0_@babel+core@7.6.2/node_modules/babel-jest/build/index.js"
],
[
"^.+\\.tsx?$",
"/Users/igor/proj1/node_modules/.pnpm/registry.npmjs.org/ts-jest/24.1.0_jest@24.9.0/node_modules/ts-jest/dist/index.js"
]
],
"transformIgnorePatterns": [
"/!node_modules\\/lodash-es/"
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": 0,
"changedFilesWithAncestor": false,
"collectCoverage": false,
"collectCoverageFrom": null,
"coverageDirectory": "/Users/igor/proj1/packages/wear-services/coverage",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"coverageThreshold": null,
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"filter": null,
"globalSetup": null,
"globalTeardown": null,
"json": false,
"listTests": false,
"maxConcurrency": 5,
"maxWorkers": 3,
"noStackTrace": false,
"nonFlagArgs": [
"database/publishedProducts"
],
"notify": false,
"notifyMode": "failure-change",
"onlyChanged": false,
"passWithNoTests": false,
"projects": null,
"rootDir": "/Users/igor/proj1/packages/wear-services",
"runTestsByPath": false,
"skipFilter": false,
"testFailureExitCode": 1,
"testPathPattern": "database/publishedProducts",
"testResultsProcessor": null,
"testSequencer": "/Users/igor/proj1/node_modules/.pnpm/registry.npmjs.org/@jest/test-sequencer/24.9.0/node_modules/@jest/test-sequencer/build/index.js",
"updateSnapshot": "new",
"useStderr": false,
"verbose": null,
"watch": false,
"watchman": true
},
"version": "24.9.0"
}
envinfo
System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz
Binaries:
Node: 12.11.1 - /usr/local/bin/node
npm: 6.11.3 - /usr/local/bin/npm
npmPackages:
jest: ^24.9.0 => 24.9.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5
Top GitHub Comments
In case someone is facing the same issue using
jest --env node
is the solution. Thank you for your advice.unref
is a node timer thing, so make sure to run your tests usingjets-environment-node
and not the default jsdom env