fromDocument static method
Implementation
static List<EnsembleTestDefinitionPreview> fromDocument(
String path,
dynamic document,
) {
if (document == null) return const [];
if (document is! YamlMap) {
throw EnsembleTestFailure(
'Invalid test file ($path): root must be a map',
);
}
final id = document['id']?.toString();
if (id == null || id.isEmpty) {
throw EnsembleTestFailure('Each test must have an "id"');
}
final feature = document['feature']?.toString();
final tags = _stringList(document['tags']);
final sessionValue = document['session']?.toString();
final session =
sessionValue == null || sessionValue.isEmpty ? null : sessionValue;
final scenarios = document['scenarios'];
if (scenarios is YamlList && scenarios.isNotEmpty) {
return [
for (final entry in scenarios)
if (entry is YamlMap)
EnsembleTestDefinitionPreview(
assetPath: path,
testCase: EnsembleTestCase(
id: '$id[${entry['id']}]',
sourcePath: path,
feature: feature,
tags: tags,
session: session,
steps: const [],
),
),
];
}
return [
EnsembleTestDefinitionPreview(
assetPath: path,
testCase: EnsembleTestCase(
id: id,
sourcePath: path,
feature: feature,
tags: tags,
session: session,
steps: const [],
),
),
];
}