test: migrate fake-server to express - #2265
Merged
2 commits merged intoSep 23, 2021
Merged
Conversation
ghost
marked this pull request as draft
September 21, 2021 15:44
ghost
removed the request for review
from JamesPatrickGill
September 21, 2021 15:44
1 task
Contributor
ghost
force-pushed
the
test/migrate-to-express
branch
15 times, most recently
from
September 22, 2021 17:12
aee4417 to
c2c8422
Compare
ghost
force-pushed
the
test/migrate-to-express
branch
from
September 22, 2021 17:22
c2c8422 to
5ed7ddc
Compare
ghost
force-pushed
the
test/migrate-to-express
branch
from
September 22, 2021 17:26
5ed7ddc to
2cc7d52
Compare
ghost
marked this pull request as ready for review
September 22, 2021 17:29
ghost
self-requested a review
September 22, 2021 17:29
ghost
requested a review
from ipapast
September 22, 2021 17:29
ipapast
approved these changes
Sep 23, 2021
ipapast
left a comment
Contributor
There was a problem hiding this comment.
Get Port function for CloudConfig is fine according to the proposed changes ✅
maxjeffos
approved these changes
Sep 23, 2021
ghost
deleted the
test/migrate-to-express
branch
September 23, 2021 16:02
This was referenced Nov 10, 2021
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
It seems Restify is unable to correctly process the JSON payloads we send, at least going through
snyk monitor. This blocks tests for #2264.The issue seems to be a race condition between Restify’s bodyReader (which assigns req.body) and jsonBodyParser (which converts req.body to a js object). jsonBodyParser receives an empty req.body and fails to parse it. However, bodyReader clearly assigns the correct req.body — eventually. No idea if/why/how the other test endpoints are working. They look identical.
Restify is pretty inactive and we get deprecation warnings for it so instead of digging further, I'll try migrating us to Express and see if that fixes it. We want to use Express anyway as it's a lot more popular so has a familiar API.
I can confirm that these changes fixes the body parsing issues I had for #2264.
Changes
The main change is in
fake-server.ts. I've migratedrestifytoexpress.Due to how we previously assigned additional variables and functions on the
serverobject, it was difficult to make the code infake-servertypesafe. So I've changed a few things to make that possible and avoid the inheritance we previously relied upon forFakeServerwhich coupled us to Restify.server.requestsandserver.depGraphResponseare no longer directly exposed outside the closure. You'll need to use the new setter methods.server.listenandserver.closeto avoid changing heavily used public APIs.Restify cannot be removed yet. We need to migrate tests using the old
cli-server.jstofake-server.ts. This isn't trivial, it needs some authorisation logic migrated over too. I did remove@types/restifyascli-server.jsisn't TypeScript.I've also fixed a test in
fix.spec.tswhich was relying on fake-server's previously broken behaviour. Now fake-server is setup in the test to explicitly return a 500. While I was there I migrated all of the tests in that file to use async/await instead of callbacks. I also adding a positive test case so that it's easier to see what success looks like.Side Fixes
I've fixed the
dangerfileto properly list all known problematic files at once. Previously it was only returning the first file. I've also excluded.jsfiles as those can't use import/export syntax (which includes the dangerfile itself).Related, I've fixed the import/export issues with the files DangerJS flagged.