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

test: use assert.rejects and drop chai #194

Merged
merged 2 commits into from
Mar 31, 2021
Merged

test: use assert.rejects and drop chai #194

merged 2 commits into from
Mar 31, 2021

Conversation

JustinBeckwith
Copy link
Contributor

@JustinBeckwith JustinBeckwith commented Mar 31, 2021

Apologies for the size of the review. This PR does a few things in pursuit of test cleanup:

  • Eliminates the dependency on chai, and uses the built in assert module
  • Fixes the "this should throw" pattern to use assert.throws and assert.rejects instead of try/catch gymnastics
  • Drops vestigial tslint ignore tags
  • Deletes 2 tests which never actually worked (will explain in comments)

@JustinBeckwith JustinBeckwith requested a review from a team March 31, 2021 02:31
@JustinBeckwith JustinBeckwith requested a review from a team as a code owner March 31, 2021 02:31
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 31, 2021
});
it('Forwards GitHub error if createTree fails', async () => {
// setup
const createTreeErrorMsg = 'Error committing';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok this requires an explanation :) With try/catch test pattern here, the intent was to ensure the code throws an error, and then check the error message. That only works if you put an assert.fail after the code that you expect to throw. Turns out ... these tests never worked as intended. The handleTree method here and below never actually threw, so when I converted them to assert.rejects, the tests started failing. Since they never worked as intended, I just went ahead and removed them. We can come back around to improve coverage.

@codecov
Copy link

codecov bot commented Mar 31, 2021

Codecov Report

Merging #194 (ffc79d7) into master (a1a0a7b) will increase coverage by 0.16%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #194      +/-   ##
==========================================
+ Coverage   87.88%   88.04%   +0.16%     
==========================================
  Files          24       24              
  Lines        2303     2301       -2     
  Branches      152      168      +16     
==========================================
+ Hits         2024     2026       +2     
+ Misses        279      275       -4     
Impacted Files Coverage Δ
src/bin/code-suggester.ts 0.00% <ø> (ø)
src/bin/workflow.ts 84.37% <0.00%> (+2.08%) ⬆️

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 a1a0a7b...ffc79d7. Read the comment docs.

});
it('fails when there is no env variable', async () => {
try {
sandbox.stub(process.env, 'ACCESS_TOKEN').value(undefined);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another fun fact! This code was throwing when it tried to create the stub, because ACCESS_TOKEN didn't exist as a property. This test was bunk.

// tests
const changes = parseTextFiles(userFilesMap);
expect(changes).to.deep.equal(parsedMap);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now fully distrust the deep equal implementation in Chai. The returned object was actually a set with class instances, not naked objects.

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

I was wondering which refactor you were tweeting about 😆

@JustinBeckwith JustinBeckwith merged commit 3d4aa4b into master Mar 31, 2021
@JustinBeckwith JustinBeckwith deleted the nochai branch March 31, 2021 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants