Skip to content

Commit 7792cf7

Browse files
committed
fix linters and test setup.
1 parent 604a499 commit 7792cf7

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

spec/helper.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ export interface RunHandlerResult {
4040
* data populated into the response.
4141
*/
4242
export function runHandler(
43-
handler: express.Handler,
43+
handler: (
44+
req: https.Request,
45+
res: express.Response,
46+
next?: express.NextFunction
47+
) => void | Promise<void>,
4448
request: https.Request
4549
): Promise<RunHandlerResult> {
4650
return new Promise((resolve) => {
@@ -119,7 +123,7 @@ export function runHandler(
119123
}
120124
}
121125
const response = new MockResponse();
122-
handler(request, response as any, () => undefined);
126+
return void handler(request, response as any, () => undefined);
123127
});
124128
}
125129

spec/v1/providers/httpsAsync.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ describe("CloudHttpsBuilder async onRequest", () => {
1717
});
1818

1919
it("should catch and log unhandled rejections in async onRequest handlers", async () => {
20-
const error = new Error("Async error");
20+
const err = new Error("boom");
2121
const fn = https.onRequest(async (_req, _res) => {
22-
throw error;
22+
await Promise.resolve();
23+
throw err;
2324
});
2425

2526
const req = new MockRequest({}, {});
2627
req.method = "GET";
2728

28-
await runHandler(fn, req as any);
29+
const result = await runHandler(fn, req as any);
2930

30-
expect(loggerSpy.calledWith("Unhandled error", error)).to.be.true;
31+
expect(loggerSpy.calledWith("Unhandled error", err)).to.be.true;
32+
expect(result.status).to.equal(500);
33+
expect(result.body).to.equal("Internal Server Error");
3134
});
3235

3336
it("should not log if handler completes successfully", async () => {
3437
const fn = https.onRequest(async (_req, res) => {
38+
await Promise.resolve();
3539
res.send(200);
3640
});
3741

spec/v2/providers/httpsAsync.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ describe("v2.https.onRequest async", () => {
1717
});
1818

1919
it("should catch and log unhandled rejections in async onRequest handlers", async () => {
20-
const error = new Error("Async error v2");
20+
const err = new Error("boom");
2121
const fn = https.onRequest(async (_req, _res) => {
22-
throw error;
22+
await Promise.resolve();
23+
throw err;
2324
});
2425

2526
const req = new MockRequest({}, {});
2627
req.method = "GET";
2728

28-
await runHandler(fn, req as any);
29+
const result = await runHandler(fn, req as any);
2930

30-
expect(loggerSpy.calledWith("Unhandled error", error)).to.be.true;
31+
expect(loggerSpy.calledWith("Unhandled error", err)).to.be.true;
32+
expect(result.status).to.equal(500);
33+
expect(result.body).to.equal("Internal Server Error");
3134
});
3235

3336
it("should not log if handler completes successfully", async () => {
3437
const fn = https.onRequest(async (_req, res) => {
38+
await Promise.resolve();
3539
res.send(200);
3640
});
3741

0 commit comments

Comments
 (0)