testReader static method

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

Reads the tests from the clipboard. There can be one or more tests in the clipboard. 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

static Future<List<PendingTest>> testReader(
  BuildContext context, {
  String? suiteName,
}) async {
  var tests = <PendingTest>[];

  try {
    final data = await Clipboard.getData('text/plain');
    final text = data?.text;
    if (text?.isNotEmpty == true) {
      final parsed = json.decode(text!);
      tests = TestStore.createMemoryTests(parsed);
    }

    tests.removeWhere(
      (test) => suiteName?.isNotEmpty == true && suiteName != test.suiteName,
    );
  } catch (e, stack) {
    _logger.severe('Error in ClipboardTestStore.testReader', e, stack);
  }

  return tests;
}