Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
192 lines
4.4 KiB
TypeScript
192 lines
4.4 KiB
TypeScript
/**
|
|
* @fileoverview
|
|
*
|
|
* This file contains utilities for `create-next-app` testing.
|
|
*/
|
|
|
|
import { execSync, spawn, SpawnOptions } from 'child_process'
|
|
import { existsSync } from 'fs'
|
|
import { join, resolve } from 'path'
|
|
import glob from 'glob'
|
|
import Conf from 'next/dist/compiled/conf'
|
|
|
|
import {
|
|
getProjectSetting,
|
|
mapSrcFiles,
|
|
projectSpecification,
|
|
} from './specification'
|
|
import {
|
|
CustomTemplateOptions,
|
|
DefaultTemplateOptions,
|
|
ProjectDeps,
|
|
ProjectFiles,
|
|
} from './types'
|
|
|
|
const cli = require.resolve('create-next-app/dist/index.js')
|
|
|
|
/**
|
|
* Run the built version of `create-next-app` with the given arguments.
|
|
*/
|
|
export const createNextApp = (
|
|
args: string[],
|
|
options?: SpawnOptions,
|
|
testVersion?: string,
|
|
clearPreferences: boolean = true
|
|
) => {
|
|
const conf = new Conf({ projectName: 'create-next-app' })
|
|
if (clearPreferences) {
|
|
conf.clear()
|
|
}
|
|
|
|
console.log(`[TEST] $ ${cli} ${args.join(' ')}`, { options })
|
|
|
|
const cloneEnv = { ...process.env }
|
|
// unset CI env as this skips the auto-install behavior
|
|
// being tested
|
|
delete cloneEnv.CI
|
|
delete cloneEnv.CIRCLECI
|
|
delete cloneEnv.GITHUB_ACTIONS
|
|
delete cloneEnv.CONTINUOUS_INTEGRATION
|
|
delete cloneEnv.RUN_ID
|
|
delete cloneEnv.BUILD_NUMBER
|
|
|
|
cloneEnv.NEXT_PRIVATE_TEST_VERSION = testVersion || 'canary'
|
|
|
|
return spawn('node', [cli].concat(args), {
|
|
...options,
|
|
env: {
|
|
...cloneEnv,
|
|
...options.env,
|
|
},
|
|
})
|
|
}
|
|
|
|
export const projectShouldHaveNoGitChanges = ({
|
|
cwd,
|
|
projectName,
|
|
}: DefaultTemplateOptions) => {
|
|
const projectDirname = join(cwd, projectName)
|
|
|
|
try {
|
|
execSync('git diff --quiet', { cwd: projectDirname })
|
|
} catch {
|
|
execSync('git status', { cwd: projectDirname, stdio: 'inherit' })
|
|
execSync('git --no-pager diff', { cwd: projectDirname, stdio: 'inherit' })
|
|
|
|
throw new Error('Found unexpected git changes.')
|
|
}
|
|
}
|
|
|
|
export const projectFilesShouldExist = ({
|
|
cwd,
|
|
projectName,
|
|
files,
|
|
}: ProjectFiles) => {
|
|
const projectRoot = resolve(cwd, projectName)
|
|
for (const file of files) {
|
|
try {
|
|
expect(existsSync(resolve(projectRoot, file))).toBe(true)
|
|
} catch (err) {
|
|
require('console').error(
|
|
`missing expected file ${file}`,
|
|
glob.sync('**/*', { cwd, ignore: '**/node_modules/**' }),
|
|
files
|
|
)
|
|
throw err
|
|
}
|
|
}
|
|
}
|
|
|
|
export const projectFilesShouldNotExist = ({
|
|
cwd,
|
|
projectName,
|
|
files,
|
|
}: ProjectFiles) => {
|
|
const projectRoot = resolve(cwd, projectName)
|
|
for (const file of files) {
|
|
try {
|
|
expect(existsSync(resolve(projectRoot, file))).toBe(false)
|
|
} catch (err) {
|
|
require('console').error(
|
|
`unexpected file present ${file}`,
|
|
glob.sync('**/*', { cwd, ignore: '**/node_modules/**' }),
|
|
files
|
|
)
|
|
throw err
|
|
}
|
|
}
|
|
}
|
|
|
|
export const projectDepsShouldBe = ({
|
|
cwd,
|
|
projectName,
|
|
type,
|
|
deps,
|
|
}: ProjectDeps) => {
|
|
const projectRoot = resolve(cwd, projectName)
|
|
const pkgJson = require(resolve(projectRoot, 'package.json'))
|
|
expect(Object.keys(pkgJson[type] || {}).sort()).toEqual(deps.sort())
|
|
}
|
|
|
|
export const shouldBeTemplateProject = ({
|
|
cwd,
|
|
projectName,
|
|
template,
|
|
mode,
|
|
srcDir,
|
|
}: CustomTemplateOptions) => {
|
|
projectFilesShouldExist({
|
|
cwd,
|
|
projectName,
|
|
files: getProjectSetting({ template, mode, setting: 'files', srcDir }),
|
|
})
|
|
|
|
// Tailwind templates share the same files (tailwind.config.mjs, postcss.config.mjs)
|
|
if (
|
|
!['app-tw', 'app-tw-empty', 'default-tw', 'default-tw-empty'].includes(
|
|
template
|
|
)
|
|
) {
|
|
projectFilesShouldNotExist({
|
|
cwd,
|
|
projectName,
|
|
files: mapSrcFiles(
|
|
projectSpecification[template][mode === 'js' ? 'ts' : 'js'].files,
|
|
srcDir
|
|
),
|
|
})
|
|
}
|
|
|
|
projectDepsShouldBe({
|
|
type: 'dependencies',
|
|
cwd,
|
|
projectName,
|
|
deps: getProjectSetting({ template, mode, setting: 'deps' }),
|
|
})
|
|
|
|
projectDepsShouldBe({
|
|
type: 'devDependencies',
|
|
cwd,
|
|
projectName,
|
|
deps: getProjectSetting({ template, mode, setting: 'devDeps' }),
|
|
})
|
|
}
|
|
|
|
export const shouldBeJavascriptProject = ({
|
|
cwd,
|
|
projectName,
|
|
template,
|
|
srcDir,
|
|
}: Omit<CustomTemplateOptions, 'mode'>) => {
|
|
shouldBeTemplateProject({ cwd, projectName, template, mode: 'js', srcDir })
|
|
}
|
|
|
|
export const shouldBeTypescriptProject = ({
|
|
cwd,
|
|
projectName,
|
|
template,
|
|
srcDir,
|
|
}: Omit<CustomTemplateOptions, 'mode'>) => {
|
|
shouldBeTemplateProject({ cwd, projectName, template, mode: 'ts', srcDir })
|
|
}
|