CockpitTestSuite.fromJson constructor

CockpitTestSuite.fromJson(
  1. Object? value, {
  2. String path = r'$',
})

Decodes a CockpitTestSuite from a JSON object.

Implementation

factory CockpitTestSuite.fromJson(Object? value, {String path = r'$'}) {
  final json = CockpitTestValueReader.object(value, path);
  CockpitTestValueReader.keys(
    json,
    const <String>{
      'schemaVersion',
      'kind',
      'id',
      'name',
      'description',
      'tags',
      'cases',
      'fixtures',
      'matrix',
      'execution',
      'report',
      'includeTags',
      'excludeTags',
    },
    path,
    required: const <String>{'schemaVersion', 'kind', 'id', 'cases'},
    allowExtensions: true,
  );
  final rawCases = CockpitTestValueReader.list(json['cases'], '$path.cases');
  final rawFixtures = json['fixtures'] == null
      ? const <Object?>[]
      : CockpitTestValueReader.list(json['fixtures'], '$path.fixtures');
  return CockpitTestSuite(
    schemaVersion: CockpitTestValueReader.string(
      json['schemaVersion'],
      '$path.schemaVersion',
    ),
    kind: CockpitTestValueReader.string(json['kind'], '$path.kind'),
    id: CockpitTestValueReader.string(json['id'], '$path.id', id: true),
    name: CockpitTestValueReader.optionalString(json['name'], '$path.name'),
    description: CockpitTestValueReader.optionalString(
      json['description'],
      '$path.description',
    ),
    tags: _strings(json['tags'], '$path.tags'),
    cases: <CockpitTestSuiteEntry>[
      for (var index = 0; index < rawCases.length; index += 1)
        CockpitTestSuiteEntry.fromJson(
          rawCases[index],
          path: '$path.cases[$index]',
        ),
    ],
    fixtures: <CockpitTestFixture>[
      for (var index = 0; index < rawFixtures.length; index += 1)
        CockpitTestFixture.fromJson(
          rawFixtures[index],
          path: '$path.fixtures[$index]',
        ),
    ],
    matrix: json['matrix'] == null
        ? CockpitTestMatrix.empty
        : CockpitTestMatrix.fromJson(json['matrix'], path: '$path.matrix'),
    execution: json['execution'] == null
        ? CockpitTestSuiteExecutionPolicy.standard
        : CockpitTestSuiteExecutionPolicy.fromJson(
            json['execution'],
            path: '$path.execution',
          ),
    report: json['report'] == null
        ? CockpitTestSuiteReportPolicy.standard
        : CockpitTestSuiteReportPolicy.fromJson(
            json['report'],
            path: '$path.report',
          ),
    includeTags: _strings(json['includeTags'], '$path.includeTags'),
    excludeTags: _strings(json['excludeTags'], '$path.excludeTags'),
    extensions: <String, Object?>{
      for (final entry in json.entries)
        if (entry.key.startsWith('x-')) entry.key: entry.value,
    },
  );
}