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

Refactor handling of response's 'end' in forwarder #301

Conversation

DamienCassou
Copy link
Contributor

The only purpose of this refactoring is to simplify the implementation
of a new feature.

This refactoring propagates the limitation that the error code is a
string of only one character. This limitation is already present in
the code handling the 'readable' event.

It would be better to remove this limitation though but I wanted your
point of view on this first as it requires some more refactoring.

@mantoni
Copy link
Owner

mantoni commented Jul 30, 2024

Yes, I agree that it would be better to remove the limitation 👍

Just so I feel safer with the next refactoring.
We want to check what is written to stdout, not the implementation
details of which event handler writes what.
@DamienCassou DamienCassou force-pushed the refactor-forwarder-response-handling branch from 1afcd13 to 7517071 Compare July 31, 2024 19:16
@DamienCassou
Copy link
Contributor Author

I have started refactoring. Feel free to give early feedback if you want to.

@DamienCassou DamienCassou force-pushed the refactor-forwarder-response-handling branch 3 times, most recently from 7605bf5 to 660204a Compare August 1, 2024 05:20
@DamienCassou
Copy link
Contributor Author

@mantoni This PR is finally ready.

The fact that the last commit has to change all these tests is a smell in my opinion. I believe these unit tests should test more the behavior of the application and less the implementation details. This is out of scope for this PR, but I would replace code like this:

assert.calledWith(process.stdout.write, 'res');
assert.calledWith(process.stdout.write, 'ponse from ');
assert.calledWith(process.stdout.write, 'daemon');

with something like:

assertWritten(process.stdout, 'response from daemon');

assertWritten(stream, expectedMessage) would be a function that concatenates the first argument of every call to stream.write() and compare that against expectedMessage.

The previous implementation only worked for exit codes of one
character and had repeated magic numbers.
@mantoni
Copy link
Owner

mantoni commented Aug 1, 2024

Thank you for kicking this off. I merged #306 which includes your work.

@mantoni mantoni closed this Aug 1, 2024
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.

2 participants