[go: nahoru, domu]

Skip to content

Commit

Permalink
integration framework: request -> node-fetch (#2787)
Browse files Browse the repository at this point in the history
* request -> fetch

* statusCode -> status

* await on the response data
  • Loading branch information
bkendall committed Nov 11, 2020
1 parent 50a2aab commit cd6e7ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions scripts/extensions-emulator-tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("extension emulator", () => {

const res = await test.invokeHttpFunction(TEST_FUNCTION_NAME, FIREBASE_PROJECT_ZONE);

expect(res.statusCode).to.equal(200);
expect(res.body).to.equal("Hello World from greet-the-world");
expect(res.status).to.equal(200);
await expect(res.text()).to.eventually.equal("Hello World from greet-the-world");
});
});
21 changes: 8 additions & 13 deletions scripts/integration-helpers/framework.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as request from "request";
import fetch, { Response } from "node-fetch";

import { CLIProcess } from "./cli";

Expand Down Expand Up @@ -124,35 +124,30 @@ export class TriggerEndToEndTest {
return this.cliProcess ? this.cliProcess.stop() : Promise.resolve();
}

invokeHttpFunction(name: string, zone = FIREBASE_PROJECT_ZONE): Promise<request.Response> {
invokeHttpFunction(name: string, zone = FIREBASE_PROJECT_ZONE): Promise<Response> {
const url = `http://localhost:${[this.functionsEmulatorPort, this.project, zone, name].join(
"/"
)}`;
return new Promise((resolve, reject) => {
request.get(url, {}, (err, res) => {
if (err) return reject(err);
resolve(res);
});
});
return fetch(url);
}

writeToRtdb(): Promise<request.Response> {
writeToRtdb(): Promise<Response> {
return this.invokeHttpFunction("writeToRtdb");
}

writeToFirestore(): Promise<request.Response> {
writeToFirestore(): Promise<Response> {
return this.invokeHttpFunction("writeToFirestore");
}

writeToPubsub(): Promise<request.Response> {
writeToPubsub(): Promise<Response> {
return this.invokeHttpFunction("writeToPubsub");
}

writeToAuth(): Promise<request.Response> {
writeToAuth(): Promise<Response> {
return this.invokeHttpFunction("writeToAuth");
}

writeToScheduledPubsub(): Promise<request.Response> {
writeToScheduledPubsub(): Promise<Response> {
return this.invokeHttpFunction("writeToScheduledPubsub");
}

Expand Down
10 changes: 5 additions & 5 deletions scripts/triggers-end-to-end-tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ describe("database and firestore emulator function triggers", () => {
this.timeout(EMULATOR_TEST_TIMEOUT);

const response = await test.writeToRtdb();
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
});

it("should write to the firestore emulator", async function() {
// eslint-disable-next-line no-invalid-this
this.timeout(EMULATOR_TEST_TIMEOUT);

const response = await test.writeToFirestore();
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);

/*
* We delay again here because the functions triggered
Expand Down Expand Up @@ -193,7 +193,7 @@ describe("pubsub emulator function triggers", () => {
this.timeout(EMULATOR_TEST_TIMEOUT);

const response = await test.writeToPubsub();
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
await new Promise((resolve) => setTimeout(resolve, EMULATORS_WRITE_DELAY_MS));
});

Expand All @@ -206,7 +206,7 @@ describe("pubsub emulator function triggers", () => {
this.timeout(EMULATOR_TEST_TIMEOUT);

const response = await test.writeToScheduledPubsub();
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
await new Promise((resolve) => setTimeout(resolve, EMULATORS_WRITE_DELAY_MS));
});

Expand Down Expand Up @@ -246,7 +246,7 @@ describe("auth emulator function triggers", () => {
}

const response = await test.writeToAuth();
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
await new Promise((resolve) => setTimeout(resolve, EMULATORS_WRITE_DELAY_MS));
});

Expand Down

0 comments on commit cd6e7ef

Please sign in to comment.