Created
September 27, 2019 13:26
-
-
Save knaeckeKami/a8306b442cbaef69f2d044c5848a0b06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_driver/driver_extension.dart'; | |
import 'package:flutter_test/flutter_test.dart' as test_base; | |
import 'package:test/test.dart'; | |
List<dynamic> exceptions = []; | |
var status = "waiting"; | |
///custom expect method to intercept fails | |
expect(dynamic actual, dynamic matcher, {String reason, dynamic skip}) { | |
try { | |
test_base.expect(actual, WrappedMatcher(matcher), | |
reason: reason, skip: skip); | |
} catch (err) { | |
exceptions.add(err); | |
rethrow; | |
} | |
} | |
void setUp(Function setup) => test_base.setUp(setup); | |
void setUpAll(Function setup) => test_base.setUpAll(setup); | |
void tearDown(Function tearDown) => test_base.tearDown(tearDown); | |
void tearDownAll(Function tearDown) => test_base.tearDownAll(tearDown); | |
initIntegrationTests() { | |
enableFlutterDriverExtension(handler: (request) => Future.value(status)); | |
test_base.tearDownAll(() { | |
if (exceptions.isEmpty) { | |
status = "ok"; | |
} else { | |
status = "fail: " + exceptions.join("\n"); | |
} | |
}); | |
} | |
class WrappedMatcher extends test_base.Matcher { | |
test_base.Matcher matcher; | |
WrappedMatcher(dynamic m) { | |
if (m is test_base.Matcher) { | |
this.matcher = m; | |
} else { | |
this.matcher = test_base.equals(m); | |
} | |
} | |
@override | |
test_base.Description describe(test_base.Description description) { | |
return matcher.describe(description); | |
} | |
@override | |
bool matches(item, Map matchState) { | |
final result = matcher.matches(item, matchState); | |
if (!result) { | |
exceptions.add(Exception("expected $item, was ${matchState.toString()}")); | |
} | |
return result; | |
} | |
} | |
void test( | |
Object description, | |
Function body, { | |
String testOn, | |
Timeout timeout, | |
dynamic skip, | |
dynamic tags, | |
Map<String, dynamic> onPlatform, | |
int retry, | |
}) { | |
if (skip == true) return; | |
try { | |
test_base.test(description, () async { | |
try { | |
await body(); | |
} catch (err) { | |
exceptions.add(err); | |
rethrow; | |
} | |
}, | |
testOn: testOn, | |
timeout: timeout, | |
skip: skip, | |
tags: tags, | |
onPlatform: onPlatform, | |
retry: retry); | |
} catch (err) { | |
exceptions.add(err); | |
rethrow; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment