testReader method
Reads and returns zero or more tests from the assets defined by
testAssets. This ignores the context
that is passed in. This will
never throw an error or return null
and will instead return an empty
array if it encounters issues loading the tests.
If the suiteName
is not-null, this will exclude any tests that are not
same test suite.
Implementation
Future<List<PendingTest>> testReader(
BuildContext? context, {
String? suiteName,
}) async {
List<String>? files = <String>[];
if (testAssetIndex?.isNotEmpty == true) {
try {
var indexData = await rootBundle.loadString(testAssetIndex!);
files = List<String>.from(json.decode(indexData));
} catch (e, stack) {
_logger.severe('Error in AssetTestStore.testReader', e, stack);
}
} else {
files = testAssets;
}
var tests = <PendingTest>[];
if (files?.isNotEmpty == true) {
for (var asset in files!) {
try {
var text = await rootBundle.loadString(asset);
if (text.isNotEmpty == true) {
var parsed = json.decode(text);
tests.addAll(TestStore.createMemoryTests(parsed));
}
} catch (e, stack) {
_logger.severe('Error in AssetTestStore.testReader', e, stack);
}
}
tests.removeWhere(
(test) => suiteName?.isNotEmpty == true && suiteName != test.suiteName,
);
}
return tests;
}