Skip to content

Commit

Permalink
test(dart-sentry): fix failing tests for example_web compilation
Browse files Browse the repository at this point in the history
Test ordering should not have impact on example_web_comopile_test
and path handling across platforms was simplified.

Resolves #1893
  • Loading branch information
daniel-v committed Mar 6, 2024
1 parent 84a9d66 commit b92fa1c
Showing 1 changed file with 43 additions and 31 deletions.
74 changes: 43 additions & 31 deletions dart/test/example_web_compile_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,36 @@ import 'package:test/test.dart';
// https://github.com/getsentry/sentry-dart/issues/1893
void main() {
group('Compile example_web', () {
test('dart pub get 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');
});
test('dart run build_runner build should run successfully', () async {
// running this test locally require clean working directory
final cleanResult = await _runProcess('dart run build_runner clean',
workingDirectory: _exampleWebWorkingDir);
expect(cleanResult.exitCode, 0);
final result = await _runProcess(
'dart run build_runner build -r web -o build --delete-conflicting-outputs',
workingDirectory: _exampleWebWorkingDir);
expect(result.exitCode, 0,
reason: 'Could not compile example_web project');
expect(
result.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(result.stdout,
contains('build_web_compilers:entrypoint on web/main.dart:Compiled'));
});
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
);
});
}

Expand All @@ -53,17 +57,25 @@ Future<_CommandResult> _runProcess(String command,
// forward standard streams
unawaited(stderr.addStream(process.stderr));
final buffer = <int>[];
await for (final units in process.stdout) {
buffer.addAll(units);
stdout.add(units);
}
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.uri.resolve('./example_web').normalizePath().path;
return '${Directory.current.path}${Platform.pathSeparator}example_web';
}

class _CommandResult {
Expand Down

0 comments on commit b92fa1c

Please sign in to comment.