diRoleAppTest function

Future<MatrixAppTest> diRoleAppTest({
  1. Set<DiLifetime> lifetimes = const {},
})

The test of the DI role that the CLI keeps in its app_tests/di_role, for the apps with the role, whichever module provides it, whose modules register services, at least one of each of lifetimes: once the start-up of the app ran, every service resolves, a singleton and a lazy singleton to one instance; resetDependencies() removes them all, and registerDependencies() registers them again.

The test knows only the role. The matrix writes the services of each app for it, from the registrations of its DI role, into registeredServicesFile. The matrix of the fixtures runs it too, in the apps whose services have every lifetime. Its probe, probeServices() of integration_test/di_role/probe.dart, resolves each service on a device for the start check, a singleton and a lazy singleton twice, without calling it or resetting the container.

Implementation

Future<MatrixAppTest> diRoleAppTest({
  Set<DiLifetime> lifetimes = const {},
}) async =>
    MatrixAppTest(
      '${await appTestsDirectoryOf('smf_flutter_cli')}/di_role',
      appliesTo: (app) {
        if (!app.hook!.presentRoles.contains(diRole)) return false;
        final registered = {
          for (final registration in _servicesOf(app)) registration.lifetime,
        };
        return registered.isNotEmpty && registered.containsAll(lifetimes);
      },
      generatedFiles: _registeredServicesOf,
      roles: {diRole},
      startProbe: const MatrixStartProbe(
        'integration_test/di_role/probe.dart',
        'probeServices',
      ),
    );