feat(dependencies): added in calls to reporters and hooks

This commit is contained in:
Jon Samwell 2021-01-08 12:32:42 +11:00
parent 9ba3ced69a
commit 7dc4408f62
15 changed files with 167 additions and 36 deletions

View File

@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"integration_test","path":"C:\\\\Google\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\integration_test-1.0.1\\\\","dependencies":[]}],"android":[{"name":"integration_test","path":"C:\\\\Google\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\integration_test-1.0.1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"integration_test","dependencies":[]}],"date_created":"2021-01-07 17:35:05.210344","version":"1.22.5"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"integration_test","path":"C:\\\\Google\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\integration_test-1.0.1\\\\","dependencies":[]}],"android":[{"name":"integration_test","path":"C:\\\\Google\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\integration_test-1.0.1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"integration_test","dependencies":[]}],"date_created":"2021-01-08 11:27:21.268830","version":"1.22.5"}

View File

@ -2,6 +2,7 @@
"cSpell.words": [
"Errored",
"Serializable",
"multiline",
"scrollable",
"writeln"
]

View File

@ -0,0 +1,3 @@
{
"gherkin_results": "{\"test\":\"moo\"}"
}

View File

@ -8,7 +8,7 @@ part of 'gherkin_suite_test.dart';
class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner {
_CustomGherkinIntegrationTestRunner(
FlutterTestConfiguration configuration,
TestConfiguration configuration,
void Function() appMainFunction,
) : super(configuration, appMainFunction);
@ -35,22 +35,24 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner {
'Given I expect the "counter" to be "0"',
[],
null,
dependencies.world,
dependencies,
);
await runStep(
'When I tap the "increment" button',
[],
null,
dependencies.world,
dependencies,
);
await runStep(
'Then I expect the "counter" to be "1"',
[],
null,
dependencies.world,
dependencies,
);
cleanupScenarioRun(dependencies);
},
timeout: scenarioExecutionTimeout,
);

View File

@ -234,9 +234,11 @@ packages:
gherkin:
dependency: transitive
description:
path: "../../dart_gherkin"
relative: true
source: path
path: "."
ref: "59b9db42e917927ccb8d1265e6cb8fe93ddbb73a"
resolved-ref: "59b9db42e917927ccb8d1265e6cb8fe93ddbb73a"
url: "https://github.com/jonsamwell/dart_gherkin.git"
source: git
version: "1.1.10"
glob:
dependency: transitive

View File

@ -1,3 +1,23 @@
import 'package:integration_test/integration_test_driver.dart';
import 'package:integration_test/integration_test_driver.dart' as integration_test_driver;
Future<void> main() => integrationDriver(timeout: const Duration(minutes: 90));
Future<void> main() {
const maximumTestRunDuration = Duration(minutes: 90);
// Tests will write any output files to this directory
integration_test_driver.testOutputsDirectory = './';
return integration_test_driver.integrationDriver(timeout: maximumTestRunDuration);
}
// import 'package:flutter_driver/flutter_driver.dart';
// import 'package:integration_test/integration_test_driver_extended.dart';
// Future<void> main() async {
// final driver = await FlutterDriver.connect();
// await integrationDriver(
// driver: driver,
// onScreenshot: (String screenshotName, List<int> screenshotBytes) async {
// return true;
// },
// );
// }

View File

@ -18,9 +18,12 @@ abstract class AppDriverAdapter<TRawAdapter, TFinderType, TWidgetBaseType> {
_driver = driver;
}
/// Returns the correct finder type instance
/// `data` can be `String`, `Key` or a `Type`
/// `findType` denotes the type of finder returned
TFinderType findBy(
String text,
FindType type,
dynamic data,
FindType findType,
);
TFinderType findByAncestor(

View File

@ -148,16 +148,19 @@ class FlutterDriverAppDriverAdapter
}
@override
SerializableFinder findBy(String data, FindType type) {
SerializableFinder findBy(
dynamic data,
FindType type,
) {
switch (type) {
case FindType.key:
return find.byValueKey(data);
return find.byValueKey(data.toString());
case FindType.text:
return find.text(data);
case FindType.tooltip:
return find.byTooltip(data);
case FindType.type:
return find.byType(data);
return find.byType(data is Type ? data.runtimeType.toString() : data);
}
throw Exception('unknown finder');

View File

@ -162,16 +162,19 @@ class WidgetTesterAppDriverAdapter
}
@override
Finder findBy(String data, FindType type) {
Finder findBy(
dynamic data,
FindType type,
) {
switch (type) {
case FindType.key:
return find.byKey(ValueKey(data));
return find.byKey(data is Key ? data : Key(data));
case FindType.text:
return find.text(data);
case FindType.tooltip:
return find.byTooltip(data);
case FindType.type:
// return find.byType(data);
return find.byType(data);
}
throw Exception('unknown finder');

View File

@ -141,6 +141,8 @@ class FeatureFileTestGeneratorVisitor extends FeatureFileVisitor {
await startApp(tester);
{{steps}}
cleanupScenarioRun(dependencies);
},
timeout: scenarioExecutionTimeout,
);
@ -150,7 +152,7 @@ class FeatureFileTestGeneratorVisitor extends FeatureFileVisitor {
'{{step_name}}',
{{step_multi_line_strings}},
{{step_table}},
dependencies.world,
dependencies,
);
''';

View File

@ -37,7 +37,7 @@ class FlutterTestConfiguration extends TestConfiguration {
StdoutReporter(MessageLevel.error),
ProgressReporter(),
TestRunSummaryReporter(),
JsonReporter(path: './report.json'),
// JsonReporter(path: './report.json'),
]
..stepDefinitions = steps;
}

View File

@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:flutter_gherkin/src/flutter/adapters/widget_tester_app_driver_adapter.dart';
import 'package:flutter_gherkin/src/flutter/world/flutter_world.dart';
import 'package:gherkin/gherkin.dart';
@ -19,10 +21,12 @@ abstract class GherkinIntegrationTestRunner {
final TestConfiguration configuration;
final void Function() appMainFunction;
Reporter _reporter;
Hook _hook;
Iterable<ExecutableStep> _executableSteps;
Iterable<CustomParameter> _customParameters;
Reporter get reporter => _reporter;
Hook get hook => _hook;
Timeout scenarioExecutionTimeout = const Timeout(Duration(minutes: 10));
@ -32,6 +36,7 @@ abstract class GherkinIntegrationTestRunner {
) {
configuration.prepare();
_reporter = _registerReporters(configuration.reporters);
_hook = _registerHooks(configuration.hooks);
_customParameters =
_registerCustomParameters(configuration.customStepParameterDefinitions);
_executableSteps = _registerStepDefinitions(
@ -40,13 +45,29 @@ abstract class GherkinIntegrationTestRunner {
);
}
void run() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
onRun();
Future<void> run() async {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized()
as IntegrationTestWidgetsFlutterBinding;
try {
await _reporter.onTestRunStarted();
onRun();
} finally {
_safeInvokeFuture(() async => await reporter.onTestRunFinished());
_safeInvokeFuture(() async => await _hook.onAfterRun(configuration));
_safeInvokeFuture(() async => await reporter.dispose());
setTestResultData(binding);
}
}
void onRun();
void setTestResultData(IntegrationTestWidgetsFlutterBinding binding) {
binding.reportData = {
'gherkin_results': jsonEncode({'test': 'moo'})
};
}
@protected
Future<void> startApp(WidgetTester tester) async {
appMainFunction();
@ -64,10 +85,10 @@ abstract class GherkinIntegrationTestRunner {
if (configuration.createWorld != null) {
world = await configuration.createWorld(configuration);
world.setAttachmentManager(attachmentManager);
}
world = world ?? FlutterWorld();
world.setAttachmentManager(attachmentManager);
(world as FlutterWorld).setAppAdapter(WidgetTesterAppDriverAdapter(tester));
@ -82,7 +103,7 @@ abstract class GherkinIntegrationTestRunner {
String step,
Iterable<String> multiLineStrings,
dynamic table,
World world,
_TestDependencies dependencies,
) async {
final executable = _executableSteps.firstWhere(
(s) => s.expression.isMatch(step),
@ -101,15 +122,26 @@ abstract class GherkinIntegrationTestRunner {
executable,
);
// await reporter.onStepStarted(StepStartedMessage('some name', null));
await _onBeforeStepRun(
dependencies.world,
step,
table,
multiLineStrings,
);
final result = await executable.step.run(
world,
dependencies.world,
reporter,
configuration.defaultTimeout,
parameters,
);
await _onAfterStepRun(
step,
result,
dependencies,
);
if (result.result == StepExecutionResult.fail) {
throw TestFailure('Step: $step \n\n${result.resultReason}');
} else if (result is ErroredStepResult) {
@ -119,13 +151,29 @@ abstract class GherkinIntegrationTestRunner {
return result;
}
@protected
void cleanupScenarioRun(_TestDependencies dependencies) {
_safeInvokeFuture(
() async => await dependencies.attachmentManager.dispose());
_safeInvokeFuture(() async => await dependencies.world.dispose());
}
Reporter _registerReporters(Iterable<Reporter> reporters) {
final _reporter = AggregatedReporter();
final reporter = AggregatedReporter();
if (reporters != null) {
reporters.forEach((r) => _reporter.addReporter(r));
reporters.forEach((r) => reporter.addReporter(r));
}
return _reporter;
return reporter;
}
Hook _registerHooks(Iterable<Hook> hooks) {
final hook = AggregatedHook();
if (hooks != null) {
hook.addHooks(hooks);
}
return hook;
}
Iterable<CustomParameter> _registerCustomParameters(
@ -182,4 +230,48 @@ abstract class GherkinIntegrationTestRunner {
return parameters;
}
Future<void> _onAfterStepRun(
String step,
StepResult result,
_TestDependencies dependencies,
) async {
await _hook.onAfterStep(
dependencies.world,
step,
result,
);
await _reporter.onStepFinished(
StepFinishedMessage(
step,
RunnableDebugInformation('', 0, step),
result,
dependencies.attachmentManager.getAttachmentsForContext(step),
),
);
}
Future<void> _onBeforeStepRun(
World world,
String step,
table,
Iterable<String> multiLineStrings,
) async {
await _hook.onBeforeStep(world, step);
await reporter.onStepStarted(
StepStartedMessage(
step,
RunnableDebugInformation('', 0, step),
table: table,
multilineString:
multiLineStrings.isNotEmpty ? multiLineStrings.first : null,
),
);
}
void _safeInvokeFuture(Future<void> Function() fn) async {
try {
await fn().catchError((_, __) {});
} catch (_) {}
}
}

View File

@ -17,9 +17,8 @@ StepDefinitionGeneric ThenExpectElementToHaveValue() {
RegExp(r'I expect the {string} to be {string}$'),
(key, value, context) async {
try {
final text = await context.world.appDriver.getText(
context.world.appDriver.findBy(key, FindType.key),
);
final finder = context.world.appDriver.findBy(key, FindType.key);
final text = await context.world.appDriver.getText(finder);
context.expect(text, value);
} catch (e) {

View File

@ -165,8 +165,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: code_gen_changes
resolved-ref: "641cefc360be618c64838b4c19820a72062dc70a"
ref: "59b9db42e917927ccb8d1265e6cb8fe93ddbb73a"
resolved-ref: "59b9db42e917927ccb8d1265e6cb8fe93ddbb73a"
url: "https://github.com/jonsamwell/dart_gherkin.git"
source: git
version: "1.1.10"

View File

@ -27,7 +27,8 @@ dependencies:
gherkin:
git:
url: https://github.com/jonsamwell/dart_gherkin.git
ref: code_gen_changes
ref: 59b9db42e917927ccb8d1265e6cb8fe93ddbb73a
# ref: code_gen_changes
dev_dependencies:
test: