-
-
Notifications
You must be signed in to change notification settings - Fork 255
fix(sentry-dart): remove transitive dart:io reference for web #1898
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
Merged
buenaflor
merged 6 commits into
getsentry:main
from
daniel-v:fix-example-web-compilation
Mar 7, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ae5b60
fix(sentry-dart): remove transitive dart:io reference for web
daniel-v f66a7d5
docs(api): update CHANGELOG.md for unreleased fix
daniel-v 84a9d66
test(dart-sentry): add compilation tests for example_web
daniel-v b92fa1c
test(dart-sentry): fix failing tests for example_web compilation
daniel-v adc1a40
docs(api): update CHANGELOG.md
daniel-v 39598e4
chore(code-style): code formatting for #1893
daniel-v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
@TestOn('vm') | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:test/test.dart'; | ||
|
||
// Tests for the following issue | ||
// https://github.com/getsentry/sentry-dart/issues/1893 | ||
void main() { | ||
group('Compile example_web', () { | ||
test( | ||
'dart pub get and compilation should run successfully', | ||
() async { | ||
final result = await _runProcess('dart pub get', | ||
workingDirectory: _exampleWebWorkingDir); | ||
expect(result.exitCode, 0, | ||
reason: 'Could run `dart pub get` for example_web. ' | ||
'Likely caused by outdated dependencies'); | ||
// running this test locally require clean working directory | ||
final cleanResult = await _runProcess('dart run build_runner clean', | ||
workingDirectory: _exampleWebWorkingDir); | ||
expect(cleanResult.exitCode, 0); | ||
final compileResult = await _runProcess( | ||
'dart run build_runner build -r web -o build --delete-conflicting-outputs', | ||
workingDirectory: _exampleWebWorkingDir); | ||
expect(compileResult.exitCode, 0, | ||
reason: 'Could not compile example_web project'); | ||
expect( | ||
compileResult.stdout, | ||
isNot(contains( | ||
'Skipping compiling sentry_dart_web_example|web/main.dart')), | ||
reason: | ||
'Could not compile main.dart, likely because of dart:io import.'); | ||
expect( | ||
compileResult.stdout, | ||
contains( | ||
'build_web_compilers:entrypoint on web/main.dart:Compiled')); | ||
}, | ||
timeout: Timeout(const Duration(minutes: 1)), // double of detault timeout | ||
); | ||
}); | ||
} | ||
|
||
/// Runs [command] with command's stdout and stderr being forwrarded to | ||
/// test runner's respective streams. It buffers stdout and returns it. | ||
/// | ||
/// Returns [_CommandResult] with exitCode and stdout as a single sting | ||
Future<_CommandResult> _runProcess(String command, | ||
{String workingDirectory = '.'}) async { | ||
final parts = command.split(' '); | ||
assert(parts.isNotEmpty); | ||
final cmd = parts[0]; | ||
final args = parts.skip(1).toList(); | ||
final process = | ||
await Process.start(cmd, args, workingDirectory: workingDirectory); | ||
// forward standard streams | ||
unawaited(stderr.addStream(process.stderr)); | ||
final buffer = <int>[]; | ||
final stdoutCompleter = Completer.sync(); | ||
process.stdout.listen( | ||
(units) { | ||
buffer.addAll(units); | ||
stdout.add(units); | ||
}, | ||
cancelOnError: true, | ||
onDone: () { | ||
stdoutCompleter.complete(); | ||
}, | ||
); | ||
await stdoutCompleter.future; | ||
final processOut = utf8.decode(buffer); | ||
int exitCode = await process.exitCode; | ||
return _CommandResult(exitCode: exitCode, stdout: processOut); | ||
} | ||
|
||
String get _exampleWebWorkingDir { | ||
return '${Directory.current.path}${Platform.pathSeparator}example_web'; | ||
} | ||
|
||
class _CommandResult { | ||
final int exitCode; | ||
final String stdout; | ||
|
||
const _CommandResult({required this.exitCode, required this.stdout}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Picked
Process.start()
over eg.Process.runSync()
so that stdout and stderr can be forwarded while the tests are running for immediate feedback to the dev.