toJson method

Map<String, Object?> toJson()

Implementation

Map<String, Object?> toJson() => {
  // `id` rather than `scenario`, and `steps` alongside a preview's
  // `channels`: a reader walking the whole artifact should not need to know
  // which half a row came from to find out what it is called.
  'id': scenario,
  'state': state.name,
  'package': ?package,
  'inconclusive': ?inconclusive,
  if (baseMs != null || headMs != null)
    'ms': {'base': ?baseMs, 'head': ?headMs},
  if (baseErrors.isNotEmpty || headErrors.isNotEmpty)
    'errors': {
      if (baseErrors.isNotEmpty) 'base': baseErrors,
      if (headErrors.isNotEmpty) 'head': headErrors,
    },
  if (branches.isNotEmpty)
    'branches': [
      for (var branch in branches)
        {
          'label': branch.label,
          'state': branch.added ? 'added' : 'removed',
          'steps': branch.steps,
          if (branch.path.isNotEmpty) 'path': branch.path,
        },
    ],
  'steps': [
    for (var item in items)
      {
        ...item.toJson(),
        'frames': ?(frames[item.id] == null
            ? null
            : {
                'base': ?frames[item.id]!.base?.toJson(),
                'head': ?frames[item.id]!.head?.toJson(),
              }),
      },
  ],
};