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

Upgrade oclif to v3 to avoid deprecation warnings #3896

Merged
merged 8 commits into from
Sep 14, 2023
Merged

Conversation

garrettjstevens
Copy link
Collaborator

@garrettjstevens garrettjstevens commented Sep 6, 2023

This upgrades our CLI tool to the latest major release of oclif. The changes to the command files were pretty minimal, mostly that flags was renamed to Flags, args have a new format that look more like the flags format, and this.parse is now an asynchronous method.

What caused some problems is that the tests would no longer run without removing the "fileTransform.js" Jest setup step. This is used to allaw us to import png and svg files directly in our code. There was only one place in our code this was used, though, and so in this branch I've remove the "fileTransform.js" and encoded the pngs that were used as data URLs instead.

The other odd thing is that if there is an error in the tests, it won't emit a useful error message. I tracked this down to the fact that process.warn in Node (which is called in the oclif code) expects an instance of an Error or a string. But instanceof checks often don't work in Jest. Here's an interesting article explaining why: https://backend.cafe/should-you-use-jest-as-a-testing-library. The only thing I can think of to get better error messages would be to run the CLI tests in a different jest command using a different test runner.

Fixes #3869

@garrettjstevens garrettjstevens self-assigned this Sep 6, 2023
@github-actions github-actions bot added the needs label triage Needs a label to show in changelog (breaking, enhancement, bug, documentation, or internal) label Sep 6, 2023
@cmdcolin
Copy link
Collaborator

cmdcolin commented Sep 6, 2023

error in test might due to this message

"(node:2014) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit"

it is close to the admin-server test...which IIRC does start a real server. just a guess

@garrettjstevens
Copy link
Collaborator Author

I've been able to reproduce the test error where jest exits with error code 1 even after all tests pass. Here's what I've found:

  • It's a problem with the tests for all the oclif commands, not any specific one
  • All of the tests will exit with code 1 after all tests pass
  • It only happens on Node 20, not Node 18
  • It happens on tests where the command() helper is called and the command results in an error that is caught by either .catch() or .exit()
  • Using jest's fake timers doesn't seem to change anything

@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #3896 (12bf104) into main (4fc2e2c) will decrease coverage by 0.40%.
The diff coverage is 89.28%.

@@            Coverage Diff             @@
##             main    #3896      +/-   ##
==========================================
- Coverage   64.38%   63.99%   -0.40%     
==========================================
  Files        1004     1005       +1     
  Lines       29856    29827      -29     
  Branches     7151     7148       -3     
==========================================
- Hits        19224    19087     -137     
- Misses      10469    10577     +108     
  Partials      163      163              
Files Changed Coverage Δ
products/jbrowse-cli/src/base.ts 75.00% <ø> (-9.22%) ⬇️
...cts/jbrowse-web/src/components/NewSessionCards.tsx 85.71% <ø> (ø)
...roducts/jbrowse-cli/src/commands/add-track-json.ts 11.76% <50.00%> (ø)
products/jbrowse-cli/src/commands/text-index.ts 70.66% <66.66%> (-0.28%) ⬇️
products/jbrowse-cli/src/commands/add-assembly.ts 48.10% <100.00%> (-41.78%) ⬇️
...roducts/jbrowse-cli/src/commands/add-connection.ts 89.04% <100.00%> (ø)
products/jbrowse-cli/src/commands/add-track.ts 83.98% <100.00%> (ø)
products/jbrowse-cli/src/commands/admin-server.ts 95.06% <100.00%> (ø)
products/jbrowse-cli/src/commands/create.ts 88.88% <100.00%> (ø)
products/jbrowse-cli/src/commands/remove-track.ts 100.00% <100.00%> (ø)
... and 4 more

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@garrettjstevens
Copy link
Collaborator Author

I've sort of figured out what's going on with jest exiting with 1 even though all the tests pass. I've filed a bug report with jest here, since jest's behavior is different between node 18 and 20. For now, I've been able to smooth it over in node 20 by adding an afterAll to each affected test that resets the exitCode to 0.

@cmdcolin
Copy link
Collaborator

awesome, great job tracking down that process.exitCode fix

@cmdcolin cmdcolin merged commit 0128d1f into main Sep 14, 2023
@cmdcolin
Copy link
Collaborator

I say merge :) the stuff about importing raw png with file loader is interesting in its own right as well, here clearly fighting with the jest config somehow, but the data URIs are fine

@cmdcolin cmdcolin deleted the oclif_2_upgrade_gs branch September 14, 2023 14:02
@cmdcolin cmdcolin added enhancement New feature or request and removed needs label triage Needs a label to show in changelog (breaking, enhancement, bug, documentation, or internal) labels Sep 14, 2023
@cmdcolin cmdcolin changed the title Upgrade oclif Upgrade oclif to v3 to avoid deprecation warnings Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI install deprecation warnings
2 participants