read static method
Reads the run.json in directory.
root is what file will resolve artifact paths against — the worktree
the run executed in; the default only suits a script running at that
worktree's root.
Throws FormatException when the directory holds no report, or holds one this version cannot read. Both name what was found and what was expected, since the reader is usually looking at build output from elsewhere.
Implementation
static Future<ScenarioRunReport> read(
String directory, {
String root = '.',
}) async {
var file = File(
'$directory${Platform.pathSeparator}$scenarioRunReportFile',
);
if (!file.existsSync()) {
throw FormatException(
'No $scenarioRunReportFile in "$directory". '
'Run `fw run scenarios run` first.',
);
}
return ScenarioRunReport(
directory: directory,
root: root,
run: ScenarioRunResult.fromJson(switch (jsonDecode(
await file.readAsString(),
)) {
Map json => json.cast<String, Object?>(),
var other => throw FormatException(
'${file.path} is ${other.runtimeType}, not an object.',
),
}),
);
}