Skip to content

Jest config#10855

Merged
tmashuang merged 16 commits intodevelopfrom
jest-config
Apr 9, 2021
Merged

Jest config#10855
tmashuang merged 16 commits intodevelopfrom
jest-config

Conversation

@tmashuang
Copy link
Copy Markdown
Contributor

@tmashuang tmashuang commented Apr 8, 2021

Configures jest and lint rules for the /ui/app/pages/swaps/*.test.js.
Omit the swaps folder from unit tests for now.
Adds test:unit:jest script to run the jest tests isolated to the swap ui folder.
Rewrite ui/app/pages/swaps/swaps.util.test.js to jest. Replaces proxyquire with jest.mock and use nock for api mocking.

@tmashuang tmashuang requested a review from a team as a code owner April 8, 2021 20:07
@tmashuang tmashuang requested a review from Gudahtt April 8, 2021 20:07
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2021

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [ecc02f3]
Page Load Metrics (668 ± 87 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint47725974
domContentLoaded419124766718187
load420124866818187
domInteractive418124766618187

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [2eee19b]
Page Load Metrics (545 ± 51 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint44675463
domContentLoaded33665354310651
load33765554510651
domInteractive33565354310651

Copy link
Copy Markdown

@adamlaska adamlaska left a comment

Choose a reason for hiding this comment

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

Helo world

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [44b7909]
Page Load Metrics (578 ± 35 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint45785484
domContentLoaded3726495767335
load3746505787335
domInteractive3726495767335

"test:unit": "mocha --exit --require test/env.js --require test/setup.js --ignore './ui/app/pages/swaps/**/*.test.js' --recursive './{ui,app,shared}/**/*.test.js'",
"test:unit:global": "mocha --exit --require test/env.js --require test/setup.js --recursive test/unit-global/*.test.js",
"test:unit:lax": "mocha --exit --require test/env.js --require test/setup.js --ignore './app/scripts/controllers/permissions/*.test.js' --recursive './{ui,app,shared}/**/*.test.js'",
"test:unit:jest": "jest",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome!

restoreMocks: true,
setupFiles: ['./test/setup.js', './test/env.js'],
testMatch: ['**/ui/app/pages/swaps/**/?(*.)+(test).js'],
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we please add coverageThreshold for Jest? Something like we have in the Controllers repo: https://github.com/MetaMask/controllers/blob/develop/package.json#L108
We can start with whatever numbers we get now from the coverage report and slowly but surely keep increasing them with new code.

Once we have this minimum threshold set up, I can send a PR for setting up enforcement of that threshold on every Git push. It could be done e.g. via the husky node module: https://github.com/typicode/husky
image

Then whoever is contributing to the Swaps feature (and later on to any feature in this repo) will have to add enough unit tests, otherwise they won't be able to push their code.

Let me know what you think.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Setting a minimum coverage goal and ratcheting it up is a good idea - that's basically what we've done with the test:unit:strict and test:unit:lax scripts (the "strict" ones have 100% coverage).

Not sure it needs to go in at this point though? The coverage is incredibly low at the moment. Seems like it could wait for another PR.

The Husky suggestion is bound to be controversial 😅 Some people find husky very irritating. Certainly a discussion to have elsewhere. I've been considering removing the husky setup from the controllers repo and replacing it with something where the git hook is still version-controlled but is opt-in rather than automatic, so that people who prefer not using it or have their IDE running the linter/tests on each change already don't have to add --no-verify to every command.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [0b66411]
Page Load Metrics (578 ± 31 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint44725794
domContentLoaded3616305776531
load3636315786531
domInteractive3616305766531

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@tmashuang tmashuang merged commit 253efc6 into develop Apr 9, 2021
@tmashuang tmashuang deleted the jest-config branch April 9, 2021 17:20
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants