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

Integration test fixes in light of new Promise warnings #7

Merged
merged 2 commits into from
Dec 1, 2016

Conversation

mbland
Copy link
Owner

@mbland mbland commented Dec 1, 2016

As discovered in 18F#51, the UnhandledPromiseRejectionWarning and PromiseRejectionHandledWarning warnings were apparently added in v6.6.0 (https://nodejs.org/en/blog/release/v6.6.0/); specifically it was added by nodejs/node#8223. See also:

nodejs/node#6439
nodejs/node#8217
https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_unhandledrejection
https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_rejectionhandled
https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_warning

Test failures from test/integration-test.js after upgrading to Node v6.9.1 showed extra output such as:

  (node:39696) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): null
  (node:39696) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 2)

This was happening because scripts/slack-github-issues.js created a Hubot listener that returned a Promise so that the integration test could use .should.be.rejectedWith assertions. Rather than jump through hoops to quash the warnings, this change now causes the listener's catch handler to return the result of the rejected Promise, converting it to a fulfilled Promise in the process.

Since Hubot never used the result anyway, the only effect it has in production is to eliminate the warning messages. The tests now just check that the Promise returned by the listener callback is fulfilled with the expected error result, with practically no loss in clarity.

Also, there were test failures when I'd left HUBOT_LOG_LEVEL=debug set in the environment, which added DEBUG messages to the logging output. So there's also a commit to clear HUBOT_LOG_LEVEL in the test set up.

There were test failures when I'd left `HUBOT_LOG_LEVEL=debug` set in
the environment, which added `DEBUG` messages to the logging output.
As discovered in 18F#51, the
`UnhandledPromiseRejectionWarning` and `PromiseRejectionHandledWarning`
warnings were apparently added in v6.6.0
(https://nodejs.org/en/blog/release/v6.6.0/); specifically it was added
by nodejs/node#8223. See also:

  nodejs/node#6439
  nodejs/node#8217
  https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_unhandledrejection
  https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_rejectionhandled
  https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_warning

Test failures from `test/integration-test.js` after upgrading to Node
v6.9.1 showed extra output such as:

```
  (node:39696) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): null
  (node:39696) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 2)
```

This was happening because `scripts/slack-github-issues.js` created a
Hubot listener that returned a `Promise` so that the integration test
could use `.should.be.rejectedWith` assertions. Rather than jump through
hoops to quash the warnings, this change now causes the listener's
`catch` handler to return the result of the rejected `Promise`,
converting it to a fulfilled `Promise` in the process.

Since Hubot never used the result anyway, the only effect it has in
production is to eliminate the warning messages. The tests now just
check that the `Promise` returned by the listener callback is fulfilled
with the expected error result, with practically no loss in clarity.
@mbland mbland merged commit 113d851 into master Dec 1, 2016
@mbland mbland deleted the integration-test-fix branch December 1, 2016 16:25
mbland added a commit to mbland/unit-testing-node that referenced this pull request Apr 28, 2017
Backported from mbland/hubot-slack-github-issues#7.

As discovered in 18F/hubot-slack-github-issues#51, the
`UnhandledPromiseRejectionWarning` and `PromiseRejectionHandledWarning`
warnings were apparently added in v6.6.0
(https://nodejs.org/en/blog/release/v6.6.0/); specifically it was added
by nodejs/node#8223. See also:

  nodejs/node#6439
  nodejs/node#8217
  https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_unhandledrejection
  https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_rejectionhandled
  https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_event_warning

A test failure from `solutions/06-integration/test/integration-test.js`
after upgrading to Node v6.9.1 showed output such as:

```
-  "(node:87412) UnhandledPromiseRejectionWarning: Unhandled
     promise rejection (rejection id: 14): Error: failed to create a
     GitHub issue in 18F/handbook: received 500 response from GitHub
     API: {\"message\":\"test failure\"}\n"
```

This was happening because `scripts/slack-github-issues.js`
ignored the return value from `Middleware.execute()`, whether it was
undefined or a `Promise`. For consistency's sake (and to provide a
clearer upgrade path to the current state of
mbland/slack-github-issues), `Middleware.execute()` always returns a
`Promise`, and `scripts/slack-github-issues.js` handles and ignores any
rejected Promises.

This fixed the `integration-test.js` error, but also required minor
updates to `solutions/{05-middleware,complete}/test/middleware-test.js`.
The next commit will update the tutorial narrative to account for this
change.
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.

1 participant