Unverified Commit b508fef2 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Merge e2e test node_modules (#40926)

Merge e2e tests customized `node_modules` with installed `node_modules`,
to let you debug easily locally without moving folder between
`node_modules` and `node_modules_bak`

Also add `optoutServerComponentsBundle` to config schema.
parent c86a9b99
...@@ -240,6 +240,12 @@ const configSchema = { ...@@ -240,6 +240,12 @@ const configSchema = {
appDir: { appDir: {
type: 'boolean', type: 'boolean',
}, },
optoutServerComponentsBundle: {
items: {
type: 'string',
},
type: 'array',
},
browsersListForSwc: { browsersListForSwc: {
type: 'boolean', type: 'boolean',
}, },
......
...@@ -223,8 +223,10 @@ async function main() { ...@@ -223,8 +223,10 @@ async function main() {
console.log('Creating Next.js install for isolated tests') console.log('Creating Next.js install for isolated tests')
const reactVersion = process.env.NEXT_TEST_REACT_VERSION || 'latest' const reactVersion = process.env.NEXT_TEST_REACT_VERSION || 'latest'
const testStarter = await createNextInstall({ const testStarter = await createNextInstall({
react: reactVersion, dependencies: {
'react-dom': reactVersion, react: reactVersion,
'react-dom': reactVersion,
},
}) })
process.env.NEXT_TEST_STARTER = testStarter process.env.NEXT_TEST_STARTER = testStarter
} }
......
...@@ -38,15 +38,14 @@ describe('app dir - react server components', () => { ...@@ -38,15 +38,14 @@ describe('app dir - react server components', () => {
next = await createNext({ next = await createNext({
files: new FileRef(path.join(__dirname, './rsc-basic')), files: new FileRef(path.join(__dirname, './rsc-basic')),
dependencies: { dependencies: {
'styled-components': '6.0.0-alpha.5', 'styled-components': '6.0.0-beta.2',
react: 'experimental', react: 'experimental',
'react-dom': 'experimental', 'react-dom': 'experimental',
}, },
packageJson: { packageJson: {
scripts: { scripts: {
setup: `cp -r ./node_modules_bak/* ./node_modules`, build: 'next build',
build: 'yarn setup && next build', dev: 'next dev',
dev: 'yarn setup && next dev',
start: 'next start', start: 'next start',
}, },
}, },
......
...@@ -13,23 +13,25 @@ function runTest() { ...@@ -13,23 +13,25 @@ function runTest() {
beforeAll(async () => { beforeAll(async () => {
next = await createNext({ next = await createNext({
files: { files: {
node_modules_bak: new FileRef(path.join(appDir, 'node_modules_bak')), node_modules: new FileRef(path.join(appDir, 'node_modules')),
pages: new FileRef(path.join(appDir, 'pages')), pages: new FileRef(path.join(appDir, 'pages')),
'.npmrc': new FileRef(path.join(appDir, '.npmrc')), '.npmrc': new FileRef(path.join(appDir, '.npmrc')),
}, },
packageJson: { packageJson: {
scripts: { scripts: {
setup: `cp -r ./node_modules_bak/my-comps ./node_modules;`, build: 'next build',
build: `yarn setup && next build`, dev: 'next dev',
dev: `yarn setup && next dev`,
start: 'next start', start: 'next start',
}, },
}, },
dependencies: { dependencies: {
'styled-jsx': '5.0.0', // styled-jsx on user side // A different version of styled-jsx on user side,
// using a different patch version comparing to the one from next.js
'styled-jsx': '5.0.0',
}, },
startCommand: 'yarn ' + ((global as any).isNextDev ? 'dev' : 'start'), startCommand: 'yarn ' + ((global as any).isNextDev ? 'dev' : 'start'),
buildCommand: `yarn build`, buildCommand: 'yarn build',
installCommand: 'yarn',
}) })
}) })
afterAll(() => next.destroy()) afterAll(() => next.destroy())
......
...@@ -7,12 +7,12 @@ const { randomBytes } = require('crypto') ...@@ -7,12 +7,12 @@ const { randomBytes } = require('crypto')
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( async function createNextInstall({
dependencies, dependencies,
installCommand, installCommand,
packageJson = {}, packageJson = {},
packageLockPath = '' packageLockPath = '',
) { }) {
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( const installDir = path.join(
......
...@@ -143,16 +143,30 @@ export class NextInstance { ...@@ -143,16 +143,30 @@ export class NextInstance {
) { ) {
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({
finalDependencies, dependencies: finalDependencies,
this.installCommand, installCommand: this.installCommand,
this.packageJson, packageJson: this.packageJson,
this.packageLockPath packageLockPath: this.packageLockPath,
) })
} }
require('console').log('created next.js install, writing test files') require('console').log('created next.js install, writing test files')
} }
const tempNodeModulesFolder = 'node_modules_bak'
// Merge customized node_modules and installed node_modules.
// Move files[node_modules] to a temporary folder node_modules_back,
// then copy the modules back to node_modules after installation.
const tempNodeModulesPath = path.join(this.testDir, tempNodeModulesFolder)
const nodeModulesDir = path.join(this.testDir, 'node_modules')
const hasNodeModulesDir =
fs.existsSync(nodeModulesDir) &&
(await fs.stat(nodeModulesDir)).isDirectory()
if (hasNodeModulesDir) {
// Move node_modules to temp folder
await fs.move(nodeModulesDir, tempNodeModulesPath)
}
if (this.files instanceof FileRef) { if (this.files instanceof FileRef) {
// if a FileRef is passed directly to `files` we copy the // if a FileRef is passed directly to `files` we copy the
// entire folder to the test directory // entire folder to the test directory
...@@ -163,6 +177,7 @@ export class NextInstance { ...@@ -163,6 +177,7 @@ export class NextInstance {
`FileRef passed to "files" in "createNext" is not a directory ${this.files.fsPath}` `FileRef passed to "files" in "createNext" is not a directory ${this.files.fsPath}`
) )
} }
await fs.copy(this.files.fsPath, this.testDir) await fs.copy(this.files.fsPath, this.testDir)
} else { } else {
for (const filename of Object.keys(this.files)) { for (const filename of Object.keys(this.files)) {
...@@ -178,6 +193,12 @@ export class NextInstance { ...@@ -178,6 +193,12 @@ export class NextInstance {
} }
} }
if (hasNodeModulesDir) {
// Move node_modules from temp back to origin
await fs.copy(tempNodeModulesPath, nodeModulesDir)
await fs.remove(tempNodeModulesPath)
}
let nextConfigFile = Object.keys(this.files).find((file) => let nextConfigFile = Object.keys(this.files).find((file) =>
file.startsWith('next.config.') file.startsWith('next.config.')
) )
......
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