Skip to content

Commit b92fa1c

Browse files
committed
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
1 parent 84a9d66 commit b92fa1c

File tree

1 file changed

+43
-31
lines changed

1 file changed

+43
-31
lines changed

dart/test/example_web_compile_test.dart

+43-31
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,36 @@ import 'package:test/test.dart';
99
// https://github.com/getsentry/sentry-dart/issues/1893
1010
void main() {
1111
group('Compile example_web', () {
12-
test('dart pub get should run successfully', () async {
13-
final result = await _runProcess('dart pub get',
14-
workingDirectory: _exampleWebWorkingDir);
15-
expect(result.exitCode, 0,
16-
reason: 'Could run `dart pub get` for example_web. '
17-
'Likely caused by outdated dependencies');
18-
});
19-
test('dart run build_runner build should run successfully', () async {
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 result = await _runProcess(
25-
'dart run build_runner build -r web -o build --delete-conflicting-outputs',
26-
workingDirectory: _exampleWebWorkingDir);
27-
expect(result.exitCode, 0,
28-
reason: 'Could not compile example_web project');
29-
expect(
30-
result.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(result.stdout,
36-
contains('build_web_compilers:entrypoint on web/main.dart:Compiled'));
37-
});
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+
);
3842
});
3943
}
4044

@@ -53,17 +57,25 @@ Future<_CommandResult> _runProcess(String command,
5357
// forward standard streams
5458
unawaited(stderr.addStream(process.stderr));
5559
final buffer = <int>[];
56-
await for (final units in process.stdout) {
57-
buffer.addAll(units);
58-
stdout.add(units);
59-
}
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;
6072
final processOut = utf8.decode(buffer);
6173
int exitCode = await process.exitCode;
6274
return _CommandResult(exitCode: exitCode, stdout: processOut);
6375
}
6476

6577
String get _exampleWebWorkingDir {
66-
return Directory.current.uri.resolve('./example_web').normalizePath().path;
78+
return '${Directory.current.path}${Platform.pathSeparator}example_web';
6779
}
6880

6981
class _CommandResult {

0 commit comments

Comments
 (0)