Skip to content
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

Supertest: getTestServer Not Found #594

Open
adamkpurdy opened this issue Mar 25, 2024 · 7 comments
Open

Supertest: getTestServer Not Found #594

adamkpurdy opened this issue Mar 25, 2024 · 7 comments

Comments

@adamkpurdy
Copy link

Hello and to whom it may concern.

I am trying to work with the implementation of getTestServer in Supertest documentation, and when I try to instantiate my test server I get this error:

Screenshot 2024-03-25 at 9 58 27 AM

@google-cloud/functions-framework is installed as a dependency of this project so my assumption would have been that this should be available in the import.

I've Googled a few things and I've tried updating my tsconfig, but nothing seems to work.

Thanks ahead.

@kenneth-rosario
Copy link
Contributor

Hey,

Can you share your tsconfig.json?

@adamkpurdy
Copy link
Author

Sure thing:

tsconfig.json

{
  "extends": "./node_modules/gts/tsconfig-google.json",
  "include": ["src/**/*.ts"],
  "compilerOptions": {
    "esModuleInterop": true,
    "rootDir": ".",
    "outDir": "build",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "noImplicitAny": false,
    "resolveJsonModule": true
  }
}

I tried adding:
"target": "ES2020", // or "ESNext"
"moduleResolution": "node",

@kenneth-rosario
Copy link
Contributor

Thanks,

can you try setting moduleResolution to nodenext?

@adamkpurdy
Copy link
Author

When I did that the terminal threw an error saying: "error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'." I did that and got it to compile correctly, but then my test threw a jest configuration error"

FAIL tests/endpoints.spec.ts
● Test suite failed to run

Unable to process '/Users/adampurdy/Sites/KPA_PRODUCTIONS/USSSA/ms-platform/event-api-ms/__tests__/endpoints.spec.ts', please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to inform `ts-jest` to transform /Users/blah/Sites/blah/blah/ms-platform/event-api-ms/__tests__/endpoints.spec.ts

  at TsCompiler.getCompiledOutput (node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:173:27)
  at TsJestCompiler.getCompiledOutput (node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js:14:39)
  at TsJestTransformer.exports.TsJestTransformer.TsJestTransformer.processWithTs (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:265:37)
  at TsJestTransformer.exports.TsJestTransformer.TsJestTransformer.process (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:188:24)
  at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:545:31)
  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:674:40)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:726:19)

I tried adjusting jest.config.js and that didn't work either.

Can you help me understand why I need to adjust the tsconfig, when I'm importing other @google-cloud/functions-framework functions like:

import { cloudEvent } from '@google-cloud/functions-framework'. That works fine without adjusting my tsconfig from what it was.

Thanks

@adamkpurdy
Copy link
Author

@kenneth-rosario I was able to access the getTestServer function via this assignment:
const getTestServer = require('@google-cloud/functions-framework')

I then did a little inspection of what was being returned via these three statements:

console.log(typeof getTestServer, 'getTestServer typeof')
console.log(getTestServer, 'getTestServer')
console.log(getTestServer(), 'getTestServer invocation')

And the output:

console.log
object getTestServer typeof

  at Object.<anonymous> (src/api/eventHandler/event.controller.spec.ts:8:9)

console.log
{
http: [Getter],
cloudEvent: [Getter],
typed: [Getter],
JsonInvocationFormat: [Getter]
} getTestServer

  at Object.<anonymous> (src/api/eventHandler/event.controller.spec.ts:9:9)

FAIL src/api/eventHandler/event.controller.spec.ts
● Test suite failed to run

TypeError: getTestServer is not a function

Not what I was expecting from the instructions in the documentation.

Our API application is a microservice with a small express app wrapped in a cloud function. Our approach is working great, I am just having trouble calling GCP services when trying to run integration tests using supertest test runner.

Any insight would be helpful. Thank you.

@kenneth-rosario
Copy link
Contributor

Hey @adamkpurdy can you provide a very minimal reproduction repo I can use to poke around?

Not sure if https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/main/docs/typescript.md might be of help as well.

@adamkpurdy
Copy link
Author

@kenneth-rosario Thanks for your help on this.

Looks like its a TypeScript issue. When I goto test this in a basic javascript file, it works as expected, but when I changed it into a ts file I get the issue. I know we tried adjusting the tscofig, but that doesn't seem to work. Here is my basic file.

functions-framwork.zip

@kenneth-rosario kenneth-rosario removed their assignment Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants