(logger: Logger, workspaceContext: WorkspaceContext, folderPath: string)
| 46 | * versioned with the Flutter SDK and don't need a package version check. |
| 47 | */ |
| 48 | export function getPackageTestCapabilitiesForDartProject(logger: Logger, workspaceContext: WorkspaceContext, folderPath: string): DartTestCapabilities { |
| 49 | // Don't look for a version in places where we don't support `dart run test`. |
| 50 | if (workspaceContext.config.supportsDartRunTest === false) |
| 51 | return DartTestCapabilities.empty; |
| 52 | |
| 53 | // We cache by both folder and package map so we can look up a cache value without |
| 54 | // having to locate the package map. |
| 55 | let cached = cachedTestCapabilities.get(folderPath); |
| 56 | if (cached !== undefined) |
| 57 | return cached; |
| 58 | |
| 59 | // Test capabilities are the same for projects in a workspace, so look up the package map path and we'll also cache |
| 60 | // on that. If there is no package map, there is no pkg:test. |
| 61 | const packageFile = PackageMap.findPackagesFile(folderPath); |
| 62 | if (!packageFile) |
| 63 | return DartTestCapabilities.empty; |
| 64 | |
| 65 | // Check the cache again for the package map. |
| 66 | cached = cachedTestCapabilities.get(packageFile); |
| 67 | if (cached !== undefined) |
| 68 | return cached; |
| 69 | |
| 70 | try { |
| 71 | const capabilities = getCapabilitiesFromVersionInPackageGraph(logger, packageFile) ?? DartTestCapabilities.empty; |
| 72 | cachedTestCapabilities.add(folderPath, capabilities, packageTestCapabilitiesCacheTimeInMs); |
| 73 | cachedTestCapabilities.add(packageFile, capabilities, packageTestCapabilitiesCacheTimeInMs); |
| 74 | |
| 75 | return capabilities; |
| 76 | } catch (e) { |
| 77 | logger.error(`Failed to get package:test capabilities: ${e}`); |
| 78 | |
| 79 | return DartTestCapabilities.empty; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | interface PackageGraphJson { |
| 84 | packages?: PackageGraphPackage[]; |
no test coverage detected