Tests fail in browser environment
Description
Tests using spot fail when running them in a browser environment.
Expected behavior
If a test that does not use spot succeeds when passing the --platform chrome flag. The same test refactored to use spot should also succeed.
Actual behavior
Tests that use spot fail with the following error when running them with --platform chrome flag.
Test failed, generating timeline report
Unsupported operation: Platform._environment
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 296:3 throw_
dart-sdk/lib/_internal/js_dev_runtime/patch/io_patch.dart 279:5 _environment
dart-sdk/lib/io/platform_impl.dart 83:17 get environment
dart-sdk/lib/io/platform.dart 177:59 get environment
packages/ci/src/ci.dart.js 21:26 get isCI
packages/spot/src/widgets/wrap.g.dart.js 12107:22 reportOnError
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 <fn>
Steps to reproduce
- Clone https://github.com/peetee06/spot_browser_issue
- Run
flutter test --platform chrome
You're correct.
I just tested it. The following features do not work on web:
- timeline (can't write HTML report to disk)
- screenshots (can't write files to disk)
- font loading (can't load font)
I might find workarounds but not in the short-term.
What's your reason for executing your tests in chrome instead of the Dart VM?
Since you might have some experience with running tests in chrome: Would you rather have await loadAppFonts() crash on web or do nothing on web (with warning in the console)?
One example was that we are using flutter_pdfview to view PDFs. We ran into an issue, because that package only works on mobile platform. So we used a different code path using if (kIsWeb) to open the url via url_launcher on web instead.
Because we are already using spot everywhere else, we wanted to use it here as well, also for the nicer syntax.
We skip await loadAppFonts() in our tests, so passing with a warning would be best. 👍
Fixe in 0.18.0