You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import*assinonfrom'sinon';import*asadminfrom"firebase-admin";import*aschaifrom'chai';consttest=require('firebase-functions-test')({projectId: 'project-id',});describe('Cloud Functions',()=>{
let functions: any;before(()=>{admin.initializeApp();functions=require('../src/debug');});after(()=>{test.cleanup();});afterEach(()=>{sinon.restore();});describe('callBar',()=>{it('should call bar without error',async()=>{console.log('test: about to await');awaittest.wrap(functions.bar)({},{});console.log('test: done await');})});describe('callFoo',()=>{it('should call foo without error',async()=>{constsendStub=sinon.stub();console.log('test: about to await');awaitfunctions.foo({},{send: sendStub,});console.log('test: done await');chai.assert(sendStub.calledOnceWith(200));})});});
functions/src/debug.ts:
import*asfunctionsfrom'firebase-functions';exportconstfoo=functions.https.onRequest(async(req,resp)=>{awaitdelayedPromise();resp.send(200);});exportconstbar=functions.https.onCall(async(data,context)=>{awaitdelayedPromise();});asyncfunctiondelayedPromise(){console.log('https: about to await');awaitnewPromise((resolve,reject)=>{setTimeout(()=>{resolve();},500);});console.log('https: done await');}
Steps to reproduce
Run the tests. I'm using the npm run test script from my package.json:
The test should await until all awaits from the function are done (for all function trigger types).
Actual behavior
The test does not wait for the await call from the https.onRequest trigger. This is the output from running the tests.
For the https.onRequest triggered function, the https: done await appears after the test: done await (not expected). However, for the https.onCall triggered function, the https: done await log appears before the test: done await (expected).
Cloud Functions
callBar
test: about to await
https: about to await
https: done await
test: done await
✓ should call bar without error (504ms)
callFoo
test: about to await
https: about to await
test: done await
1) should call foo without error
1 passing (785ms)
1 failing
1) Cloud Functions
callFoo
should call foo without error:
AssertionError: Unspecified AssertionError
at Object.<anonymous> (test/index.test.ts:45:18)
at Generator.next (<anonymous>)
at fulfilled (test/index.test.ts:4:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
https: done await
The text was updated successfully, but these errors were encountered:
noelmansour
changed the title
Test not waiting for await in https.onRequest triggered function
Async test does not wait for await in https.onRequest triggered function
Jul 8, 2019
Version info
firebase-functions-test: ^0.1.6
firebase-functions: ^3.0.2
firebase-admin: ^8.2.0
Test case
functions/test/index.test.ts:
functions/src/debug.ts:
Steps to reproduce
Run the tests. I'm using the
npm run test
script from my package.json:Expected behavior
The test should await until all awaits from the function are done (for all function trigger types).
Actual behavior
The test does not wait for the await call from the https.onRequest trigger. This is the output from running the tests.
For the https.onRequest triggered function, the
https: done await
appears after thetest: done await
(not expected). However, for the https.onCall triggered function, thehttps: done await
log appears before thetest: done await
(expected).The text was updated successfully, but these errors were encountered: