-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: check most possible combination of CNA flags
- Loading branch information
1 parent
9a72ad6
commit 3756801
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
createNextApp, | ||
spawnExitPromise, | ||
tryNextDev, | ||
useTempDir, | ||
} from '../utils' | ||
|
||
let testVersion | ||
beforeAll(async () => { | ||
if (testVersion) return | ||
// TODO: investigate moving this post publish or create deployed GH#57025 | ||
// tarballs to avoid these failing while a publish is in progress | ||
testVersion = 'latest' | ||
// const span = new Span({ name: 'parent' }) | ||
// testVersion = ( | ||
// await createNextInstall({ onlyPackages: true, parentSpan: span }) | ||
// ).get('next') | ||
}) | ||
|
||
describe.each(['app', 'pages'] as const)( | ||
'CNA options matrix - %s', | ||
(pagesOrApp) => { | ||
const allFlagValues = { | ||
app: [pagesOrApp === 'app' ? '--app' : '--no-app'], | ||
ts: ['--js', '--ts'], | ||
importAlias: [ | ||
'--import-alias=@acme/*', | ||
'--import-alias=@/*', | ||
'--no-import-alias', | ||
], | ||
// doesn't affect if the app builds or not | ||
// eslint: ['--eslint', '--no-eslint'], | ||
eslint: ['--eslint'], | ||
srcDir: ['--src-dir', '--no-src-dir'], | ||
tailwind: ['--tailwind', '--no-tailwind'], | ||
// shouldn't affect if the app builds or not | ||
// packageManager: ['--use-npm', '--use-pnpm', '--use-yarn', '--use-bun'], | ||
} | ||
|
||
const getPermutations = <T>(items: T[][]): T[][] => { | ||
if (!items.length) return [[]] | ||
const [first, ...rest] = items | ||
const children = getPermutations(rest) | ||
return first.flatMap((value) => | ||
children.map((child) => [value, ...child]) | ||
) | ||
} | ||
|
||
const flagPermutations = getPermutations(Object.values(allFlagValues)) | ||
const testCases = flagPermutations.map((flags) => ({ | ||
name: flags.join(' '), | ||
flags, | ||
})) | ||
|
||
let id = 0 | ||
it.each(testCases)('$name', async ({ flags }) => { | ||
await useTempDir(async (cwd) => { | ||
const projectName = `cna-matrix-${pagesOrApp}-${id++}` | ||
const childProcess = createNextApp( | ||
[projectName, ...flags], | ||
{ | ||
cwd, | ||
}, | ||
testVersion | ||
) | ||
|
||
const exitCode = await spawnExitPromise(childProcess) | ||
expect(exitCode).toBe(0) | ||
|
||
await tryNextDev({ | ||
cwd, | ||
projectName, | ||
}) | ||
}) | ||
}) | ||
} | ||
) |