parseString static method

EnsembleTestCase parseString(
  1. String content, {
  2. String? sourcePath,
  3. Map<String, dynamic> inputs = const {},
  4. Map<String, dynamic> scenario = const {},
  5. String? scenarioId,
})

Parses one *.test.yaml document from content.

Implementation

static EnsembleTestCase parseString(
  String content, {
  String? sourcePath,
  Map<String, dynamic> inputs = const {},
  Map<String, dynamic> scenario = const {},
  String? scenarioId,
}) {
  final dynamic doc = loadYaml(content);
  if (doc is! YamlMap) {
    throw EnsembleTestFailure(
        'Invalid test file${sourcePath != null ? ' ($sourcePath)' : ''}: root must be a map');
  }

  if (doc.containsKey('tests')) {
    throw EnsembleTestFailure(
      'Each *.test.yaml file defines one test at the root — remove the "tests" '
      'wrapper and put id, startScreen, and steps at the top level.',
    );
  }

  return _parseTestCase(
    doc,
    sourcePath: sourcePath,
    inputs: inputs,
    scenario: scenario,
    scenarioId: scenarioId,
  );
}