-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Create test to browser compatibility
#284
Comments
browser compatibility
tests for fuels
SDKbrowser compatibility
This would catch bugs and implementation details like these: |
Current work in progress report on browser compatibility testing: So far I’ve tried a number of different approaches and tackled a few different challenges that can be summarised into the following categories, that gets us closer to cross environment (and potentially cross framework testing) within the TS SDK. Test Grouping The agreed upon approach is inspired by jest-runner-groups where we append test cases with a comment block that outlines the testing groups it is part of: /**
* @group node
* @group browser
*/
describe("Testcase", () => {
... Pretty much all testing frameworks that have been used allow some kind of regex matching, that allow us to pass in test files. @arboleya wrote a nice shell script that parses for test files for such group tags and returns file names, that can be used across frameworks. We should keep away from custom test runners where possible to avoid compatibility issues between frameworks. Appending environments to test file names ( Coverage merging As we will now be running multiple test suites, we need to be able to merge test coverage to report confidently on the coverage across the repository. Most frameworks support Istanbul for coverage, and therefore a tool called NYC can be used to merge and report on coverage. @Dhaiwat10 implemented this in the initial implementation also with success. We should hand off all coverage collection and reporting to Istanbul and thus NYC. Jest has it’s own Json format that made merging incompatible with NYC, I foresee this issue with other frameworks. Therefore NYC provides a succinct way across frameworks (so long as the framework supports NYC, I’m yet to test one that doesn’t. The only caveat here is coverage reporting in our workflow actions. I recommend also utilising one that supports a test format such as LCOV rather than a framework (i.e. Jest) to ensure cross framework compatibility. Also would recommend avoiding JSON for cross framework reporting, due to differences in the schema across frameworks. Testing frameworks and tools So far I have tried a range of frameworks/tools to meet the following criteria:
The following frameworks/tools have been tried and I’ll summarise the outcomes: Jest (standalone)
Jest (with Playwright)
Jest (with Puppeteer)
Jest (with Electon)
Yet to try
Won’t try
Conclusions (so far) So far I have been prioritising augmentations of our current Jest infrastructure, as it is a well supported tool so framework adapters are pretty common, and to introduce minimal interruption to our current setup. However I am coming to believe that our new requirements may not be best fit for Jest. Hence I am going to continue investigating a complete change of test infrastructure (with benchmarks). Successful grouping, merging and workflow reporting for the new requirements has been implemented in #1182 however the implemented tools and frameworks are subject to change |
Thanks for getting to the bottom of this. Jest doesn't offer a browser-runner, and each workaround opens up a can of worms. I ran some experiments in my free time, and Vitest seems like the best solution to fulfill our needs. Things like Mocha/Jasmine also offer browser-runners, but the required tooling around them is exhaustive. I've been using these in conjunction with Instabul middlewares for a long time, and they haven't evolved much in 10 years. @danielbate Let's talk and see where it leads us. |
Pausing the Vitest investigations for now. Currently impressions are that it is very fast (will benchmark once the full suite runs) and requires minimal configuration compared to Jest, but there appears to be a couple blockers with itself and our current setup. However positive as it seems to giving the highest level of confidence regarding browser compatibility testing.
|
After upgrading a few packages to better integrate with Vitest, still experiencing some issues.
Currently it seems evident that |
@danielbate Thank you for the updates. I appreciate all the work you've put into this endeavor already. Considering everything you already did, saw, and thought about — where should we go from here? |
Sorry yes I was referring more towards domains. But correct, right now most of fuel-gauge uses |
What do you mean by domains, and how would you make most of the tests work? Maybe I'm missing the point or unable to clarify myself, but I can't see how The only way to ship these files to the browser is if we generate types for everything using Typegen. The JSON and hexlified bytecode would be included in the generated Typescript classes, making it possible to run them inside the browser. This, however, would require a complete revamp of all tests, which concerns me. |
Apologies, I am not explaining myself well. Regarding domains I was referring to domains within our SDK, so whether we want to browser test Regarding I am still investigating the fs build time polyfill but may need changes to those functions, rather than all the tests. |
Awesome! Thanks for clarifying. 🎯 |
This might be a worthwhile endeavor just because we'd be eating our own dog food.
If this doesn't pan out as expected, another approach could be to spin up a server that'd serve the necessary files and have |
Something else to have in mind: |
As discussed above we currently have the following caveats. For both environments, mocking functionality from the same file as the functionality under test will not work as expected. This is a caveat to mocking with Vitest. Additionally, currently module mocking is not supported in a browser environment. Mocked functions ( |
@danielbate Any clue as to how it works locally? |
My bad. I initially ran the wrong test file. Now I'm getting the same error. |
Fuels-ts
would probably be used on many WebApps and this requires adding tests to run jest on a browser environment.See also:
versions
package doesn't use native moduels #651The text was updated successfully, but these errors were encountered: