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

Unhandled promise rejection in boot-loader prefetching #58

Closed
neodon opened this issue Sep 20, 2021 · 1 comment
Closed

Unhandled promise rejection in boot-loader prefetching #58

neodon opened this issue Sep 20, 2021 · 1 comment

Comments

@neodon
Copy link

neodon commented Sep 20, 2021

This project is exciting! Keep the momentum.

I ran into a failing unit test due to an unhandled promise rejection. I think it might have slipped by if you've only run the unit tests with an earlier version of node that just provides a warning in this situation.

Steps to reproduce:

  1. Use NodeJS v16+
  2. Run unit tests via yarn test.unit
  3. Result:
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason
"TypeError: Cannot read property 'headers' of null".] {
  code: 'ERR_UNHANDLED_REJECTION'
}
 FAIL  src/bootloader-shared.unit.ts
  ● Test suite failed to run

    Jest worker encountered 4 child process exceptions, exceeding retry limit

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)

The error appears to originate in the setUpWebWorker() function in src/bootloader-shared.ts. Specifically, this statement:

((await fetch(url)).headers.get('Link') || '').replace(
  /<([^>]*)>/g,
  prefetch as any as (_: string, url: string) => string
);

We're expecting fetch(url) to return a response with a headers key. The mock for fetch in the unit test, however, returns null:

const mockFetch = jest.fn(() => null);

I tried changing the mock to provide the minimal response object to avoid an error, and it appears to resolve the issue:

const mockFetch = jest.fn(() => ({ headers: { get: () => {}}}));
  prefetch
    setUpWebWorker
      ✓ should listen on events and fire fetch

Is this the correct way to resolve the issue? If so, I could submit a pull request.

I appreciate any insight you can provide as well. Thanks!

@neodon
Copy link
Author

neodon commented Sep 24, 2021

Looks like this is already fixed in mhevery:functional.

@neodon neodon closed this as completed Sep 24, 2021
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

1 participant