Skip to content
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

Remove whitespace replacement from Android runner #2437

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/compatibility-table.mdx

This file was deleted.

3 changes: 2 additions & 1 deletion docs/documentation/compatibility-table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ the table below to assess which version you should use.

| patrol_cli | patrol | Min Flutter Version |
| -------------- | -------------- | ------------------- |
| 3.4.0+ | 3.13.0+ | 3.24.0 |
| 3.4.1+ | 3.13.1+ | 3.24.0 |
| 3.4.0 | 3.13.0 | 3.24.0 |
| 3.3.0 | 3.12.0 | 3.24.0 |
| 3.2.1 | 3.11.2 | 3.24.0 |
| 3.2.0 | 3.11.0 - 3.11.1| 3.22.0 |
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Check out our video version of this tutorial on YouTube!
Add this line to `dependencies` section:

```groovy title="android/app/build.gradle"
androidTestUtil "androidx.test:orchestrator:1.4.2"
androidTestUtil "androidx.test:orchestrator:1.5.1"
```
</Step>
</Steps>
Expand Down
3 changes: 0 additions & 3 deletions docs/getting-started.mdx

This file was deleted.

4 changes: 4 additions & 0 deletions packages/patrol/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.13.1

- Remove whitespace replacement on Android test name. (#2437)

## 3.13.0

- Add support for the `patrol_log` package. (#2387)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class PatrolJUnitRunner extends AndroidJUnitRunner {
public PatrolAppServiceClient patrolAppServiceClient;
private Map<String, Boolean> dartTestCaseSkipMap = new HashMap<>();

private String spaceReplacement = "__";

@Override
protected boolean shouldWaitForActivitiesToComplete() {
return false;
Expand Down Expand Up @@ -117,9 +115,8 @@ public Object[] listDartTests() {
List<DartGroupEntry> dartTestCases = ContractsExtensionsKt.listTestsFlat(dartTestGroup, "");
List<String> dartTestCaseNamesList = new ArrayList<>();
for (DartGroupEntry dartTestCase : dartTestCases) {
final String testName = sanitizeTestCaseName(dartTestCase.getName());
dartTestCaseSkipMap.put(testName, dartTestCase.getSkip());
dartTestCaseNamesList.add(testName);
dartTestCaseSkipMap.put(dartTestCase.getName(), dartTestCase.getSkip());
dartTestCaseNamesList.add(dartTestCase.getName());
}
Object[] dartTestCaseNames = dartTestCaseNamesList.toArray();
Logger.INSTANCE.i(TAG + "Got Dart tests: " + Arrays.toString(dartTestCaseNames));
Expand All @@ -145,7 +142,7 @@ public RunDartTestResponse runDartTest(String name) {

try {
Logger.INSTANCE.i(TAG + "Requested execution");
RunDartTestResponse response = patrolAppServiceClient.runDartTest(originalTestCaseName(name));
RunDartTestResponse response = patrolAppServiceClient.runDartTest(name);
if (response.getResult() == Contracts.RunDartTestResponseResult.failure) {
throw new AssertionError("Dart test failed: " + name + "\n" + response.getDetails());
}
Expand All @@ -156,19 +153,4 @@ public RunDartTestResponse runDartTest(String name) {
throw new RuntimeException(e);
}
}

/**
* We need to remove whitespaces from test case name in order to make in compatible with Orchestrator 1.5.0.
* New requirement can be observed (<a href="https://github.com/android/android-test/commit/8383d784e51dd67972f79f7738e19e7e99706d23">here</a>).
* */
private String sanitizeTestCaseName(String name) {
return name.replace(" ", spaceReplacement);
}

/**
* When calling test on dart side, we need to bring back original test case name.
* */
private String originalTestCaseName(String name) {
return name.replace(spaceReplacement, " ");
}
}
2 changes: 1 addition & 1 deletion packages/patrol/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ flutter {
}

dependencies {
androidTestUtil 'androidx.test:orchestrator:1.4.2'
androidTestUtil 'androidx.test:orchestrator:1.5.1'
}
2 changes: 2 additions & 0 deletions packages/patrol/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ dev_dependencies:
leancode_lint: ^14.2.0
patrol:
path: ..
patrol_cli:
path: ../../patrol_cli

flutter_launcher_icons:
android: 'launcher_icon'
Expand Down
2 changes: 1 addition & 1 deletion packages/patrol/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: patrol
description: >
Powerful Flutter-native UI testing framework overcoming limitations of
existing Flutter testing tools. Ready for action!
version: 3.13.0
version: 3.13.1
homepage: https://patrol.leancode.co
repository: https://github.com/leancodepl/patrol/tree/master/packages/patrol
issue_tracker: https://github.com/leancodepl/patrol/issues
Expand Down
3 changes: 2 additions & 1 deletion packages/patrol_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased
## 3.4.1

- Add android product flavor to dart-define. (#2425)
- Detect and warn about Orchestrator 1.5.0. (#2437)

## 3.4.0

Expand Down
33 changes: 33 additions & 0 deletions packages/patrol_cli/lib/src/android/android_test_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AndroidTestBackend {
Future<void> build(AndroidAppOptions options) async {
await buildApkConfigOnly(options.flutter.command);
await loadJavaPathFromFlutterDoctor(options.flutter.command);
await detectOrchestratorVersion(options);

await _disposeScope.run((scope) async {
final subject = options.description;
Expand Down Expand Up @@ -179,6 +180,38 @@ class AndroidTestBackend {
);
}

/// Detects the orchestrator version and warns the user if it's 1.5.0.
/// Related to this regression: https://github.com/android/android-test/issues/2255
Future<void> detectOrchestratorVersion(
AndroidAppOptions options,
) async {
await _disposeScope.run((scope) async {
Process process;

process = await _processManager.start(
options.toGradleAppDependencies(isWindows: _platform.isWindows),
runInShell: true,
workingDirectory: _rootDirectory.childDirectory('android').path,
environment: switch (javaPath) {
final javaPath? => {'JAVA_HOME': javaPath},
_ => {},
},
)
..disposedBy(scope);
process.listenStdOut((l) {
if (l.contains('androidx.test:orchestrator:1.5.0')) {
_logger.warn(
'Orchestrator version 1.5.0 detected\n'
'Orchestrator 1.5.0 does not support whitespace in the test name.\n'
'Please update the orchestrator version to 1.5.1 or higher.\n',
);
}
}).disposedBy(scope);

await process.exitCode;
});
}

/// Executes the tests of the given [options] on the given [device].
///
/// [build] must be called before this method.
Expand Down
2 changes: 1 addition & 1 deletion packages/patrol_cli/lib/src/base/constants.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// Version of Patrol CLI. Must be kept in sync with pubspec.yaml.
/// If you update this, make sure that compatibility-table.mdx is updated (if needed)
const version = '3.4.0';
const version = '3.4.1';
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CompatibilityChecker {
process.listenStdOut(
(line) async {
if (line.startsWith('- patrol ')) {
packageCompleter.complete(line.split(' ').last);
packageCompleter.maybeComplete(line.split(' ').last);
}
},
onDone: () {
Expand Down Expand Up @@ -215,6 +215,10 @@ final _patrolVersionRange = [
),
VersionRange(
min: Version.parse('3.13.0'),
max: Version.parse('3.13.0'),
),
VersionRange(
min: Version.parse('3.13.1'),
),
];

Expand Down Expand Up @@ -265,5 +269,9 @@ final _patrolCliVersionRange = [
),
VersionRange(
min: Version.parse('3.4.0'),
max: Version.parse('3.4.0'),
),
VersionRange(
min: Version.parse('3.4.1'),
),
];
14 changes: 14 additions & 0 deletions packages/patrol_cli/lib/src/crossplatform/app_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ class AndroidAppOptions {
);
}

List<String> toGradleAppDependencies({required bool isWindows}) {
final List<String> cmd;
if (isWindows) {
cmd = <String>[r'.\gradlew.bat'];
} else {
cmd = <String>['./gradlew'];
}

// Add Gradle task
cmd.add(':app:dependencies');

return cmd;
}

String get _buildMode => flutter.buildMode.androidName;

String get _effectiveFlavor {
Expand Down
2 changes: 1 addition & 1 deletion packages/patrol_cli/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: patrol_cli
description: >
Command-line tool for Patrol, a powerful Flutter-native UI testing framework.
version: 3.4.0 # Must be kept in sync with constants.dart
version: 3.4.1 # Must be kept in sync with constants.dart
homepage: https://patrol.leancode.co
repository: https://github.com/leancodepl/patrol/tree/master/packages/patrol_cli
issue_tracker: https://github.com/leancodepl/patrol/issues?q=is%3Aopen+is%3Aissue+label%3A%22package%3A+patrol_cli%22
Expand Down
Loading