|
| 1 | +import { |
| 2 | + createNextApp, |
| 3 | + spawnExitPromise, |
| 4 | + tryNextDev, |
| 5 | + useTempDir, |
| 6 | +} from '../utils' |
| 7 | + |
| 8 | +let testVersion |
| 9 | +beforeAll(async () => { |
| 10 | + if (testVersion) return |
| 11 | + // TODO: investigate moving this post publish or create deployed GH#57025 |
| 12 | + // tarballs to avoid these failing while a publish is in progress |
| 13 | + testVersion = 'latest' |
| 14 | + // const span = new Span({ name: 'parent' }) |
| 15 | + // testVersion = ( |
| 16 | + // await createNextInstall({ onlyPackages: true, parentSpan: span }) |
| 17 | + // ).get('next') |
| 18 | +}) |
| 19 | + |
| 20 | +describe.each(['app', 'pages'] as const)( |
| 21 | + 'CNA options matrix - %s', |
| 22 | + (pagesOrApp) => { |
| 23 | + const allFlagValues = { |
| 24 | + app: [pagesOrApp === 'app' ? '--app' : '--no-app'], |
| 25 | + ts: ['--js', '--ts'], |
| 26 | + importAlias: [ |
| 27 | + '--import-alias=@acme/*', |
| 28 | + '--import-alias=@/*', |
| 29 | + '--no-import-alias', |
| 30 | + ], |
| 31 | + // doesn't affect if the app builds or not |
| 32 | + // eslint: ['--eslint', '--no-eslint'], |
| 33 | + eslint: ['--eslint'], |
| 34 | + srcDir: ['--src-dir', '--no-src-dir'], |
| 35 | + tailwind: ['--tailwind', '--no-tailwind'], |
| 36 | + // shouldn't affect if the app builds or not |
| 37 | + // packageManager: ['--use-npm', '--use-pnpm', '--use-yarn', '--use-bun'], |
| 38 | + } |
| 39 | + |
| 40 | + const getPermutations = <T>(items: T[][]): T[][] => { |
| 41 | + if (!items.length) return [[]] |
| 42 | + const [first, ...rest] = items |
| 43 | + const children = getPermutations(rest) |
| 44 | + return first.flatMap((value) => |
| 45 | + children.map((child) => [value, ...child]) |
| 46 | + ) |
| 47 | + } |
| 48 | + |
| 49 | + const flagPermutations = getPermutations(Object.values(allFlagValues)) |
| 50 | + const testCases = flagPermutations.map((flags) => ({ |
| 51 | + name: flags.join(' '), |
| 52 | + flags, |
| 53 | + })) |
| 54 | + |
| 55 | + let id = 0 |
| 56 | + it.each(testCases)('$name', async ({ flags }) => { |
| 57 | + await useTempDir(async (cwd) => { |
| 58 | + const projectName = `cna-matrix-${pagesOrApp}-${id++}` |
| 59 | + const childProcess = createNextApp( |
| 60 | + [projectName, ...flags], |
| 61 | + { |
| 62 | + cwd, |
| 63 | + }, |
| 64 | + testVersion |
| 65 | + ) |
| 66 | + |
| 67 | + const exitCode = await spawnExitPromise(childProcess) |
| 68 | + expect(exitCode).toBe(0) |
| 69 | + |
| 70 | + await tryNextDev({ |
| 71 | + cwd, |
| 72 | + projectName, |
| 73 | + }) |
| 74 | + }) |
| 75 | + }) |
| 76 | + } |
| 77 | +) |
0 commit comments