testReader method

Future<List<PendingTest>> testReader(
  1. BuildContext? context, {
  2. String? suiteName,
})

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 {
      final 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;
  }

  final tests = <PendingTest>[];

  if (files?.isNotEmpty == true) {
    for (var asset in files!) {
      try {
        final text = await rootBundle.loadString(asset);
        if (text.isNotEmpty == true) {
          final 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;
}