Skip to content

Commit

Permalink
test: fix flaky test in linux CI/CD environments (#677)
Browse files Browse the repository at this point in the history
* test: update run test in order to fix flaky result in linux environment

* chore: remove unnecessary TODO reminder

* chore: add ignoringDependencyMessages as matcher utility

Also, apply same fix to workspace test

* fix: dart format in matcher utility file

---------

Co-authored-by: Jessica Tarra <[email protected]>
  • Loading branch information
jessicatarra and Jessica Tarra authored Mar 26, 2024
1 parent 2ee575e commit 28882a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/melos/test/commands/run_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ melos run hello_script

expect(
logger.output.normalizeNewLines(),
ignoringAnsii(
ignoringDependencyMessages(
'''
melos run hello_script
└> test_script
Expand Down
19 changes: 19 additions & 0 deletions packages/melos/test/matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';

/// Resolve flaky test in linux environments
Matcher ignoringDependencyMessages(String expected) {
return predicate(
(actual) {
final normalizedActual = actual
.toString()
.split('\n')
.where(
(line) =>
!line.startsWith('Resolving dependencies...') &&
!line.startsWith('Got dependencies!'),
)
.join('\n');
return ignoringAnsii(expected).matches(normalizedActual, {});
},
'ignores dependency resolution messages',
);
}

Matcher packageNamed(Object? matcher) => _PackageNameMatcher(matcher);

Matcher ignoringAnsii(Object? matcher) {
Expand Down
2 changes: 1 addition & 1 deletion packages/melos/test/workspace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ The packages that caused the problem are:
);

expect(result.exitCode, 0);
expect(result.stdout, 'a\n');
expect(result.stdout, ignoringDependencyMessages('a\n'));
});

test(
Expand Down

0 comments on commit 28882a1

Please sign in to comment.