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

chore(deps): update express to v5 & jest deprecations #1502

Merged
merged 3 commits into from
Oct 8, 2024

Conversation

Imod7
Copy link
Contributor

@Imod7 Imod7 commented Oct 8, 2024

Description

Closes #1492

The changes in this PR include the following :

  • Updates express to v5.0.0
  • Updates also express related types packages
  • Replaces deprecated jest matchers with their native ones
  • Updates the code so it builds corrently

Migrating to Express 5

Some highlights

  • res.send(obj, status) becomes res.status(status).send(obj).
  • Express 5 will handle rejections from Promises returned from middleware or route handlers by passing the rejection as the first argument to next.
  • The app.router object, which was removed in Express 4, has made a comeback in Express 5.

🧑‍💻 Code Updates 🧑‍💻

src/App.ts
Adjusted the syntax (basically just the brackets) of app.get to be as expected. I was thinking that I needed to change the syntax of res.send(... to res.status(status).send(... (based on the v5.0.0 changes) but it is not needed. I think it is because we do not use status.

AbstractControllers.spec.ts
It does not expect any return values

Type 'Promise<string>' is not assignable to type 'Promise<void>'

I just changed it so it does not return the "Great success!" message and just console.log's it.

testTools.ts and util.ts
I get a floating-promises error from the linter

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be....

so I just added the async - await syntax to the middleware calls.

Jest Deprecations

Replaced the following matchers :

  • toBeCalled
  • toBeCalledWith
  • toBeCalledTimes

with the corresponding ones :

  • toHaveBeenCalled
  • toHaveBeenCalledWith
  • toHaveBeenCalledTimes

based on this PR.

⚠️ Important Note ⚠️

When running yarn upgrade-interactive it suggests as latest version the ^4.21.0 for the express package, even though currently the package is in ^5.0.0. This feels a bit counterintuitive but I think it is because express 5.0.0 is not yet the default one.

Checks

  • yarn build
  • yarn lint --fix
  • yarn test
  • yarn test:latest-e2e-tests
  • yarn test:historical-e2e-tests

@Imod7 Imod7 requested a review from a team as a code owner October 8, 2024 10:50
Copy link
Contributor

@bee344 bee344 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Contributor

@filvecchiato filvecchiato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@Imod7 Imod7 merged commit 28e039e into master Oct 8, 2024
15 checks passed
@Imod7 Imod7 deleted the domi-express-jest branch October 8, 2024 12:10
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.

Express 5.0 is out
3 participants