-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export Server #463
Export Server #463
Conversation
In order to support using `@google-cloud/functions-framework` in integration tests, add `./server` to exports
Since opening this, I've realised that I can use 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:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. However, this is intentional.
Can you file a GitHub issue first before a PR?
@@ -16,6 +16,7 @@ | |||
* @public | |||
*/ | |||
export * from './functions'; | |||
export * from './server'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lack of re-export is intentional.
The usage should be:
import {getTestServer} from '@google-cloud/functions-framework/testing';
Or, if you are trying to get server
, you can import from /server
.
See docs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, if you are trying to get server, you can import from /server.
Thanks, though server isn’t currently included in the package.json exports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Why do you want to import the internal server vs the test server?
Perhaps a different approach can be taken, since we can't export our internal server.
We have examples of integration tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my follow up comment here.
I don’t think I need this anymore as I was able to figure out how to load a function in code.
I think the docs could be updated to show how you can test a function without it existing on disk.
For those still getting |
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: