我试图建立我的测试环境来测试我的安全fules与firestore。我已经复制了这个代码从https://firebase.google.com/docs/rules/unit-tests#before_you_run_the_emulator
let testEnv : RulesTestEnvironment;
beforeAll(async () => {
testEnv = await initializeTestEnvironment({
projectId: "demo-project-1234",
firestore: {
rules: fs.readFileSync('firestore.rules', 'utf8'),
},
});
});
然而,我得到这个错误。The host and port of the firestore emulator must be specified. (You may wrap the test script with firebase emulators:exec './your-test-script' to enable automatic discovery, or specify manually via initializeTestEnvironment({firestore: {host, port}}).
有人知道怎么解决吗?
编辑
我尝试将主机和端口添加到正在运行的模拟器中,如下所示
let testEnv : RulesTestEnvironment;
beforeAll(async () => {
testEnv = await initializeTestEnvironment({
projectId: "comment-section-e9c09",
firestore: {
rules: fs.readFileSync('firestore.rules', 'utf8'),
host:'localhost',
port:8080
},
});
});
现在它似乎可以连接到我的模拟器,但当我尝试fx清除数据库时,如
test("sefse", () => {
testEnv.clearDatabase()
})
我收到以下错误[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Error: The host and port of the database emulator must be specified. (You may wrap the test script with 'firebase emulators:exec './your-test-script'' to enable automatic discovery, or specify manually via initializeTestEnvironment({database: {host, port}}).".] {
2条答案
按热度按时间bqucvtff1#
我给予你一个“摩卡为主”的出发点:security.test.js:
gg58donl2#
您是否在firebase.json文件中指定了firestore端口和规则路径?