( packageJsonPath: string, variantLabel: string, testAppPath: string, )
| 79 | } |
| 80 | |
| 81 | async function getVariantBuildCommand( |
| 82 | packageJsonPath: string, |
| 83 | variantLabel: string, |
| 84 | testAppPath: string, |
| 85 | ): Promise<{ buildCommand: string; assertCommand: string; testLabel: string; matchedVariantLabel?: string }> { |
| 86 | try { |
| 87 | const packageJsonContent = await readFile(packageJsonPath, 'utf-8'); |
| 88 | const packageJson: PackageJson = JSON.parse(packageJsonContent); |
| 89 | |
| 90 | const allVariants = [ |
| 91 | ...(packageJson.sentryTest?.variants || []), |
| 92 | ...(packageJson.sentryTest?.optionalVariants || []), |
| 93 | ]; |
| 94 | |
| 95 | const matchingVariant = findMatchingVariant(allVariants, variantLabel); |
| 96 | |
| 97 | if (matchingVariant) { |
| 98 | return { |
| 99 | buildCommand: matchingVariant['build-command'] || 'pnpm test:build', |
| 100 | assertCommand: matchingVariant['assert-command'] || 'pnpm test:assert', |
| 101 | testLabel: matchingVariant.label || testAppPath, |
| 102 | matchedVariantLabel: matchingVariant.label, |
| 103 | }; |
| 104 | } |
| 105 | |
| 106 | console.log(`No matching variant found for "${variantLabel}" in ${testAppPath}, using default build`); |
| 107 | } catch { |
| 108 | console.log(`Could not read variants from package.json for ${testAppPath}, using default build`); |
| 109 | } |
| 110 | |
| 111 | return { |
| 112 | buildCommand: 'pnpm test:build', |
| 113 | assertCommand: 'pnpm test:assert', |
| 114 | testLabel: testAppPath, |
| 115 | }; |
| 116 | } |
| 117 | |
| 118 | async function run(): Promise<void> { |
| 119 | // Load environment variables from .env file locally |
no test coverage detected