Closed jeadorf closed 1 month ago
Thanks for the detailed steps for reproduction. I have a PR with a fix.
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:
npm view firebase
firebase@10.11.0 | Apache-2.0 | deps: 26 | versions: 3591
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: