0

When running all my tests together, the makeDocumentSnapshot call gives error SyntaxError: Unexpected token u in JSON at position 0 at firebase-functions-test/lib/app.js:41:65, which is basically that process.env.FIREBASE_CONFIG being undefined. However, if I just run the test individually, it passes.

My file structure

src |-- foo |-- index.ts |-- foo.ts |-- index.ts test |-- test.ts |-- foo |-- foo.test.ts package.json { "test": "mocha -r ts-node/register test/**/*.test.ts" } 
// index.ts import * as admin from 'firebase-admin'; admin.initializeApp(); admin.firestore().settings({ ignoreUndefinedProperties: true }); export * as foo from './foo/index'; 
// test.ts import Test from 'firebase-functions-test'; export default Test({ databaseURL, storageBucket, projectId }, 'test/service-account-key.json'); 
// foo.test.ts import test from '../test'; import * as myFunctions from '../../src/index'; describe('foo()', () => { const wrapped = test.wrap(myFunctions.foo.foo); it ('should do this', async () => { // This line gives error when running all tests together, // but not when running this test individually with // describe.only(). const snapshot = test.firestore.makeDocumentSnapshot(...) ... }); }); 
3
  • Can you share what is there in firebase-functions-test/lib/app.js:41:65? Or else can you share your firebase-functions-test/lib/app.js file? Commented Jan 6, 2022 at 12:31
  • Here: ibb.co/4TVq6md Commented Jan 7, 2022 at 1:54
  • Have you checked the thread, thread? Commented Jan 17, 2022 at 5:05

1 Answer 1

0

Follow the official guide for Initializing Firebase Test SDK for Cloud Functions, and see if this helps your use case:

// At the top of test/index.test.js const test = require('firebase-functions-test')({ databaseURL: 'https://my-project.firebaseio.com', storageBucket: 'my-project.appspot.com', projectId: 'my-project', }, 'path/to/serviceAccountKey.json'); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.