expectGraphSnapshots function
expectGraphSnapshot for each of environments, one file each:
<directory>/<environment name>.txt.
graphOf builds the graph for one environment — typically the generated
root scope given that environment, in a test scope. Every environment is
checked before anything fails, and the failure names each one that
differs, so a review sees at once how dev and prod moved apart. Each
graph is disposed once it is described.
update and COBALT_UPDATE_SNAPSHOTS=1 rewrite every file, as for one.
Implementation
Future<void> expectGraphSnapshots(
FutureOr<CobaltScope> Function(CobaltEnvironment environment) graphOf, {
required Iterable<CobaltEnvironment> environments,
required String directory,
bool? update,
}) async {
final failures = <String>[];
for (final environment in environments) {
final scope = await graphOf(environment);
try {
expectGraphSnapshot(
scope,
'$directory/${environment.name}.txt',
update: update,
);
} on TestFailure catch (failure) {
failures.add('environment "${environment.name}": ${failure.message}');
} finally {
await scope.dispose();
}
}
if (failures.isNotEmpty) fail(failures.join('\n\n'));
}