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 and gaxios do not work in conjunction #730

Closed
VikramTiwari opened this issue Jun 3, 2019 · 5 comments · Fixed by googleapis/gaxios#138
Closed

supertest and gaxios do not work in conjunction #730

VikramTiwari opened this issue Jun 3, 2019 · 5 comments · Fixed by googleapis/gaxios#138
Assignees
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. web

Comments

@VikramTiwari
Copy link

Environment details

  • OS: Mac OS X - 10.14.5
  • Node.js version: 10.16.0
  • npm version: 6.9.0
  • @google-cloud/storage version: 2.5.0

Steps to reproduce

  1. Using supertest to test an endpoint which runs the following code and return the files as response.
const [files] = await storage
            .bucket(bucketName)
            .getFiles({
              prefix: String(user._id),
            })
  1. While running the endpoint as normal server and sending requests, it works fine. But while running test, it breaks.
  2. Confirming that all the config, auth and service account credentials etc are properly set in test environment as well

Error log:

    TypeError: fetch is not a function

      at Gaxios.<anonymous> (node_modules/gaxios/src/gaxios.ts:70:27)
      at node_modules/gaxios/build/src/gaxios.js:19:71
      at Object.<anonymous>.__awaiter (node_modules/gaxios/build/src/gaxios.js:15:12)
      at Gaxios.request (node_modules/gaxios/build/src/gaxios.js:60:16)
      at Object.<anonymous> (node_modules/gaxios/src/index.ts:31:19)
      at node_modules/gaxios/build/src/index.js:19:71
      at Object.<anonymous>.__awaiter (node_modules/gaxios/build/src/index.js:15:12)
      at Object.request (node_modules/gaxios/build/src/index.js:37:12)
      at GoogleToken.<anonymous> (node_modules/gtoken/build/src/index.js:191:29)
      at node_modules/gtoken/build/src/index.js:13:71
      at Object.<anonymous>.__awaiter (node_modules/gtoken/build/src/index.js:9:12)
      at GoogleToken.requestToken (node_modules/gtoken/build/src/index.js:179:16)
      at GoogleToken.<anonymous> (node_modules/gtoken/build/src/index.js:125:25)
      at node_modules/gtoken/build/src/index.js:13:71
      at Object.<anonymous>.__awaiter (node_modules/gtoken/build/src/index.js:9:12)
      at GoogleToken.getTokenAsync (node_modules/gtoken/build/src/index.js:110:16)
      at GoogleToken.getToken (node_modules/gtoken/build/src/index.js:64:21)
      at JWT.<anonymous> (node_modules/google-auth-library/build/src/auth/jwtclient.js:144:40)
      at node_modules/google-auth-library/build/src/auth/jwtclient.js:22:71
      at Object.<anonymous>.__awaiter (node_modules/google-auth-library/build/src/auth/jwtclient.js:18:12)
      at JWT.refreshTokenNoCache (node_modules/google-auth-library/build/src/auth/jwtclient.js:142:16)
      at JWT.<anonymous> (node_modules/google-auth-library/build/src/auth/oauth2client.js:160:28)
      at node_modules/google-auth-library/build/src/auth/oauth2client.js:22:71
      at Object.<anonymous>.__awaiter (node_modules/google-auth-library/build/src/auth/oauth2client.js:18:12)
      at JWT.refreshToken (node_modules/google-auth-library/build/src/auth/oauth2client.js:151:16)
      at JWT.<anonymous> (node_modules/google-auth-library/build/src/auth/oauth2client.js:289:32)
      at node_modules/google-auth-library/build/src/auth/oauth2client.js:22:71
      at Object.<anonymous>.__awaiter (node_modules/google-auth-library/build/src/auth/oauth2client.js:18:12)
      at JWT.getRequestMetadataAsync (node_modules/google-auth-library/build/src/auth/oauth2client.js:271:16)
      at JWT.<anonymous> (node_modules/google-auth-library/build/src/auth/jwtclient.js:87:55)
      at node_modules/google-auth-library/build/src/auth/jwtclient.js:22:71
      at Object.<anonymous>.__awaiter (node_modules/google-auth-library/build/src/auth/jwtclient.js:18:12)
      at JWT.getRequestMetadataAsync (node_modules/google-auth-library/build/src/auth/jwtclient.js:70:16)
      at JWT.<anonymous> (node_modules/google-auth-library/build/src/auth/oauth2client.js:266:36)
      at node_modules/google-auth-library/build/src/auth/oauth2client.js:22:71
      at Object.<anonymous>.__awaiter (node_modules/google-auth-library/build/src/auth/oauth2client.js:18:12)
      at JWT.getRequestHeaders (node_modules/google-auth-library/build/src/auth/oauth2client.js:265:16)
      at GoogleAuth.<anonymous> (node_modules/google-auth-library/build/src/auth/googleauth.js:598:42)
      at fulfilled (node_modules/google-auth-library/build/src/auth/googleauth.js:19:58)
@JustinBeckwith
Copy link
Contributor

Greetings! Is there any chance you're trying to run this in the browser, via create-react-app, webpack, rollup, electron, any of that stuff?

@VikramTiwari
Copy link
Author

Hey @JustinBeckwith No, this is just an express based API server running purely on nodejs on GAE. While it runs as server, it works fine. It's only during testing that I see this happen. Very weird. Initially I thought it was auth but checked everything with test credentials and not seeing this error happen at all.

I will keep the issue updated if I find anything.

@bcoe
Copy link
Contributor

bcoe commented Jun 4, 2019

@VikramTiwari could you share the code you are executing in your it block in supertest?

If I understand correctly, you are able to manually curl the endpoint, but the supertest request fails?

@bcoe bcoe added needs more info This issue needs more information from the customer to proceed. status: investigating The issue is under investigation, which is determined to be non-trivial. labels Jun 4, 2019
@yoshi-automation yoshi-automation added triage me I really want to be triaged. and removed triage me I really want to be triaged. labels Jun 4, 2019
@VikramTiwari
Copy link
Author

Hey @bcoe Yes, that is correct. Here's the failing test.

it('Returns download urls', async () => {
    return request(app)
      .post('/')
      .send({ op: 'downloadUrls' })
      .set({
        Authorization: `Bearer ${testUser.bearerToken}`,
        Accept: 'application/json',
      })
      .expect('Content-Type', /json/)
      .expect(200)
      .then(response => {
        expect(response.body.length).toBeGreaterThan(0)
      })
  })

@bcoe bcoe added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed needs more info This issue needs more information from the customer to proceed. status: investigating The issue is under investigation, which is determined to be non-trivial. labels Jun 7, 2019
@bcoe bcoe changed the title fetch is not a function supertest and gaxios do not work in conjunction Jun 7, 2019
@bcoe
Copy link
Contributor

bcoe commented Jun 7, 2019

@VikramTiwari nothing immediately jumps out at me (from your logic, or the stacktrace you shared initially).

It might also be worth opening an issue on the supertest repo, I'm wondering if perhaps a global is being overridden; resulting in fetch having a different value than gaxios expects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. web
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants