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

Add a test for #1438 #1469

Merged
merged 4 commits into from Sep 20, 2020
Merged

Add a test for #1438 #1469

merged 4 commits into from Sep 20, 2020

Conversation

szmarczak
Copy link
Collaborator

@szmarczak szmarczak commented Sep 18, 2020

szm@solus ~/Desktop/got $ npm run build && ava test/promise.ts -v

> got@11.6.2 build /home/szm/Desktop/got
> del-cli dist && tsc


  ✔ promise.json() can be called before a file stream body is open
false PCancelable [Promise] {
  _cancelHandlers: [ [Function (anonymous)], [Function (anonymous)] ],
  _isPending: false,
  _isCanceled: true,
  _rejectOnCancel: false,
  _reject: [Function (anonymous)],
  _promise: Promise {
    <rejected> CancelError: Promise was canceled
        at /home/szm/Desktop/got/dist/source/as-promise/index.js:40:35
        at PCancelable.cancel (/home/szm/Desktop/got/node_modules/p-cancelable/index.js:86:6)
        at /home/szm/Desktop/got/dist/test/promise.js:71:13
        at /home/szm/Desktop/got/dist/test/helpers/with-server.js:37:15
        at processTicksAndRejections (internal/process/task_queues.js:93:5) {
      code: undefined,
      timings: undefined
    }
  },
  on: [Function (anonymous)],
  json: [Function (anonymous)],
  buffer: [Function (anonymous)],
  text: [Function (anonymous)],
  asdf: 123
} Promise {
  <rejected> CancelError: Promise was canceled
      at /home/szm/Desktop/got/dist/source/as-promise/index.js:40:35
      at PCancelable.cancel (/home/szm/Desktop/got/node_modules/p-cancelable/index.js:86:6)
      at /home/szm/Desktop/got/dist/test/promise.js:71:13
      at /home/szm/Desktop/got/dist/test/helpers/with-server.js:37:15
      at processTicksAndRejections (internal/process/task_queues.js:93:5) {
    code: undefined,
    timings: undefined
  },
  _cancelHandlers: [ [Function (anonymous)], [Function (anonymous)] ],
  _isPending: true,
  _isCanceled: false,
  _rejectOnCancel: false,
  _reject: [Function (anonymous)],
  _promise: Promise {
    <rejected> CancelError: Promise was canceled
        at /home/szm/Desktop/got/dist/source/as-promise/index.js:40:35
        at PCancelable.cancel (/home/szm/Desktop/got/node_modules/p-cancelable/index.js:86:6)
        at /home/szm/Desktop/got/dist/test/promise.js:71:13
        at /home/szm/Desktop/got/dist/test/helpers/with-server.js:37:15
        at processTicksAndRejections (internal/process/task_queues.js:93:5) {
      code: undefined,
      timings: undefined
    }
  },
  on: [Function (anonymous)],
  json: [Function (anonymous)],
  buffer: [Function (anonymous)],
  text: [Function (anonymous)],
  asdf: 123
}

  Unhandled rejection in test/promise.ts

  CancelError: Promise was canceled

  › dist/source/as-promise/index.js:40:35
  › PCancelable.cancel (node_modules/p-cancelable/index.js:86:6)
  › dist/test/promise.js:71:13
  › dist/test/helpers/with-server.js:37:15

  ─

  1 test passed
  1 unhandled rejection

@szmarczak
Copy link
Collaborator Author

@sindresorhus Do you know why it says unhandled rejection? I can clearly see that these promises are the same but p === promise gives false 🤯

@Giotino
Copy link
Collaborator

Giotino commented Sep 19, 2020

The promises are not the same object.

The first is generated by this:
https://github.com/sindresorhus/got/blob/weird-rejection/source/as-promise/index.ts#L31

The second is a "clone" of the first generated by this:
https://github.com/sindresorhus/got/blob/weird-rejection/source/as-promise/index.ts#L175-L188

I pushed a commit that should fix the test (I've not removed your debug stuff).
But there's one more thing: is got supposed to work like that?

I think: yes. Because these are 2 different promises with different outcomes, for example the json one could fail because the response is not a JSON.

@szmarczak szmarczak merged commit c31366b into master Sep 20, 2020
@szmarczak szmarczak deleted the weird-rejection branch September 20, 2020 13:20
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

Successfully merging this pull request may close these issues.

None yet

2 participants