Skip to content

Commit

Permalink
Update test create-next-app running (#47611)
Browse files Browse the repository at this point in the history
This re-enables running the CNA tests for all non-docs changes as it's now ensuring we don't regress on turbopack or our default templates. 

Also fixes the main repo's package.json files from being modified during tests.
  • Loading branch information
ijjk authored Mar 28, 2023
1 parent 4d0f5a0 commit 28d56ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,8 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native

- run: echo "CNA_CHANGE<<EOF" >> $GITHUB_OUTPUT; echo "$(node scripts/run-for-change.js --type cna --always-canary --exec echo 'yup')" >> $GITHUB_OUTPUT; echo "EOF" >> $GITHUB_OUTPUT
id: cna-change

- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-jammy /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ env.NODE_LTS_VERSION }} | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_CNA=1 xvfb-run node run-tests.js test/integration/create-next-app/index.test.ts test/integration/create-next-app/templates.test.ts >> /proc/1/fd/1"
if: ${{ needs.build.outputs.docsChange == 'nope' && steps.cna-change.outputs.CNA_CHANGE == 'yup' }}
if: ${{ needs.build.outputs.docsChange == 'nope' }}

- name: Upload test trace
if: always()
Expand Down
19 changes: 8 additions & 11 deletions test/integration/create-next-app/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import {
shouldBeTypescriptProject,
spawnExitPromise,
} from './lib/utils'
import { Span } from 'next/dist/trace'

import { useTempDir } from '../../../test/lib/use-temp-dir'
import { fetchViaHTTP, findPort, killApp, launchApp } from 'next-test-utils'
import resolveFrom from 'resolve-from'
import { getPkgPaths } from '../../../test/lib/create-next-install'
import { createNextInstall } from '../../../test/lib/create-next-install'

const startsWithoutError = async (
appDir: string,
Expand All @@ -38,16 +39,16 @@ const startsWithoutError = async (

try {
const res = await fetchViaHTTP(appPort, '/')
expect(res.status).toBe(200)
expect(await res.text()).toContain('Get started by editing')
expect(res.status).toBe(200)

const apiRes = await fetchViaHTTP(appPort, '/api/hello')
expect(apiRes.status).toBe(200)
if (usingAppDirectory) {
expect(await apiRes.text()).toEqual('Hello, Next.js!')
} else {
expect(await apiRes.json()).toEqual({ name: 'John Doe' })
}
expect(apiRes.status).toBe(200)
} finally {
await killApp(app)
}
Expand All @@ -62,11 +63,9 @@ describe('create-next-app templates', () => {
}

beforeAll(async () => {
const span = new Span({ name: 'parent' })
testVersion = (
await getPkgPaths({
repoDir: path.join(__dirname, '../../../'),
nextSwcVersion: '',
})
await createNextInstall({ onlyPackages: true, parentSpan: span })
).get('next')
})

Expand Down Expand Up @@ -417,11 +416,9 @@ describe('create-next-app --experimental-app', () => {

beforeAll(async () => {
if (testVersion) return
const span = new Span({ name: 'parent' })
testVersion = (
await getPkgPaths({
repoDir: path.join(__dirname, '../../../'),
nextSwcVersion: '',
})
await createNextInstall({ onlyPackages: true, parentSpan: span })
).get('next')
})

Expand Down
12 changes: 9 additions & 3 deletions test/lib/create-next-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const { linkPackages } =
require('../../.github/actions/next-stats-action/src/prepare/repo-setup')()

async function createNextInstall({
parentSpan,
dependencies,
installCommand,
parentSpan = null,
dependencies = null,
installCommand = null,
packageJson = {},
dirSuffix = '',
onlyPackages = false,
}) {
return await parentSpan
.traceChild('createNextInstall')
Expand Down Expand Up @@ -96,6 +97,11 @@ async function createNextInstall({
repoDir: tmpRepoDir,
})
)

if (onlyPackages) {
return pkgPaths
}

combinedDependencies = {
next: pkgPaths.get('next'),
...Object.keys(dependencies).reduce((prev, pkg) => {
Expand Down

0 comments on commit 28d56ec

Please sign in to comment.