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

[credential-provider-imds]: unit tests are failing in Node.js v20.3.0 #4827

Closed
3 tasks done
trivikr opened this issue Jun 12, 2023 · 2 comments · Fixed by #4840
Closed
3 tasks done

[credential-provider-imds]: unit tests are failing in Node.js v20.3.0 #4827

trivikr opened this issue Jun 12, 2023 · 2 comments · Fixed by #4840
Labels
bug This issue is a bug. p2 This is a standard priority issue queued This issues is on the AWS team's backlog

Comments

@trivikr
Copy link
Member

trivikr commented Jun 12, 2023

Checkboxes for prior research

Describe the bug

The unit tests of credential-provider-imds throw the following error in Node.js v20.3.0:

    Expected: [SyntaxError: Unexpected token . in JSON at position 0]
    Received: [SyntaxError: Unexpected token '.', "." is not valid JSON]

This may or may not have impact SDK usage. The unit test needs to be fixed.

SDK version number

main

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.3.0

Reproduction Steps

Run unit tests in credential-provider-imds

Observed Behavior

$ credential-provider-imds> yarn test
...
 FAIL  src/fromInstanceMetadata.spec.ts
  ● fromInstanceMetadata › throws SyntaxError if httpRequest returns unparseable creds

    expect(received).rejects.toEqual(expected) // deep equality

    Expected: [SyntaxError: Unexpected token . in JSON at position 0]
    Received: [SyntaxError: Unexpected token '.', "." is not valid JSON]

      182 |     (retry as jest.Mock).mockImplementation((fn: any) => fn());
      183 |
    > 184 |     await expect(fromInstanceMetadata()()).rejects.toEqual(new SyntaxError("Unexpected token . in JSON at position 0"));
          |                                                    ^
      185 |     expect(retry).toHaveBeenCalledTimes(2);
      186 |     expect(httpRequest).toHaveBeenCalledTimes(3);
      187 |     expect(fromImdsCredentials).not.toHaveBeenCalled();

      at Object.toEqual (../../node_modules/expect/build/index.js:241:22)
      at src/fromInstanceMetadata.spec.ts:184:52
      at src/fromInstanceMetadata.spec.ts:8:71
      at Object.<anonymous>.__awaiter (src/fromInstanceMetadata.spec.ts:4:12)
      at Object.<anonymous> (src/fromInstanceMetadata.spec.ts:177:80)

 PASS  src/config/EndpointConfigOptions.spec.ts
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.

Test Suites: 1 failed, 10 passed, 11 total
Tests:       1 failed, 74 passed, 75 total
Snapshots:   0 total
Time:        4.943 s
Ran all test suites.
error Command failed with exit code 1.

Expected Behavior

$ credential-provider-imds> yarn test
...
Test Suites: 11 passed, 11 total
Tests:       75 passed, 75 total
Snapshots:   0 total
Time:        4.505 s, estimated 5 s
Ran all test suites.
✨  Done in 5.04s.

Possible Solution

No response

Additional Information/Context

No response

@trivikr trivikr added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 12, 2023
@RanVaknin RanVaknin added p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jun 12, 2023
@yenfryherrerafeliz yenfryherrerafeliz added the queued This issues is on the AWS team's backlog label Jun 13, 2023
@trivikr trivikr changed the title [credential-provider-imds]: [credential-provider-imds]: unit tests are failing in Node.js v20.3.0 Jun 13, 2023
@trivikr
Copy link
Member Author

trivikr commented Jun 14, 2023

This happens as SyntaxError message has changed in Node.js 20.x

Node.js <=18.x

Welcome to Node.js v18.16.0.
Type ".help" for more information.
> JSON.parse(".")
Uncaught SyntaxError: Unexpected token . in JSON at position 0

Node.js 20.x

Welcome to Node.js v20.3.0.
Type ".help" for more information.
> JSON.parse(".")
Uncaught SyntaxError: Unexpected token '.', "." is not valid JSON

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. p2 This is a standard priority issue queued This issues is on the AWS team's backlog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants