Closed penx closed 2 years ago
Since opening this, I've realised that I can use getTestServer
as follows:
import { http } from "@google-cloud/functions-framework";
import { getTestServer } from "@google-cloud/functions-framework/testing";
http(
"remixServer",
createFirebaseHandler({
build: fixture.build,
mode: "production",
})
);
let functionsServer = getTestServer("remixServer");
However:
import { getTestServer } from "@google-cloud/functions-framework/testing"
(Cannot find module '@google-cloud/functions-framework/testing' or its corresponding type declarations.ts(2307)), which may be resolved by https://github.com/GoogleCloudPlatform/functions-framework-nodejs/pull/461getServer
would be usefulFor those still getting Cannot find module '@google-cloud/functions-framework/testing' or its corresponding type declarations.ts(2307)
in modern times, the fix is here as dimip1606 calls out. I note that "moduleResolution": "nodenext"
needs to go under compilerOptions
, not at the top level.
Add
export * from server
toindex.ts
.Use case
I would like to use
@google-cloud/functions-framework
for integration tests of a Remix Firebase functions adapter, to start and stop a functions server during Playwright tests.The existing integration tests for Remix use their Express adapter:
https://github.com/remix-run/remix/blob/6a2bf52d9ca60e2ce6459ebe72df28e6a568ed26/integration/helpers/create-fixture.ts#L97-L121
I would like to run the same tests against a Firebase adapter I am working on.
The difference between the Express adapter and Firebase adapter is primarily the use of rawBody, and I'd like to ensure the integration tests still succeed given this difference. I need a functions server to use in the integration tests that behaves as per production deployments of Firebase functions.
I can update the above code to the following:
...but this requires access to the
getServer
function.I looked at other libraries such as the emulators in firebase-tools, but these require the functions to exist as files on disk. In the tests above, the functions need to be created per test using
fixture.build
as an argument.The
getTestServer
exported from testing.ts has 2 issues preventing me from using it for this purpose: