Road to 100% Code Coverage #1632
Replies: 1 comment
-
I'd love to hear what actual limitations you are running into that would be solvable with jest? @JasonHowellSlavin had a similar question in the previous thread:
I agree with @auniverseaway point in the previous thread that this increases complexity & setup without a clear benefit. Or at least the problems jest solves are not clear to me.
As you've mentioned not being able to easily mock Awesome to see that coverage on DC though! Great job 🚀 🎉 |
Beta Was this translation helpful? Give feedback.
-
Unit testing stands as the primary line of defense against defective code. Achieving 100% code coverage is akin to setting up a robust safety net, ensuring that every line of the code is scrutinized and verified.
DC team started this journey with the Web Test Runner (WTR) framework based on Milo team’s recommendation. A standout feature of WTR is its ability to run code within an actual browser environment, providing a realistic testing ground that closely mimics real-world usage.
However, this approach is not without its limitations. One significant challenge is the difficulty in mocking certain environments and conditions within the browser. This limitation can hinder our ability to comprehensively test all lines of the code.
Further complicating matters is the emphasis on performance optimization. Our functions are meticulously crafted for peak performance, but this often comes at the expense of testability. The intricate structure that boosts efficiency can also create formidable obstacles in achieving thorough test coverage.
To navigate these challenges, a solution was proposed. Jest is the most popular framework for this purpose. Jest offers a versatile environment for JavaScript testing, allowing us to simulate browser-like conditions without the limitations we encountered with WTR.
By leveraging both WTR and Jest, we have crafted a more robust testing infrastructure. This dual approach enables us to enjoy the benefits of real browser testing while also utilizing the flexibility and control provided by Jest.
This journey is not just about reaching a numerical target; it's about fostering a culture of quality and reliability in our software development process.
Steps for setting up dual unit test frameworks
Add
jest
andjest-environment-jsdom
to your dependencies.Add Jest configuration to
package.json
. With the configuration, Jest and WTR tests co-exist in the/test
folder. Jest test files have the.jest.js
extension and WTR.test.js
.npm run
commands:wtr
andjest
. Changenpm test
to run the two commands.npm run
command.Beta Was this translation helpful? Give feedback.
All reactions