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

Add more complete unit tests #28

Merged
merged 6 commits into from
Sep 21, 2018
Merged

Conversation

erickzhao
Copy link
Collaborator

What are you trying to accomplish with this PR?

Adds more complete unit tests, including the missing logger and install files. Also fixed a bug in /lib/logger.js not accepting multiple parameters.

Jest coverage output

-------------------|----------|----------|----------|----------|-------------------|
File               |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-------------------|----------|----------|----------|----------|-------------------|
All files          |    95.51 |    93.55 |    86.67 |    95.45 |                   |
 config.js         |      100 |      100 |      100 |      100 |                   |
 install.js        |      100 |      100 |      100 |      100 |                   |
 logger.js         |      100 |      100 |      100 |      100 |                   |
 run-executable.js |     87.5 |       50 |    66.67 |     87.5 |          30,34,39 |
 themekit.js       |      100 |      100 |      100 |      100 |                   |
 utils.js          |    94.74 |       90 |      100 |    94.44 |                16 |
-------------------|----------|----------|----------|----------|-------------------|

Checklist

For contributors:

  • I have updated the documentation in the README file to reflect these changes, if applicable.

For maintainers:

  • I have 🎩'd these changes.
  • I have bumped the package.json version in a separate PR, if applicable.

Considerations:

@erickzhao erickzhao mentioned this pull request Sep 5, 2018
3 tasks
Copy link
Contributor

@t-kelly t-kelly left a comment

Choose a reason for hiding this comment

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

Nice work @erickzhao! Small stuff to look at.

// require config after setting mock platform
const config = require('../lib/config');

expect(config.binName === 'theme.exe').toBe(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, but could be:

expect(config.binName).toBe('theme.exe');

@@ -0,0 +1,18 @@
/* eslint-disable no-use-before-define */
const src = jest.fn(() => binWrapperObject);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't binWrapperObject throw a ReferenceError at this point since const variables are not hoisted and is binWrapperObject is declared below?

Or I guess it is not referenced until this callback is called... in which case binWrapperObject is declared in the parent scope? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Honestly not sure at all. I just tried stuff until it worked for this one, which was tricky since I needed the mutually recursive definitions. In any case, the mock seems to behave as expected. 🤷🏻‍♂️


test('rejects promise if error in installation run', () => {
const errorMessage = 'some err';
run.mockImplementationOnce((_, cb) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice use of mockImplementationOnce() 👍

});

test('defaults to level 2 without input parameters', () => {
const log = logger('info');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean to have logger() here? This test is identical to the one on line 52.

@erickzhao
Copy link
Collaborator Author

@t-kelly made some small fixes! :) Tests still passing.

@t-kelly t-kelly merged commit 4e53cc2 into Shopify:master Sep 21, 2018
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