Building my react/redux/flowtype app, writing tests, all is well. As soon as I bring it firestore into one of my redux action creators, the most basic app test now fails. (But the app works as expected). The test suite (code below) fails to initialize with the folowing error:
โ Test suite failed to run
Cannot find module 'grpc' from 'grpc_connection.js' at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17) at Object.<anonymous> (node_modules/@firebase/firestore/dist/cjs/src/platform_node/grpc_connection.js:29:12)
? Include a jest test against app that includes firestore downstream. If I comment out from my app
// require('firebase/firestore');
// const db = Firebase.firestore();
then all tests pass again (but app breaks, of course.)
import React from 'react';
import App from '../App';
describe('Main App component', () => {
it('matches snapshot', () => {
// as soon as I include firestore anywhere in my app I get this error:
// Cannot find module 'grpc' from 'grpc_connection.js'
// and test fails
const wrapper = shallow(
<App />
);
expect(wrapper).toMatchSnapshot();
})
it('above is broken, firestore issue, see notes', () => {
expect(true).toEqual(true)
})
})
I'm having the exact same issue with Jest
Here is a test app to reproduce:
any update on this? I am also facing the same issue on firebase": "^4.5.2",
@jakelowen What are you using to test? If it is jest, see the explainer below. If not, could you provide me an example repo so I can see what is going on?
@mathieuseguin in the repro you sent you are using jest with the --env=jsdom flag, but without the --browser flag. They are actually both required to properly test browser code.
Firebase specifies a pkg.browser so providing Jest's browser flag is required.
For your demo, simply adding a --browser to the end of the test script alleviated the issue for me.
Amazing! Thanks @jshcrowthe!
It does resolve the issue for me.
That fixed it for me as well. Thanks @jshcrowthe!
Most helpful comment
@jakelowen What are you using to test? If it is jest, see the explainer below. If not, could you provide me an example repo so I can see what is going on?
@mathieuseguin in the repro you sent you are using jest with the
--env=jsdomflag, but without the--browserflag. They are actually both required to properly test browser code.Firebase specifies a
pkg.browserso providing Jest's browser flag is required.For your demo, simply adding a
--browserto the end of the test script alleviated the issue for me.