question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firestore emulator: False negative warning about affecting production when running tests

See original GitHub issue

[REQUIRED] Environment info

firebase-tools: master (dad143c42445056014f6f48cc9dfa13156e3c186)

Platform: macOS

[REQUIRED] Test case

Discovered while testing out the fix for: #1451.

Please note I’m not familiar with javascript nor typescript so it’s very likely there is something wrong with my setup. Happy to be told that’s the case.

src/index.ts:

import * as admin from 'firebase-admin';

admin.initializeApp();

export * from './debug'

src/debug.ts:

import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import Timestamp = admin.firestore.Timestamp;

export const foo = functions.https.onRequest(async (req, resp) => {
    const firestore = admin.firestore();
    await firestore.doc('/users/foo/').set({
        time: Timestamp.now(),
        enabled: true,
    });
    resp.sendStatus(200);
});

test/index.test.ts:

import * as assert from 'assert';

import('../src/index');

describe('Cloud Functions', () => {

    describe('foo', () => {
        it('bar', () => {
            assert.strictEqual(true, true);
        });
    });
});

test/mocha.opts:

--ui mocha-typescript
--require ts-node/register test/**/*.ts
--recursive test

package.json:

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "emulators": "npm run build && firebase emulators:start",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log",
    "format": "prettier --write **/*.ts",
    "pretest": "tsc",
    "test": "mocha"
  },
  "engines": {
    "node": "8"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^8.2.0",
    "firebase-functions": "^3.1.0"
  },
  "devDependencies": {
    "@types/mocha": "^5.2.7",
    "mocha": "^6.1.4",
    "mocha-typescript": "^1.1.17",
    "prettier": "^1.18.2",
    "ts-node": "^8.3.0",
    "tslint": "^5.12.0",
    "typescript": "^3.5.2"
  },
  "private": true
}

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2015",
    "typeRoots" : ["./node_modules/@types", "./typings"]
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

[REQUIRED] Steps to reproduce

Run npm run build. Then run firebase emulators:exec "npm run test".

[REQUIRED] Expected behavior

No warning.

[REQUIRED] Actual behavior

Shows this warning: ⚠ The Cloud Firestore emulator is not running, so calls to Firestore will affect production.

Logs from running with --debug debug.txt

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
samtsterncommented, Jul 19, 2019

@noelmansour I still think this is a bug on our side but I’m glad the fix was simple.

0reactions
samtsterncommented, Jul 24, 2019

This should be fixed in 7.2.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test your Cloud Firestore Security Rules | Firebase - Google
If your tests are occasionally passing and failing, even without any changes to the tests themselves, you might need to verify that they're...
Read more >
"Unexpected" error when trying to start Local Firebase Emulators
I'm trying to start local firebase emulators to test Cloud ... services from the Functions emulator will affect production: auth, firestore, ...
Read more >
How to use Firebase emulator with Flutter - Codemagic Blog
Now, run this app using the flutter run command, and try out our new Firestore-powered counter app. Integration testing with the Firebase ...
Read more >
@firebase/firestore | Yarn - Package Manager
@firebase/firestore. owner firebase5.7mApache-2.03.8.0TS vulns 0 vulnerabilities. The Cloud Firestore component of the Firebase JS SDK.
Read more >
Using TDD to Test and Deploy Firestore Security Rules Locally
Enable the Authentication Emulator and Firestore Emulator then hit ... so that they are active on your production database you can run:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found