fix: flutter coverage-package unusable through melos
Is there an existing issue for this?
- [X] I have searched the existing issues.
Version
5.3.0
Description
This command for example: melos exec -- "flutter test --coverage --coverage-package=MELOS_PACKAGE_NAME(|_service)" will end with an error.
This is not due to the env variable MELOS_PACKAGE_NAME but to the regular expression itself. Tested with other expressions with the same result. I also tried to put the regular expression to an env variable.
Those examples are OK ✅: flutter test --coverage --coverage-package=package_name(|_service)✅ melos exec -- "flutter test --coverage --coverage-package=MELOS_PACKAGE_NAME" => ✅ melos exec -- "flutter test --coverage --coverage-package=package_name" => ✅
Steps to reproduce
- Execute melos exec -- "flutter test --coverage --coverage-package=MELOS_PACKAGE_NAME(|_service)"
- Acquire the error:
ERROR: ERROR: ERROR: Unhandled exception:
FormatException: Unexpected extension byte (at offset 96)
#0 _Utf8Decoder.convertChunked (dart:convert-patch/convert_patch.dart:1845:7)
#1 _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:304:28)
#2 _Utf8ConversionSink.add (dart:convert/string_conversion.dart:300:5)
#3 _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:69:18)
#4 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#8 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#9 _StreamController._add (dart:async/stream_controller.dart:658:7)
#10 _StreamController.add (dart:async/stream_controller.dart:606:5)
#11 _Socket._onData (dart:io-patch/socket_patch.dart:2447:41)
#12 _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#13 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#14 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#15 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#16 _StreamController._add (dart:async/stream_controller.dart:658:7)
#17 _StreamController.add (dart:async/stream_controller.dart:606:5)
#18 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1936:33)
#19 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1379:14)
#20 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#21 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#22 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#23 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)
Expected behavior
MELOS_PACKAGE_NAME replaced and the regular expression correctly handled to provide deep code coverage
Screenshots
No response
Additional context and comments
No response
(|_service) is some type of regex shell expansion for a specific shell right? Is it just expanding to two versions of the script, one with package_name and one with package_name_service as arguments? I don't think it would be possible for us to support this within Melos since startCommand is using /bin/sh.
You could try running it through the shell you want to use like melos exec -- "zsh -c flutter test --coverage --coverage-package=MELOS_PACKAGE_NAME(|_service)" (replace zsh with your shell).
No there's no hidden part here.
coverage-package is a parameter for flutter test command. The regular expression is simple String set in melos.yaml.
I'm on Windows host. Tested with CMD and Powershell.
I suppose the culprit is the pipe ('|') here.
Here's the help text for this parameter.
--coverage-package=<package-name-regexp>
A regular expression matching packages names to include in the coverage report (if coverage is enabled). If unset, matches the current package name.
Ah, I didn't know that was included in --coverage-package, I think you're just missing some inner quotes then, try this:
melos exec -- "flutter test --coverage --coverage-package='MELOS_PACKAGE_NAME(|_service)'"
Nope same result.
Interesting, I did not get that same result on Linux. Can you try escaping the problematic characters then? Probably both that parenthesis and the pipe.
Escaping does not help.
I transformed the sample expression to this one MELOS_PACKAGE_NAME(_service)?
So, by removing the pipe, the process runs as expected.