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

Fixed bundle-phobia-install not working #40

Merged
merged 7 commits into from
Dec 8, 2020
Merged

Fixed bundle-phobia-install not working #40

merged 7 commits into from
Dec 8, 2020

Conversation

soimon
Copy link
Contributor

@soimon soimon commented Dec 7, 2020

The bundle-phobia-install command didn't work for me, regardless of #37.
Every attempt failed with the error npm install returned with status code undefined
To fix it, I encapsulated the actual execFile within const performInstall with a Promise.

Reasons to believe that should be the case:

  1. Every invocation of the function is awaited
  2. The same function in npm-utils.js returns a Promise
  3. execFile is asynchronous, so acting on the direct result instead of in a callback does not guarantee the process has been finished
  4. The current error check relies on res.code where res is the result of execFile. The resulting ChildProcess does in fact not contain a property called code (hence the "status code undefined")

The reason this has not been identified in integration tests is that the test in question mocks the execFile (incorrectly: it contains a property code which the documented ChildProcess doesn't), so it never has to deal with a process error. I would propose a fix for this as well, but I do not feel confident enough in your testing stack so I'll leave that decision to the author 🤕🤷‍♂️

(If all is well you should be able to commit to my branch)

@codecov
Copy link

codecov bot commented Dec 7, 2020

Codecov Report

Merging #40 (6c0286c) into master (f37949a) will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #40   +/-   ##
=======================================
  Coverage   33.78%   33.78%           
=======================================
  Files           8        8           
  Lines         293      293           
=======================================
  Hits           99       99           
  Misses        194      194           
Impacted Files Coverage Δ
src/install.js 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f37949a...6c0286c. Read the comment docs.

@soimon
Copy link
Contributor Author

soimon commented Dec 7, 2020

I actually updated fakeExecFile to behave in line with the documentation. I also added a stdout and stderror parameter to the factory method to pave the way for mocking the npm service (that way you could actually test the error response, for example in npm-utils.js in the getVersionList function).

The branch as proposed functions properly (at least on my machine). Because I don't use the feature myself this will probably be my last commit on the branch, I hope it's of some use 😄

@AdrieanKhisbe AdrieanKhisbe added the Bug 🐛 Ooops, something is not working as it should label Dec 7, 2020
@AdrieanKhisbe AdrieanKhisbe self-requested a review December 7, 2020 09:52
@AdrieanKhisbe AdrieanKhisbe self-assigned this Dec 7, 2020
@AdrieanKhisbe
Copy link
Owner

Thanks a lot for the detailed update @soimon, will try to review it quickly.

(seems like I might have overlooked too much things in #33, and forgot that I was mocking too much stuff. 🤦)

note to self 🔖: Might be interesting at some point to add real end-to-end test with no code mocking

Copy link
Owner

@AdrieanKhisbe AdrieanKhisbe left a comment

Choose a reason for hiding this comment

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

note to self 🔖: Might be interesting at some point to add real end-to-end test with no code mocking

in fact it might be the time, would be more confident with e2e test with no code mocking
Will try on a subbranch

test/integration/utils.js Outdated Show resolved Hide resolved
src/install.js Outdated Show resolved Hide resolved
@soimon
Copy link
Contributor Author

soimon commented Dec 7, 2020

New proposal: if you define the purpose of this command as "conditionally run npm install", then it would make sense to just spawn npm install if it passes the size requirement and pipe the output of that command to the user. The npm log has plenty of (valuable) information about the process, success or failure so there should be no need to provide your own custom error handling and messaging. Like this the command becomes a seamless drop-in for npm install.

The commit is a bit large because of renaming all execFile to spawn in the integration tests for the sake of consistency. Functionally these changes do not have any effect so you can just merge install.js if you wish to rework the integration tests anyway. 💪

@AdrieanKhisbe AdrieanKhisbe added the Enhancement 🍭 Something existing, but better ;) label Dec 7, 2020
@AdrieanKhisbe
Copy link
Owner

@soimon That's a very good idea indeed, and a clear improvement!

On my side I worked on the install safety net (cf install-fix-and-e2e), and adapted it to your latest changes, it's green as you can see

(I'll open a dedicated PR for extra e2e once this one lands.)

@AdrieanKhisbe AdrieanKhisbe merged commit 435571c into AdrieanKhisbe:master Dec 8, 2020
@AdrieanKhisbe
Copy link
Owner

Thanks a lot @soimon for this great contributions.

I just squashed it, and open a PR with rebased tests I was pointing.
Will publish a patch once I'll have merged the #41 and updated the changelog accordingly.

@soimon
Copy link
Contributor Author

soimon commented Dec 8, 2020

Great! No problem, nice to finally get the gist of GitHub 😉
I look forwards to the changes and thanks for the great package.

@AdrieanKhisbe
Copy link
Owner

and here it is @soimon 😉
bundle-phobia-cli@0.14.12 is out. 🚀

🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Ooops, something is not working as it should Enhancement 🍭 Something existing, but better ;)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants