Skip to content

Commit

Permalink
Merge pull request #67 from eikebartels/feat/includeIntegrationTestBi…
Browse files Browse the repository at this point in the history
…nding

feat: add option to disable ensureInitialized
  • Loading branch information
olexale authored Feb 17, 2024
2 parents 9a8fb5a + aee1618 commit a2f12d2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.6.5] - Option to disable IntegrationTestBinding inclusion

* Add includeIntegrationTestBinding option to control `IntegrationTestWidgetsFlutterBinding.ensureInitialized();` (by @eikebartels)

## [1.6.4] - Gherkin compliance

* Add hooks (by @daniel-deboeverie-lemon)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,11 @@ targets:
testMethodName: patrolTest
testerName: $
testerType: PatrolIntegrationTester
includeIntegrationTestBinding: false
```

Since Patrol version 3.0.0, `IntegrationTestWidgetsFlutterBinding.ensureInitialized` must not be called. Set `includeIntegrationTestBinding` to `false`.

## Contributing

If you find a bug or would like to request a new feature, just [open an issue](https://github.com/olexale/bdd_widget_test/issues/new). Your contributions are always welcome!
Expand Down
4 changes: 3 additions & 1 deletion example/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ targets:
builders:
bdd_widget_test|featureBuilder:
options:
includeIntegrationTestBinding: false # if false, integration test will not include binding; default is true
stepFolderName: step # this trick is required to share steps between widget and integration tests
# testMethodName: customTestMethodName
include: package:bdd_widget_test/bdd_options.yaml # you may add defaul external steps with this line
Expand All @@ -32,4 +33,5 @@ targets:
# - package:bdd_widget_test/step/i_dismiss_the_page.dart
generate_for:
- test/**
- integration_test/**
- integration_test/**

2 changes: 2 additions & 0 deletions lib/bdd_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class FeatureBuilder implements Builder {
existingSteps: getExistingStepSubfolders(featureDir, options.stepFolder),
input: contents,
generatorOptions: options,
includeIntegrationTestBinding:
generatorOptions.includeIntegrationTestBinding,
);

final featureDart = inputId.changeExtension('_test.dart');
Expand Down
4 changes: 4 additions & 0 deletions lib/src/feature_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class FeatureFile {
required this.package,
required String input,
this.isIntegrationTest = false,
this.includeIntegrationTestBinding = true,
this.existingSteps = const <String, String>{},
this.generatorOptions = const GeneratorOptions(),
}) : _lines = _prepareLines(
Expand Down Expand Up @@ -65,6 +66,8 @@ class FeatureFile {
final String featureDir;
final String package;
final bool isIntegrationTest;

final bool includeIntegrationTestBinding;
final List<BddLine> _lines;
final Map<String, String> existingSteps;
final GeneratorOptions generatorOptions;
Expand All @@ -77,6 +80,7 @@ class FeatureFile {
_testerType,
_testerName,
isIntegrationTest,
includeIntegrationTestBinding,
hookFile,
);

Expand Down
3 changes: 2 additions & 1 deletion lib/src/feature_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ String generateFeatureDart(
String testerType,
String testerName,
bool isIntegrationTest,
bool includeIntegrationTestBinding,
HookFile? hookFile,
) {
final sb = StringBuffer();
Expand Down Expand Up @@ -70,7 +71,7 @@ String generateFeatureDart(

sb.writeln();
sb.writeln('void main() {');
if (isIntegrationTest) {
if (isIntegrationTest && includeIntegrationTestBinding) {
sb.writeln(' IntegrationTestWidgetsFlutterBinding.ensureInitialized();');
sb.writeln();
}
Expand Down
22 changes: 9 additions & 13 deletions lib/src/generator_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ class GeneratorOptions {
bool? addHooks,
String? hookFolderName,
this.include,
bool? includeIntegrationTestBinding,
}) : stepFolder = stepFolderName ?? _stepFolderName,
testMethodName = testMethodName ?? _defaultTestMethodName,
testerType = testerType ?? _defaultTesterType,
testerName = testerName ?? _defaultTesterName,
addHooks = addHooks ?? false,
hookFolderName = hookFolderName ?? _hookFolderName,
externalSteps = externalSteps ?? const [];
externalSteps = externalSteps ?? const [],
includeIntegrationTestBinding = includeIntegrationTestBinding ?? true;

factory GeneratorOptions.fromMap(Map<String, dynamic> json) =>
GeneratorOptions(
Expand All @@ -38,6 +40,8 @@ class GeneratorOptions {
include: json['include'] is String
? [(json['include'] as String)]
: (json['include'] as List?)?.cast<String>(),
includeIntegrationTestBinding:
json['includeIntegrationTestBinding'] as bool?,
);

final String stepFolder;
Expand All @@ -48,6 +52,7 @@ class GeneratorOptions {
final String hookFolderName;
final List<String>? include;
final List<String> externalSteps;
final bool includeIntegrationTestBinding;
}

Future<GeneratorOptions> flattenOptions(GeneratorOptions options) async {
Expand Down Expand Up @@ -77,18 +82,7 @@ Future<GeneratorOptions> _readFromPackage(String packageUri) async {
GeneratorOptions readFromUri(Uri uri) {
final rawYaml = fs.file(uri).readAsStringSync();
final doc = loadYamlNode(rawYaml) as YamlMap;
return GeneratorOptions(
testMethodName: doc['testMethodName'] as String?,
testerType: doc['testerType'] as String?,
testerName: doc['testerName'] as String?,
externalSteps: (doc['externalSteps'] as List?)?.cast<String>(),
stepFolderName: doc['stepFolderName'] as String?,
addHooks: doc['addHooks'] as bool?,
hookFolderName: doc['hookFolderName'] as String?,
include: doc['include'] is String
? [(doc['include'] as String)]
: (doc['include'] as YamlList?)?.value.cast<String>(),
);
return GeneratorOptions.fromMap(doc.value.cast());
}

GeneratorOptions merge(GeneratorOptions a, GeneratorOptions b) =>
Expand All @@ -108,4 +102,6 @@ GeneratorOptions merge(GeneratorOptions a, GeneratorOptions b) =>
? a.hookFolderName
: b.hookFolderName,
include: b.include,
includeIntegrationTestBinding:
a.includeIntegrationTestBinding || b.includeIntegrationTestBinding,
);
32 changes: 32 additions & 0 deletions test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,36 @@ void main() {
);
expect(feature.dartContent, expectedFeatureDart);
});

test(
'integration-related lines are not added if includeIntegrationTestBinding is false',
() {
const expectedFeatureDart = '''
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: unused_import, directives_ordering
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import './step/the_app_is_running.dart';
void main() {
group(\'\'\'Testing feature\'\'\', () {
testWidgets(\'\'\'Testing scenario\'\'\', (tester) async {
await theAppIsRunning(tester);
});
});
}
''';

final feature = FeatureFile(
featureDir: 'test.feature',
package: 'test',
input: minimalFeatureFile,
isIntegrationTest: true,
includeIntegrationTestBinding: false,
);
expect(feature.dartContent, expectedFeatureDart);
});
}

0 comments on commit a2f12d2

Please sign in to comment.