在本地运行Firestore供测试用 [英] Running Firestore local e.g. for testing
问题描述
是否可以在本地运行firestore(例如出于测试目的)?
Is there a way to run firestore locally (e.g. for testing purposes)?
针对数据库编写测试的方法是什么? (除了使用模拟)
What would the approach to write tests against the DB (except of using mocks)
推荐答案
2020年更新:
现在还有一个< a href = https://firebase.google.com/docs/emulator-suite rel = nofollow noreferrer> Firebase模拟器套件。
本地仿真(至少出于测试Firestore规则的目的)被降级了在Firebase Summit 2018上使用 @ firestore / testing
,并记录在测试您的Cloud Firestore安全规则。
Local emulation, at least for the purpose of testing Firestore rules, was demoed at Firebase Summit 2018 using @firestore/testing
and documented under Test your Cloud Firestore Security Rules.
看起来像这样:
const firebase = require(`@firebase/testing`)
const app = firebase.initializeTestApp({
projectId: 'my-project',
auth: { uid: '123', email: 'name@domain.com' }
})
const attempt = app.firestore()
.collection('colId').doc('docId').get()
firebase.assertFails(attempt)
firebase.assertSucceeds(attempt)
这似乎很早,因为发行说明中没有对此进行说明,但是我敢肯定它会随之而来。
It seems early-on, as it's not been noted in the release-notes, but I'm sure it's coming along.
这篇关于在本地运行Firestore供测试用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!