createMemoryTests static method

List<PendingTest> createMemoryTests(
  1. dynamic object, {
  2. bool ignoreImages = true,
})

Creates a list of Test objects from a given dynamic object. The dynamic object must be either a List of Map objects or an individual Map object that follow the structure defined in Test.fromDynamic.

The optional ignoreImages parameter can be used to save memory when a large number of tests are loaded. By ignoring the images, the memory required to host those images is removed.

This will never return null. If no tests exists in the object then this will return an empty array.

Implementation

static List<PendingTest> createMemoryTests(
  dynamic object, {
  bool ignoreImages = true,
}) {
  List<PendingTest>? tests;

  if (object is List) {
    final tempTests = JsonClass.fromDynamicList(
      object,
      (map) => Test.fromDynamic(map),
    )!;
    tempTests.removeWhere(
      (test) =>
          test.name?.isNotEmpty != true && test.steps.isNotEmpty != true,
    );

    tests = [];
    for (var t in tempTests) {
      tests.add(PendingTest.memory(t));
    }
  } else {
    final test = Test.fromDynamic(object);

    if (test.name?.isNotEmpty == true && test.steps.isNotEmpty == true) {
      tests = [PendingTest.memory(test)];
    }
  }

  return tests ?? <PendingTest>[];
}