Unverified Commit 613e4c91 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update yarn PnP tests and disable swc file reading for PnP (#33236)

* Update yarn PnP tests and disable swc file reading for PnP

* update job

* Update test

* add env variable

* update destory

* test one

* bump timeout

* update pnp install command

* only run pnp test

* add more logs

* handle exit signal

* dont inherit stdio for install

* update server start

* re-add test type

* add build log

* additional logging

* update build command

* remove separate timeout

* update install command

* install separate for better time info

* add cache pre-warming

* update yarn config

* enable other pnp tests

* Separate out tests

* fix-lint

* update path

* update test concurrency for isolated tests

* update retries

* Revert "update test concurrency for isolated tests"

This reverts commit 3a6e924df8ec61d55d3ee8a58d24cd50f0141195.

* re-enable production tests

* apply suggestions
parent 7f6afa4a
...@@ -347,35 +347,6 @@ jobs: ...@@ -347,35 +347,6 @@ jobs:
- run: xvfb-run node run-tests.js test/integration/with-electron/test/index.test.js - run: xvfb-run node run-tests.js test/integration/with-electron/test/index.test.js
if: ${{needs.build.outputs.docsChange != 'docs only change'}} if: ${{needs.build.outputs.docsChange != 'docs only change'}}
testYarnPnP:
runs-on: ubuntu-latest
needs: [build, build-native-dev]
env:
NODE_OPTIONS: '--unhandled-rejections=strict'
YARN_COMPRESSION_LEVEL: '0'
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }}
with:
node-version: 14
- uses: actions/cache@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}
- uses: actions/download-artifact@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
name: next-swc-dev-binary
path: packages/next-swc/native
- run: bash ./scripts/test-pnp.sh
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
testsPass: testsPass:
name: thank you, next name: thank you, next
runs-on: ubuntu-latest runs-on: ubuntu-latest
...@@ -387,7 +358,6 @@ jobs: ...@@ -387,7 +358,6 @@ jobs:
checkPrecompiled, checkPrecompiled,
testIntegration, testIntegration,
testUnit, testUnit,
testYarnPnP,
testDev, testDev,
testProd, testProd,
] ]
......
...@@ -101,6 +101,8 @@ export function pitch() { ...@@ -101,6 +101,8 @@ export function pitch() {
;(async () => { ;(async () => {
let loaderOptions = this.getOptions() || {} let loaderOptions = this.getOptions() || {}
if ( if (
// TODO: investigate swc file reading in PnP mode?
!process.versions.pnp &&
loaderOptions.fileReading && loaderOptions.fileReading &&
!EXCLUDED_PATHS.test(this.resourcePath) && !EXCLUDED_PATHS.test(this.resourcePath) &&
this.loaders.length - 1 === this.loaderIndex && this.loaders.length - 1 === this.loaderIndex &&
......
...@@ -36,6 +36,7 @@ const cleanUpAndExit = async (code) => { ...@@ -36,6 +36,7 @@ const cleanUpAndExit = async (code) => {
if (process.env.NEXT_TEST_STARTER) { if (process.env.NEXT_TEST_STARTER) {
await fs.remove(process.env.NEXT_TEST_STARTER) await fs.remove(process.env.NEXT_TEST_STARTER)
} }
console.log(`exiting with code ${code}`)
process.exit(code) process.exit(code)
} }
......
declare -a testCases=(
# Tests the webpack require hook
"progressive-web-app"
"with-eslint"
"with-typescript"
"with-next-sass"
# Tests @next/mdx
"with-mdx"
# Tests babel config
"with-styled-components"
)
set -e
set -x
# Speeds up testing locally
export CI=1
rm -rf ./e2e-tests
initialDir=$(pwd)
for testCase in "${testCases[@]}"
do
cd $initialDir
echo "--- Testing $testCase ---"
mkdir -p "./e2e-tests/$testCase"
cp -r "./examples/$testCase/." "./e2e-tests/$testCase"
cd "./e2e-tests/$testCase"
# TODO: remove after able to load bindings with YarnPnP
echo '{"presets": ["next/babel"]}' > .babelrc
touch yarn.lock
yarn set version berry
yarn config set pnpFallbackMode none
yarn config set enableGlobalCache true
yarn link --all --private -r ../..
yarn build --no-lint
done
import { runTests } from './utils'
describe('yarn PnP', () => {
runTests('progressive-web-app')
})
import fs from 'fs-extra'
import { join } from 'path'
import { fetchViaHTTP } from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
jest.setTimeout(2 * 60 * 1000)
export function runTests(example = '') {
let next: NextInstance
beforeAll(async () => {
const srcDir = join(__dirname, '../../../../examples', example)
const srcFiles = await fs.readdir(srcDir)
const packageJson = await fs.readJson(join(srcDir, 'package.json'))
next = await createNext({
files: srcFiles.reduce((prev, file) => {
if (file !== 'package.json') {
prev[file] = new FileRef(join(srcDir, file))
}
return prev
}, {} as { [key: string]: FileRef }),
dependencies: {
...packageJson.dependencies,
...packageJson.devDependencies,
},
installCommand: ({ dependencies }) => {
const pkgs = Object.keys(dependencies).reduce((prev, cur) => {
prev.push(`${cur}@${dependencies[cur]}`)
return prev
}, [] as string[])
return `yarn set version berry && yarn config set enableGlobalCache true && yarn config set compressionLevel 0 && yarn add ${pkgs.join(
' '
)}`
},
buildCommand: `yarn next build --no-lint`,
startCommand: (global as any).isNextDev ? `yarn next` : `yarn next start`,
})
})
afterAll(() => next?.destroy())
it(`should compile and serve the index page correctly ${example}`, async () => {
const res = await fetchViaHTTP(next.url, '/')
expect(res.status).toBe(200)
expect(await res.text()).toContain('<html')
})
}
import { runTests } from './utils'
describe('yarn PnP', () => {
runTests('with-eslint')
})
import { runTests } from './utils'
describe('yarn PnP', () => {
runTests('with-mdx')
})
import { runTests } from './utils'
describe('yarn PnP', () => {
runTests('with-next-sass')
})
import { runTests } from './utils'
describe('yarn PnP', () => {
runTests('with-styled-components')
})
import { runTests } from './utils'
describe('yarn PnP', () => {
runTests('with-typescript')
})
...@@ -2,10 +2,11 @@ const os = require('os') ...@@ -2,10 +2,11 @@ const os = require('os')
const path = require('path') const path = require('path')
const execa = require('execa') const execa = require('execa')
const fs = require('fs-extra') const fs = require('fs-extra')
const childProcess = require('child_process')
const { linkPackages } = const { linkPackages } =
require('../../.github/actions/next-stats-action/src/prepare/repo-setup')() require('../../.github/actions/next-stats-action/src/prepare/repo-setup')()
async function createNextInstall(dependencies) { async function createNextInstall(dependencies, installCommand) {
const tmpDir = await fs.realpath(process.env.NEXT_TEST_DIR || os.tmpdir()) const tmpDir = await fs.realpath(process.env.NEXT_TEST_DIR || os.tmpdir())
const origRepoDir = path.join(__dirname, '../../') const origRepoDir = path.join(__dirname, '../../')
const installDir = path.join(tmpDir, `next-install-${Date.now()}`) const installDir = path.join(tmpDir, `next-install-${Date.now()}`)
...@@ -45,22 +46,37 @@ async function createNextInstall(dependencies) { ...@@ -45,22 +46,37 @@ async function createNextInstall(dependencies) {
} }
const pkgPaths = await linkPackages(tmpRepoDir) const pkgPaths = await linkPackages(tmpRepoDir)
const combinedDependencies = {
...dependencies,
next: pkgPaths.get('next'),
}
await fs.ensureDir(installDir) await fs.ensureDir(installDir)
await fs.writeFile( await fs.writeFile(
path.join(installDir, 'package.json'), path.join(installDir, 'package.json'),
JSON.stringify( JSON.stringify(
{ {
dependencies: { dependencies: combinedDependencies,
...dependencies,
next: pkgPaths.get('next'),
},
private: true, private: true,
}, },
null, null,
2 2
) )
) )
if (installCommand) {
const installString =
typeof installCommand === 'function'
? installCommand({ dependencies: combinedDependencies })
: installCommand
console.log('running install command', installString)
childProcess.execSync(installString, {
cwd: installDir,
stdio: ['ignore', 'inherit', 'inherit'],
})
} else {
await execa('yarn', ['install'], { await execa('yarn', ['install'], {
cwd: installDir, cwd: installDir,
stdio: ['ignore', 'inherit', 'inherit'], stdio: ['ignore', 'inherit', 'inherit'],
...@@ -69,6 +85,7 @@ async function createNextInstall(dependencies) { ...@@ -69,6 +85,7 @@ async function createNextInstall(dependencies) {
YARN_CACHE_FOLDER: path.join(installDir, '.yarn-cache'), YARN_CACHE_FOLDER: path.join(installDir, '.yarn-cache'),
}, },
}) })
}
await fs.remove(tmpRepoDir) await fs.remove(tmpRepoDir)
return installDir return installDir
......
import path from 'path' import path from 'path'
import assert from 'assert' import assert from 'assert'
import { NextConfig } from 'next' import { NextConfig } from 'next'
import { NextInstance } from './next-modes/base' import { InstallCommand, NextInstance } from './next-modes/base'
import { NextDevInstance } from './next-modes/next-dev' import { NextDevInstance } from './next-modes/next-dev'
import { NextStartInstance } from './next-modes/next-start' import { NextStartInstance } from './next-modes/next-start'
const testFile = module.parent.filename
const testsFolder = path.join(__dirname, '..') const testsFolder = path.join(__dirname, '..')
let testFile
const testFileRegex = /\.test\.(js|tsx?)/
const visitedModules = new Set()
const checkParent = (mod) => {
if (!mod?.parent || visitedModules.has(mod)) return
testFile = mod.parent.filename || ''
visitedModules.add(mod)
if (!testFileRegex.test(testFile)) {
checkParent(mod.parent)
}
}
checkParent(module)
process.env.TEST_FILE_PATH = testFile process.env.TEST_FILE_PATH = testFile
let testMode = process.env.NEXT_TEST_MODE let testMode = process.env.NEXT_TEST_MODE
if (!testFile.match(/\.test\.(js|tsx?)/)) { if (!testFileRegex.test(testFile)) {
throw new Error( throw new Error(
'e2e-utils imported from non-test file (must end with .test.(js,ts,tsx)' `e2e-utils imported from non-test file ${testFile} (must end with .test.(js,ts,tsx)`
) )
} }
...@@ -97,6 +111,9 @@ export async function createNext(opts: { ...@@ -97,6 +111,9 @@ export async function createNext(opts: {
} }
nextConfig?: NextConfig nextConfig?: NextConfig
skipStart?: boolean skipStart?: boolean
installCommand?: InstallCommand
buildCommand?: string
startCommand?: string
}): Promise<NextInstance> { }): Promise<NextInstance> {
try { try {
if (nextInstance) { if (nextInstance) {
......
...@@ -8,12 +8,18 @@ import { ChildProcess } from 'child_process' ...@@ -8,12 +8,18 @@ import { ChildProcess } from 'child_process'
import { createNextInstall } from '../create-next-install' import { createNextInstall } from '../create-next-install'
type Event = 'stdout' | 'stderr' | 'error' | 'destroy' type Event = 'stdout' | 'stderr' | 'error' | 'destroy'
export type InstallCommand =
| string
| ((ctx: { dependencies: { [key: string]: string } }) => string)
export class NextInstance { export class NextInstance {
protected files: { protected files: {
[filename: string]: string | FileRef [filename: string]: string | FileRef
} }
protected nextConfig?: NextConfig protected nextConfig?: NextConfig
protected installCommand?: InstallCommand
protected buildCommand?: string
protected startCommand?: string
protected dependencies?: { [name: string]: string } protected dependencies?: { [name: string]: string }
protected events: { [eventName: string]: Set<any> } protected events: { [eventName: string]: Set<any> }
public testDir: string public testDir: string
...@@ -27,6 +33,9 @@ export class NextInstance { ...@@ -27,6 +33,9 @@ export class NextInstance {
files, files,
dependencies, dependencies,
nextConfig, nextConfig,
installCommand,
buildCommand,
startCommand,
}: { }: {
files: { files: {
[filename: string]: string | FileRef [filename: string]: string | FileRef
...@@ -35,10 +44,16 @@ export class NextInstance { ...@@ -35,10 +44,16 @@ export class NextInstance {
[name: string]: string [name: string]: string
} }
nextConfig?: NextConfig nextConfig?: NextConfig
installCommand?: InstallCommand
buildCommand?: string
startCommand?: string
}) { }) {
this.files = files this.files = files
this.dependencies = dependencies this.dependencies = dependencies
this.nextConfig = nextConfig this.nextConfig = nextConfig
this.installCommand = installCommand
this.buildCommand = buildCommand
this.startCommand = startCommand
this.events = {} this.events = {}
this.isDestroyed = false this.isDestroyed = false
this.isStopping = false this.isStopping = false
...@@ -59,15 +74,23 @@ export class NextInstance { ...@@ -59,15 +74,23 @@ export class NextInstance {
`next-test-${Date.now()}-${(Math.random() * 1000) | 0}` `next-test-${Date.now()}-${(Math.random() * 1000) | 0}`
) )
if (process.env.NEXT_TEST_STARTER && !this.dependencies) { if (
process.env.NEXT_TEST_STARTER &&
!this.dependencies &&
!this.installCommand
) {
await fs.copy(process.env.NEXT_TEST_STARTER, this.testDir) await fs.copy(process.env.NEXT_TEST_STARTER, this.testDir)
} else if (!skipIsolatedNext) { } else if (!skipIsolatedNext) {
this.testDir = await createNextInstall({ this.testDir = await createNextInstall(
{
react: 'latest', react: 'latest',
'react-dom': 'latest', 'react-dom': 'latest',
...this.dependencies, ...this.dependencies,
}) },
this.installCommand
)
} }
console.log('created next.js install, writing test files')
for (const filename of Object.keys(this.files)) { for (const filename of Object.keys(this.files)) {
const item = this.files[filename] const item = this.files[filename]
...@@ -182,6 +205,7 @@ export class NextInstance { ...@@ -182,6 +205,7 @@ export class NextInstance {
if (!process.env.NEXT_TEST_SKIP_CLEANUP) { if (!process.env.NEXT_TEST_SKIP_CLEANUP) {
await fs.remove(this.testDir) await fs.remove(this.testDir)
} }
console.log(`destroyed next instance`)
} }
public get url() { public get url() {
......
import path from 'path'
import resolveFrom from 'resolve-from'
import { spawn } from 'child_process' import { spawn } from 'child_process'
import { NextInstance } from './base' import { NextInstance } from './base'
...@@ -22,11 +20,14 @@ export class NextDevInstance extends NextInstance { ...@@ -22,11 +20,14 @@ export class NextDevInstance extends NextInstance {
if (this.childProcess) { if (this.childProcess) {
throw new Error('next already started') throw new Error('next already started')
} }
// we don't use yarn next here as yarn detaches itself from the let startArgs = ['yarn', 'next']
// child process making it harder to kill all processes
const nextDir = path.dirname(resolveFrom(this.testDir, 'next/package.json'))
this.childProcess = spawn('node', [path.join(nextDir, '/dist/bin/next')], { if (this.startCommand) {
startArgs = this.startCommand.split(' ')
}
await new Promise<void>((resolve) => {
this.childProcess = spawn(startArgs[0], startArgs.slice(1), {
cwd: this.testDir, cwd: this.testDir,
stdio: ['ignore', 'pipe', 'pipe'], stdio: ['ignore', 'pipe', 'pipe'],
shell: false, shell: false,
...@@ -52,14 +53,14 @@ export class NextDevInstance extends NextInstance { ...@@ -52,14 +53,14 @@ export class NextDevInstance extends NextInstance {
this.emit('stderr', [msg]) this.emit('stderr', [msg])
}) })
this.childProcess.on('close', (code) => { this.childProcess.on('close', (code, signal) => {
if (this.isStopping) return if (this.isStopping) return
if (code) { if (code || signal) {
throw new Error(`next dev exited unexpectedly with code ${code}`) throw new Error(
`next dev exited unexpectedly with code/signal ${code || signal}`
)
} }
}) })
await new Promise<void>((resolve) => {
const readyCb = (msg) => { const readyCb = (msg) => {
if (msg.includes('started server on') && msg.includes('url:')) { if (msg.includes('started server on') && msg.includes('url:')) {
this._url = msg.split('url: ').pop().trim() this._url = msg.split('url: ').pop().trim()
......
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import resolveFrom from 'resolve-from'
import { spawn, SpawnOptions } from 'child_process'
import { NextInstance } from './base' import { NextInstance } from './base'
import { spawn, SpawnOptions } from 'child_process'
export class NextStartInstance extends NextInstance { export class NextStartInstance extends NextInstance {
private _buildId: string private _buildId: string
...@@ -49,21 +48,29 @@ export class NextStartInstance extends NextInstance { ...@@ -49,21 +48,29 @@ export class NextStartInstance extends NextInstance {
this.emit('stderr', [msg]) this.emit('stderr', [msg])
}) })
} }
const nextDir = path.dirname(resolveFrom(this.testDir, 'next/package.json')) let buildArgs = ['yarn', 'next', 'build']
let startArgs = ['yarn', 'next', 'start']
this.childProcess = spawn( if (this.buildCommand) {
'node', buildArgs = this.buildCommand.split(' ')
[path.join(nextDir, '/dist/bin/next'), 'build'], }
spawnOpts if (this.startCommand) {
) startArgs = this.startCommand.split(' ')
handleStdio() }
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
this.childProcess.on('exit', (code) => { console.log('running', buildArgs.join(' '))
if (code) reject(new Error(`next build failed with code ${code}`)) this.childProcess = spawn(buildArgs[0], buildArgs.slice(1), spawnOpts)
handleStdio()
this.childProcess.on('exit', (code, signal) => {
if (code || signal)
reject(
new Error(`next build failed with code/signal ${code || signal}`)
)
else resolve() else resolve()
}) })
}) })
this._buildId = ( this._buildId = (
await fs.readFile( await fs.readFile(
path.join( path.join(
...@@ -74,23 +81,22 @@ export class NextStartInstance extends NextInstance { ...@@ -74,23 +81,22 @@ export class NextStartInstance extends NextInstance {
'utf8' 'utf8'
) )
).trim() ).trim()
// we don't use yarn next here as yarn detaches itself from the
// child process making it harder to kill all processes console.log('running', startArgs.join(' '))
this.childProcess = spawn(
'node', await new Promise<void>((resolve) => {
[path.join(nextDir, '/dist/bin/next'), 'start'], this.childProcess = spawn(startArgs[0], startArgs.slice(1), spawnOpts)
spawnOpts
)
handleStdio() handleStdio()
this.childProcess.on('close', (code) => { this.childProcess.on('close', (code, signal) => {
if (this.isStopping) return if (this.isStopping) return
if (code) { if (code || signal) {
throw new Error(`next start exited unexpectedly with code ${code}`) throw new Error(
`next start exited unexpectedly with code/signal ${code || signal}`
)
} }
}) })
await new Promise<void>((resolve) => {
const readyCb = (msg) => { const readyCb = (msg) => {
if (msg.includes('started server on') && msg.includes('url:')) { if (msg.includes('started server on') && msg.includes('url:')) {
this._url = msg.split('url: ').pop().trim() this._url = msg.split('url: ').pop().trim()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment