|
| 1 | +import console from "console" |
| 2 | +import execa from "execa" |
| 3 | +import { promises as fs } from "fs" |
| 4 | +import path from "path" |
| 5 | +import { v4 as uuidv4 } from "uuid" |
| 6 | + |
| 7 | +export const testDefaultOptions = async () => { |
| 8 | + const createNextStackDir = process.cwd() |
| 9 | + |
| 10 | + // Create unique id for this run |
| 11 | + const testRunId = uuidv4() |
| 12 | + |
| 13 | + // Switch to unique test directory |
| 14 | + const runDirectory = path.resolve( |
| 15 | + `../create-next-stack-tests/run-${testRunId}` |
| 16 | + ) |
| 17 | + await fs.mkdir(runDirectory, { recursive: true }) |
| 18 | + process.chdir(runDirectory) |
| 19 | + console.log(`Created test run directory at ${runDirectory}`) |
| 20 | + |
| 21 | + // Run /bin/run-prod to test against compiled js files in /lib instead of ts-files in /src using ts-node. |
| 22 | + const pathToProdCLI = path.resolve(`${createNextStackDir}/bin/run-prod`) |
| 23 | + |
| 24 | + console.log(`Making /bin/run readable and executable by all.`) |
| 25 | + await fs.chmod(pathToProdCLI, 0o555) |
| 26 | + |
| 27 | + console.log(`Running command: ${pathToProdCLI} --debug .`) |
| 28 | + const execaProcess = execa(pathToProdCLI, ["--debug", "."], { |
| 29 | + timeout: 10 * 60 * 1000, |
| 30 | + }) // 10 minutes |
| 31 | + execaProcess.stdout?.pipe(process.stdout) |
| 32 | + execaProcess.stderr?.pipe(process.stderr) |
| 33 | + |
| 34 | + console.log("Sending \\n to accept default options.") |
| 35 | + execaProcess.stdin?.write("\n") // Press |
| 36 | + |
| 37 | + await execaProcess |
| 38 | + |
| 39 | + console.log("Checking formatting") |
| 40 | + await execa("npx", ["prettier", "--check", "--ignore-path=.gitignore", "."]) |
| 41 | + |
| 42 | + console.log("Checking linting") |
| 43 | + await execa("yarn", ["lint"]) |
| 44 | + |
| 45 | + console.log("Running yarn build") |
| 46 | + await execa("yarn", ["build"]) |
| 47 | +} |
0 commit comments