You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Google Chrome 122.0.6261.94 (Official Build) (64-bit)
Firebase SDK Version
10.9.0
Firebase SDK Product:
Firestore
Describe your project's tooling
Two setups:
npm, firebase, mocha, chai
npm, firebase, jsdom, vitest
Describe the problem
I wanted to write a simple unit test, using the Firestore emulator. The simplest, meaningful test I could come up with was to (1) write a Firestore document, then (2) read the Firestore document, and (3) compare expectations. Unfortunately, Firestore failed with FIRESTORE (10.10.0) INTERNAL ASSERTION FAILED: Unexpected state:
This error appears when using vitest --environment=jsdom (setup 1): using jsdom does not work. This error does not appear when using vitest --environment=node (setup 1). This error does not appear when using mocha (setup 2) as the test runner.
Using --environment=node would strip me of the opportunity to run unit tests that depend on jsdom, as far as I understand. The error message ("internal assertion failed") is also rather cryptic, and does not make it clear whether this message indicates "a bug" or "working as intended; what you're doing is not supported".
There are a few similar bug reports that I stumbled upon, as well as reports on stackoverflow. None of them were giving me an answer to: is this a bug, or a feature. I also hope that a step-by-step recipe to reproduce this issue is helpful for Firestore developers and Firestore users alike.
Steps and code to reproduce issue
I used the following steps:
Create new Firebase project and Firestore database (to make firebase init work)
Set up Firebase: firebase init with feature Firestore and Emulators
Set up module: npm init
Install mocha: npm install --save-dev mocha
Install chai: npm install --save-dev chai
Install vitest: npm install --save-dev vitest
Install firebase: npm install firebase
Create simple unit test test.mjs (we'll run this with mocha later; baseline)
Create similar unit test vitest.test.mjs (we'll run this with vitest later)
Configure shorthands for running tests in package.json: test:mocha, test:vitest-node, test:vitest-jsdom
Run tests with mocha: npm run test:mocha: good
Run tests with vitest (node): npm run test:vitest-node: good
Run tests with vitest (jsdom): npm run test:vitest-jsdom: bad
jeadorf
changed the title
Firestore emulator fails with obscure FIRESTORE (10.9.0) INTERNAL ASSERTION FAILED: Unexpected state
Firestore emulator fails with FIRESTORE (10.9.0) INTERNAL ASSERTION FAILED: Unexpected state
Apr 7, 2024
jeadorf
changed the title
Firestore emulator fails with FIRESTORE (10.9.0) INTERNAL ASSERTION FAILED: Unexpected state
Firestore emulator fails with "FIRESTORE (10.9.0) INTERNAL ASSERTION FAILED: Unexpected state" when run in jsdom environment
Apr 7, 2024
Thank you! I ran the vitest.test.mjs example with vitest --environment=jsdom and the test is now passing. I did not explicitly check whether the whether the fix made it into the version, but I assume so:
Operating System
Arch Linux 6.8.2-arch2-1
Browser Version
Google Chrome 122.0.6261.94 (Official Build) (64-bit)
Firebase SDK Version
10.9.0
Firebase SDK Product:
Firestore
Describe your project's tooling
Two setups:
Describe the problem
I wanted to write a simple unit test, using the Firestore emulator. The simplest, meaningful test I could come up with was to (1) write a Firestore document, then (2) read the Firestore document, and (3) compare expectations. Unfortunately, Firestore failed with
FIRESTORE (10.10.0) INTERNAL ASSERTION FAILED: Unexpected state
:This error appears when using
vitest --environment=jsdom
(setup 1): using jsdom does not work. This error does not appear when usingvitest --environment=node
(setup 1). This error does not appear when usingmocha
(setup 2) as the test runner.Using
--environment=node
would strip me of the opportunity to run unit tests that depend onjsdom
, as far as I understand. The error message ("internal assertion failed") is also rather cryptic, and does not make it clear whether this message indicates "a bug" or "working as intended; what you're doing is not supported".There are a few similar bug reports that I stumbled upon, as well as reports on stackoverflow. None of them were giving me an answer to: is this a bug, or a feature. I also hope that a step-by-step recipe to reproduce this issue is helpful for Firestore developers and Firestore users alike.
Steps and code to reproduce issue
I used the following steps:
firebase init
work)firebase init
with featureFirestore
andEmulators
npm init
npm install --save-dev mocha
npm install --save-dev chai
npm install --save-dev vitest
npm install firebase
test.mjs
(we'll run this withmocha
later; baseline)vitest.test.mjs
(we'll run this withvitest
later)package.json
:test:mocha
,test:vitest-node
,test:vitest-jsdom
npm run test:mocha
: goodnpm run test:vitest-node
: goodnpm run test:vitest-jsdom
: badThe key files are:
package.json:
test.mjs:
vitest.test.mjs:
The text was updated successfully, but these errors were encountered: