Skip to content

Commit

Permalink
Merge 4b8482d into 4ca1528
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern committed Jul 23, 2019
2 parents 4ca1528 + 4b8482d commit 6b57be6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -2,3 +2,4 @@
* Allows emulated Cloud Functions to talk to production RTDB/Firestore if the emulators are not running.
* Fixes an issue where internal logs would sometimes appear in stdout.
* Improves RTDB emulator support for JWT algorithms and arbitrary Google Cloud auth tokens.
* Fixes an issue where functions:shell logs could be double escaped.
13 changes: 8 additions & 5 deletions scripts/triggers-end-to-end-tests/run.spec.js
Expand Up @@ -30,9 +30,10 @@ const FIRESTORE_FUNCTION_LOG = "========== FIRESTORE FUNCTION ==========";
* parallel emulator subprocesses.
*/
const TEST_SETUP_TIMEOUT = 20000;
const EMULATORS_STARTUP_DELAY_MS = 7000;
const EMULATORS_STARTUP_DELAY_MS = 10000;
const EMULATORS_WRITE_DELAY_MS = 5000;
const EMULATORS_SHUTDOWN_DELAY_MS = 2000;
const EMULATORS_SHUTDOWN_DELAY_MS = 5000;
const EMULATOR_TEST_TIMEOUT = EMULATORS_WRITE_DELAY_MS * 2;

/*
* Realtime Database and Firestore documents we used to verify
Expand Down Expand Up @@ -170,9 +171,11 @@ describe("database and firestore emulator function triggers", function() {
var test;

before(function(done) {
this.timeout(TEST_SETUP_TIMEOUT);

expect(FIREBASE_PROJECT).to.not.be.an("undefined");
expect(FIREBASE_PROJECT).to.not.be.null;
this.timeout(TEST_SETUP_TIMEOUT);

async.series(
[
function(done) {
Expand Down Expand Up @@ -285,7 +288,7 @@ describe("database and firestore emulator function triggers", function() {
});

it("should write to the database emulator", function(done) {
this.timeout(EMULATORS_WRITE_DELAY_MS);
this.timeout(EMULATOR_TEST_TIMEOUT);

test.writeToRtdb(function(err, response) {
expect(err).to.be.null;
Expand All @@ -295,7 +298,7 @@ describe("database and firestore emulator function triggers", function() {
});

it("should write to the firestore emulator", function(done) {
this.timeout(EMULATORS_WRITE_DELAY_MS * 2);
this.timeout(EMULATOR_TEST_TIMEOUT);

test.writeToFirestore(function(err, response) {
expect(err).to.be.null;
Expand Down
19 changes: 16 additions & 3 deletions src/localFunction.js
Expand Up @@ -127,9 +127,22 @@ LocalFunction.prototype._requestCallBack = function(err, response, body) {
return console.warn("\nERROR SENDING REQUEST: " + err);
}
var status = response ? response.statusCode + ", " : "";
return console.log(
"\nRESPONSE RECEIVED FROM FUNCTION: " + status + JSON.stringify(body, null, 2)
);

// If the body is a string we want to check if we can parse it as JSON
// and pretty-print it. We can't blindly stringify because stringifying
// a string results in some ugly escaping.
var bodyString = body;
if (typeof body === "string" || body instanceof string) {
try {
bodyString = JSON.stringify(JSON.parse(bodyString), null, 2);
} catch (e) {
// Ignore
}
} else {
bodyString = JSON.stringify(body, null, 2);
}

return console.log("\nRESPONSE RECEIVED FROM FUNCTION: " + status + bodyString);
};

LocalFunction.prototype._call = function(data, opts) {
Expand Down

0 comments on commit 6b57be6

Please sign in to comment.