Skip to content

Commit

Permalink
Add tags support
Browse files Browse the repository at this point in the history
  • Loading branch information
pdenert committed Aug 1, 2024
1 parent 4f67159 commit 5fe120a
Show file tree
Hide file tree
Showing 23 changed files with 114 additions and 25 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,
);
}
23 changes: 23 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,27 @@ void main() {
expect($('Hello, Flutter!'), findsOneWidget);
},
);

patrol(
'counter state is the same after going to Home and switching apps with tag',
tags: ['smoke'],
($) async {
await createApp($);

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

await $(#textField).enterText('Hello, Flutter!');
expect($('Hello, Flutter!'), findsOneWidget);

await $.native.pressHome();
await $.native.openApp();

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

expect($(#counterText).text, '2');
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

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 @@ -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
25 changes: 17 additions & 8 deletions packages/patrol/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ DartGroupEntry createDartTestGroup(
String name = '',
int level = 0,
int maxTestCaseLength = global_state.maxTestLength,
List<String> tags = const [],
}) {
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 +205,28 @@ DartGroupEntry createDartTestGroup(
throw StateError('Test is not allowed to be defined at level $level');
}

groupDTO.entries.add(
DartGroupEntry(
name: name,
type: GroupEntryType.test,
entries: [],
skip: entry.metadata.skip,
),
);
final addTest = tags.isEmpty || tags.any(entry.metadata.tags.contains);

if (addTest) {
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,
),
);
}
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.

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.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 Down
33 changes: 28 additions & 5 deletions packages/patrol/test/internals_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ void main() {
name: '',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
DartGroupEntry(
name: 'example_test',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
DartGroupEntry(
name: 'alpha',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
_testEntry('first'),
_testEntry('second'),
Expand All @@ -82,6 +85,7 @@ void main() {
name: 'bravo',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
_testEntry('first'),
_testEntry('second'),
Expand All @@ -93,6 +97,7 @@ void main() {
name: 'open_app_test',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
_testEntry('open maps'),
_testEntry('open browser'),
Expand Down Expand Up @@ -137,17 +142,20 @@ void main() {
name: '',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
DartGroupEntry(
name: 'example_test',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
_testEntry('alpha'),
DartGroupEntry(
name: 'bravo',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
_testEntry('first'),
_testEntry('second'),
Expand All @@ -158,6 +166,7 @@ void main() {
name: 'delta',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
_testEntry('first'),
_testEntry('second'),
Expand Down Expand Up @@ -199,11 +208,13 @@ void main() {
name: '',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
DartGroupEntry(
name: 'example_test',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
_testEntry('alpha'),
_testEntry('zielony'),
Expand Down Expand Up @@ -234,7 +245,7 @@ void main() {
});

group('skip group of tests', () {
test('skip test', () {
test('skip test param should be passed in DartGroupEntry', () {
// given
final topLevelGroup = Group.root([
LocalTest('patrol_test_explorer', Metadata.empty, () {}),
Expand Down Expand Up @@ -267,41 +278,53 @@ void main() {
DartGroupEntry(
name: '',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
DartGroupEntry(
name: 'example_test',
type: GroupEntryType.group,
skip: true,
tags: [],
entries: [
_testEntry('alpha'),
],
skip: true,
),
DartGroupEntry(
name: 'example2_test',
type: GroupEntryType.group,
skip: false,
tags: [],
entries: [
_testEntry('alpha'),
_testEntry('bravo first'),
_testEntry('bravo second'),
],
skip: false,
),
],
skip: false,
),
),
);
});
});

// group('test with tags', () {
// final topLevelGroup
// })
}

LocalTest _localTest(String name) => LocalTest(name, Metadata.empty, () {});

DartGroupEntry _testEntry(String name, {bool skip = false}) {
DartGroupEntry _testEntry(
String name, {
bool skip = false,
List<String> tags = const [],
}) {
return DartGroupEntry(
name: name,
type: GroupEntryType.test,
entries: [],
skip: skip,
tags: tags,
);
}
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.0.1';
const version = '3.0.2';
4 changes: 3 additions & 1 deletion packages/patrol_cli/lib/src/commands/build_android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class BuildAndroidCommand extends PatrolCommand {
usesLabelOption();
usesWaitOption();
usesPortOptions();
usesTagsOption();

usesAndroidOptions();
}
Expand Down Expand Up @@ -83,9 +84,10 @@ class BuildAndroidCommand extends PatrolCommand {
_logger.detail('Received test target: $t');
}

final tags = stringsArg('tags');
final entrypoint = _testBundler.bundledTestFile;
if (boolArg('generate-bundle')) {
_testBundler.createTestBundle(targets);
_testBundler.createTestBundle(targets, tags);
}

final flavor = stringArg('flavor') ?? config.android.flavor;
Expand Down
4 changes: 3 additions & 1 deletion packages/patrol_cli/lib/src/commands/build_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class BuildIOSCommand extends PatrolCommand {
usesLabelOption();
usesWaitOption();
usesPortOptions();
usesTagsOption();

usesIOSOptions();
argParser.addFlag(
Expand Down Expand Up @@ -87,9 +88,10 @@ class BuildIOSCommand extends PatrolCommand {
_logger.detail('Received test target: $t');
}

final tags = stringsArg('tags');
final entrypoint = _testBundler.bundledTestFile;
if (boolArg('generate-bundle')) {
_testBundler.createTestBundle(targets);
_testBundler.createTestBundle(targets, tags);
}

final flavor = stringArg('flavor') ?? config.ios.flavor;
Expand Down
4 changes: 3 additions & 1 deletion packages/patrol_cli/lib/src/commands/build_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class BuildMacOSCommand extends PatrolCommand {
usesLabelOption();
usesWaitOption();
usesPortOptions();
usesTagsOption();

usesMacOSOptions();
}
Expand Down Expand Up @@ -83,9 +84,10 @@ class BuildMacOSCommand extends PatrolCommand {
_logger.detail('Received test target: $t');
}

final tags = stringsArg('tags');
final entrypoint = _testBundler.bundledTestFile;
if (boolArg('generate-bundle')) {
_testBundler.createTestBundle(targets);
_testBundler.createTestBundle(targets, tags);
}

final flavor = stringArg('flavor') ?? config.ios.flavor;
Expand Down
1 change: 1 addition & 0 deletions packages/patrol_cli/lib/src/commands/develop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class DevelopCommand extends PatrolCommand {
usesLabelOption();
usesWaitOption();
usesPortOptions();
usesTagsOption();

usesUninstallOption();

Expand Down
Loading

0 comments on commit 5fe120a

Please sign in to comment.