Skip to content

Commit

Permalink
Merge pull request #2286 from leancodepl/add-tags-from-skip-branch
Browse files Browse the repository at this point in the history
Add tags and exclude-tags support
  • Loading branch information
pdenert authored Aug 5, 2024
2 parents 7c2c165 + ba8bcf9 commit 4727aad
Show file tree
Hide file tree
Showing 27 changed files with 410 additions and 20 deletions.
2 changes: 2 additions & 0 deletions dev/e2e_app/integration_test/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void patrol(
String description,
Future<void> Function(PatrolIntegrationTester) callback, {
bool? skip,
List<String> tags = const [],
NativeAutomatorConfig? nativeAutomatorConfig,
LiveTestWidgetsFlutterBindingFramePolicy framePolicy =
LiveTestWidgetsFlutterBindingFramePolicy.fadePointers,
Expand All @@ -30,5 +31,6 @@ void patrol(
framePolicy: framePolicy,
skip: skip,
callback,
tags: tags,
);
}
27 changes: 27 additions & 0 deletions dev/e2e_app/integration_test/example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,31 @@ void main() {
expect($('Hello, Flutter!'), findsOneWidget);
},
);

patrol(
'short test with two tags',
tags: ['smoke', 'fume'],
($) async {
await createApp($);

await $(FloatingActionButton).tap();
expect($(#counterText).text, '1');
await $(FloatingActionButton).tap();
expect($(#counterText).text, '2');
},
);

patrol(
'short test with tag',
tags: ['smoke'],
($) async {
await createApp($);

await $(FloatingActionButton).tap();
expect($(#counterText).text, '1');

await $(#textField).enterText('Hello, Flutter!');
expect($('Hello, Flutter!'), findsOneWidget);
},
);
}
2 changes: 1 addition & 1 deletion dev/e2e_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ packages:
path: "../../packages/patrol"
relative: true
source: path
version: "3.9.0"
version: "3.10.0"
patrol_finders:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion docs/compatibility-table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ the table below to assess which version you should use.

| patrol | patrol_cli |
| -------------- | -------------- |
| 3.6.0 - | 2.6.5 - |
| 3.10.0 - | 3.1.0 - |
| 3.6.0 - | 2.6.5 - 3.0.1 |
| 3.4.0 - 3.5.2 | 2.6.0 - 2.6.4 |
| 3.0.0 - 3.3.0 | 2.3.0 - 2.5.0 |
| 2.3.0 - 2.3.2 | 2.2.0 - 2.2.2 |
Expand Down
3 changes: 2 additions & 1 deletion packages/patrol/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
## Unreleased
## 3.10.0

- Implement `enableBluetooth` and `disableBluetooth` methods for Android > 11. (#2254)
- Implement `enableAirplaneMode` and `disableAirplaneMode` methods for Android. (#2254)
- Implement `enableLocation` and `disableLocation` methods for Android. (#2259)
- Fix opening settings app with clean state on iOS. (#2275)
- Add native skip. (#2278)
- Add `tags` and `exclude-tags`. (#2286)

## 3.9.0

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ fun dartTestGroup(
name: String,
entries: List<DartGroupEntry>,
): DartGroupEntry {
return DartGroupEntry(name, GroupEntryType.group, entries, false)
return DartGroupEntry(name, GroupEntryType.group, entries, false, listOf<String>())
}

fun dartTestCase(name: String): DartGroupEntry {
return DartGroupEntry(name, GroupEntryType.test, listOf(), false)
return DartGroupEntry(name, GroupEntryType.test, listOf(), false, listOf<String>())
}

class DartTestGroupExtensionsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public struct DartGroupEntry: Codable {
public var type: GroupEntryType
public var entries: [DartGroupEntry]
public var skip: Bool
public var tags: [String]
}

public struct ListDartTestsResponse: Codable {
Expand Down
26 changes: 26 additions & 0 deletions packages/patrol/lib/src/common.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io' as io;

import 'package:boolean_selector/boolean_selector.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -169,12 +170,15 @@ DartGroupEntry createDartTestGroup(
String name = '',
int level = 0,
int maxTestCaseLength = global_state.maxTestLength,
String? tags,
String? excludeTags,
}) {
final groupDTO = DartGroupEntry(
name: name,
type: GroupEntryType.group,
entries: [],
skip: parentGroup.metadata.skip,
tags: parentGroup.metadata.tags.toList(),
);

for (final entry in parentGroup.entries) {
Expand Down Expand Up @@ -203,21 +207,43 @@ DartGroupEntry createDartTestGroup(
throw StateError('Test is not allowed to be defined at level $level');
}

if (tags != null) {
final includeTagsSelector = BooleanSelector.parse(tags);

// If the user provided tags, skip tests that don't match all of them.
if (!includeTagsSelector.evaluate(entry.metadata.tags.contains)) {
continue;
}
}

if (excludeTags != null) {
final excludeTagsSelector = BooleanSelector.parse(excludeTags);

// Skip tests that do match any tags the user wants to exclude.
if (excludeTagsSelector.evaluate(entry.metadata.tags.contains)) {
continue;
}
}

groupDTO.entries.add(
DartGroupEntry(
name: name,
type: GroupEntryType.test,
entries: [],
skip: entry.metadata.skip,
tags: entry.metadata.tags.toList(),
),
);

case Group _:
groupDTO.entries.add(
createDartTestGroup(
entry,
name: name,
level: level + 1,
maxTestCaseLength: maxTestCaseLength,
tags: tags,
excludeTags: excludeTags,
),
);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/patrol/lib/src/native/contracts/contracts.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/patrol/lib/src/native/contracts/contracts.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 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.9.0
version: 3.10.0
homepage: https://patrol.leancode.co
repository: https://github.com/leancodepl/patrol/tree/master/packages/patrol
issue_tracker: https://github.com/leancodepl/patrol/issues
Expand All @@ -17,6 +17,7 @@ environment:
flutter: '>=3.22.0'

dependencies:
boolean_selector: ^2.1.1
equatable: ^2.0.5
flutter:
sdk: flutter
Expand Down
Loading

0 comments on commit 4727aad

Please sign in to comment.