Skip to content

Commit bffc2c5

Browse files
authored
fix(sentry-dart): remove transitive dart:io reference for web (#1898)
* fix(sentry-dart): remove transitive dart:io reference for web TransportUtils imported sentry_io.dart which prevented web projects such as example_web from building when build_runner was used. Resolves #1893 * docs(api): update CHANGELOG.md for unreleased fix CHANGELOG.md now includes information about unreleased fix for issue #1893. * test(dart-sentry): add compilation tests for example_web Added tests to check if example_web project can be compiled with build_runner. Resolves #1893 * test(dart-sentry): fix failing tests for example_web compilation Test ordering should not have impact on example_web_comopile_test and path handling across platforms was simplified. Resolves #1893 * docs(api): update CHANGELOG.md Place entry for #1893 under unreleased fix in CHANGELOG #1893 * chore(code-style): code formatting for #1893
1 parent cd50afa commit bffc2c5

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Fix transaction end timestamp trimming ([#1916](https://github.com/getsentry/sentry-dart/pull/1916))
88
- Transaction end timestamps are now correctly trimmed to the latest child span end timestamp
9+
- remove transitive dart:io reference for web ([#1898](https://github.com/getsentry/sentry-dart/pull/1898))
910

1011
### Features
1112

dart/lib/src/utils/transport_utils.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:http/http.dart';
22

3-
import '../../sentry_io.dart';
43
import '../client_reports/discard_reason.dart';
4+
import '../protocol.dart';
5+
import '../sentry_envelope.dart';
6+
import '../sentry_options.dart';
57
import '../transport/data_category.dart';
68

79
class TransportUtils {
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
@TestOn('vm')
2+
import 'dart:async';
3+
import 'dart:convert';
4+
import 'dart:io';
5+
6+
import 'package:test/test.dart';
7+
8+
// Tests for the following issue
9+
// https://github.com/getsentry/sentry-dart/issues/1893
10+
void main() {
11+
group('Compile example_web', () {
12+
test(
13+
'dart pub get and compilation should run successfully',
14+
() async {
15+
final result = await _runProcess('dart pub get',
16+
workingDirectory: _exampleWebWorkingDir);
17+
expect(result.exitCode, 0,
18+
reason: 'Could run `dart pub get` for example_web. '
19+
'Likely caused by outdated dependencies');
20+
// running this test locally require clean working directory
21+
final cleanResult = await _runProcess('dart run build_runner clean',
22+
workingDirectory: _exampleWebWorkingDir);
23+
expect(cleanResult.exitCode, 0);
24+
final compileResult = await _runProcess(
25+
'dart run build_runner build -r web -o build --delete-conflicting-outputs',
26+
workingDirectory: _exampleWebWorkingDir);
27+
expect(compileResult.exitCode, 0,
28+
reason: 'Could not compile example_web project');
29+
expect(
30+
compileResult.stdout,
31+
isNot(contains(
32+
'Skipping compiling sentry_dart_web_example|web/main.dart')),
33+
reason:
34+
'Could not compile main.dart, likely because of dart:io import.');
35+
expect(
36+
compileResult.stdout,
37+
contains(
38+
'build_web_compilers:entrypoint on web/main.dart:Compiled'));
39+
},
40+
timeout: Timeout(const Duration(minutes: 1)), // double of detault timeout
41+
);
42+
});
43+
}
44+
45+
/// Runs [command] with command's stdout and stderr being forwrarded to
46+
/// test runner's respective streams. It buffers stdout and returns it.
47+
///
48+
/// Returns [_CommandResult] with exitCode and stdout as a single sting
49+
Future<_CommandResult> _runProcess(String command,
50+
{String workingDirectory = '.'}) async {
51+
final parts = command.split(' ');
52+
assert(parts.isNotEmpty);
53+
final cmd = parts[0];
54+
final args = parts.skip(1).toList();
55+
final process =
56+
await Process.start(cmd, args, workingDirectory: workingDirectory);
57+
// forward standard streams
58+
unawaited(stderr.addStream(process.stderr));
59+
final buffer = <int>[];
60+
final stdoutCompleter = Completer.sync();
61+
process.stdout.listen(
62+
(units) {
63+
buffer.addAll(units);
64+
stdout.add(units);
65+
},
66+
cancelOnError: true,
67+
onDone: () {
68+
stdoutCompleter.complete();
69+
},
70+
);
71+
await stdoutCompleter.future;
72+
final processOut = utf8.decode(buffer);
73+
int exitCode = await process.exitCode;
74+
return _CommandResult(exitCode: exitCode, stdout: processOut);
75+
}
76+
77+
String get _exampleWebWorkingDir {
78+
return '${Directory.current.path}${Platform.pathSeparator}example_web';
79+
}
80+
81+
class _CommandResult {
82+
final int exitCode;
83+
final String stdout;
84+
85+
const _CommandResult({required this.exitCode, required this.stdout});
86+
}

0 commit comments

Comments
 (0)