buildStepForTestAsset function
Creates an in-memory InMemoryBuildStep for the given asset.
allowedExtensions controls which output extensions this build step will
accept when writing files. Any extraAssets will be scanned and added to
the internal assets graph so that references between assets are available
to the resolver and can be resolved during tests.
Implementation
@visibleForTesting
/// Creates an in-memory [InMemoryBuildStep] for the given [asset].
///
/// [allowedExtensions] controls which output extensions this build step will
/// accept when writing files. Any [extraAssets] will be scanned and added to
/// the internal assets graph so that references between assets are available
/// to the resolver and can be resolved during tests.
InMemoryBuildStep buildStepForTestAsset(
Asset asset, {
Set<String> allowedExtensions = const {'.g.dart'},
Set<String> includePackages = const {},
List<Asset> extraAssets = const [],
}) {
final fileResolver = getTestFileResolver();
final graph = AssetsGraph('hash');
final scanner = ReferencesScanner(graph, fileResolver);
scanDartSdkAndPackages(scanner, packages: includePackages);
for (final extraAsset in extraAssets) {
scanner.scan(extraAsset);
}
scanner.scan(asset);
final resolver = Resolver.from(graph, fileResolver, SourceParser());
return InMemoryBuildStep(asset, resolver, allowedExtensions: allowedExtensions);
}