Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Move to Jest as testing framework #1035

Merged
merged 88 commits into from
Sep 20, 2019
Merged

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Aug 31, 2019

Following lead of #755 which converts two of the tests from should.js to AVA, this initally converts the same two tests to Jest

Related issues: #661, #649, #927

(Previous PR #1005 got closed when I deleted release/3.0.0 branch.)

@shadowspawn shadowspawn changed the title WIP: Prototype Jest as testing framework WIP: Move to Jest as testing framework Sep 1, 2019
@shadowspawn
Copy link
Collaborator Author

I am happy with how this is going, and I like Jest. It is popular, comes with everything you need without extra installs or decisions, and I can find what I want in its documentation.

Pushing on with converting tests to Jest.

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Sep 1, 2019

Some notes on approach:

  • making new Command per test and not using global
  • naming tests "when do this then this happens"
  • structuring test code keeping in mind Arrange Act Assert
  • (usually) one assert per test
  • doing some refactoring (intend similar coverage, but not preserving original tests or files)

@shadowspawn
Copy link
Collaborator Author

Currently working through all the test.options files.

- _exit never returns (as before)
- callback handled explicitly in executeSubcommand
- mark _exit as private (copy and paste omission)
- support executeSubCommandAsync i default override handler to prevent call to process.exit, as expected
@shadowspawn shadowspawn requested a review from abetomo September 16, 2019 09:12
@shadowspawn
Copy link
Collaborator Author

Giant PR! But not expecting you will look at every file. :-)
Questions welcome.

program
.option('-p', 'add pepper');
program.parse(['node', 'test', '-p']);
expect(program.P).toBe(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm sorry if I sound picky.
It seems good to use toBeTruthy.
https://jestjs.io/docs/ja/expect#tobetruthy

Copy link
Collaborator Author

@shadowspawn shadowspawn Sep 18, 2019

Choose a reason for hiding this comment

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

No problem. I did consider toBeTruthy, but I decided important to test for true in at least some places. Say if we changed the implementation to return 1 or default or some other truthy value, some of the tests should fail because it would break some clients.

The README has true in an example:

$ pizza-options -d
{ debug: true, small: undefined, pizzaType: undefined }

@shadowspawn
Copy link
Collaborator Author

Are you still reviewing @abetomo? (Just checking in case comment was only question. No rush, please take your time to check what you want.)

@abetomo
Copy link
Collaborator

abetomo commented Sep 20, 2019

What do you think about checking the test code with eslint?

@shadowspawn
Copy link
Collaborator Author

In npm run lint? Good idea, yes.

@abetomo
Copy link
Collaborator

abetomo commented Sep 20, 2019

LGTM!
Thank you for a wonderful job.

When eslint is over, I will review that part again.

@shadowspawn
Copy link
Collaborator Author

Pushed, with eslint errors fixed (and the deliberately skipped tests renamed to avoid a persistent warning).

Copy link
Collaborator

@abetomo abetomo left a comment

Choose a reason for hiding this comment

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

👍

@shadowspawn shadowspawn merged commit d7f9cd4 into tj:develop Sep 20, 2019
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Sep 20, 2019
@shadowspawn
Copy link
Collaborator Author

(GitHub Action tests failed on macOS 8, but I can't reproduce locally in first try.)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
semver: major Releasing requires a major version bump, not backwards compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants