Skip to content

Commit

Permalink
Merge e2e test node_modules
Browse files Browse the repository at this point in the history
move

moving node_modules dir

simplify

simplify
  • Loading branch information
huozhi committed Sep 27, 2022
1 parent c86a9b9 commit 1354951
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 21 deletions.
6 changes: 6 additions & 0 deletions packages/next/server/config-schema.ts
Expand Up @@ -240,6 +240,12 @@ const configSchema = {
appDir: {
type: 'boolean',
},
optoutServerComponentsBundle: {
items: {
type: 'string',
},
type: 'array',
},
browsersListForSwc: {
type: 'boolean',
},
Expand Down
6 changes: 4 additions & 2 deletions run-tests.js
Expand Up @@ -223,8 +223,10 @@ async function main() {
console.log('Creating Next.js install for isolated tests')
const reactVersion = process.env.NEXT_TEST_REACT_VERSION || 'latest'
const testStarter = await createNextInstall({
react: reactVersion,
'react-dom': reactVersion,
dependencies: {
react: reactVersion,
'react-dom': reactVersion,
},
})
process.env.NEXT_TEST_STARTER = testStarter
}
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/app-dir/rsc-basic.test.ts
Expand Up @@ -38,15 +38,14 @@ describe('app dir - react server components', () => {
next = await createNext({
files: new FileRef(path.join(__dirname, './rsc-basic')),
dependencies: {
'styled-components': '6.0.0-alpha.5',
'styled-components': '6.0.0-beta.2',
react: 'experimental',
'react-dom': 'experimental',
},
packageJson: {
scripts: {
setup: `cp -r ./node_modules_bak/* ./node_modules`,
build: 'yarn setup && next build',
dev: 'yarn setup && next dev',
build: 'next build',
dev: 'next dev',
start: 'next start',
},
},
Expand Down
14 changes: 8 additions & 6 deletions test/e2e/styled-jsx/index.test.ts
Expand Up @@ -13,23 +13,25 @@ function runTest() {
beforeAll(async () => {
next = await createNext({
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')),
'.npmrc': new FileRef(path.join(appDir, '.npmrc')),
},
packageJson: {
scripts: {
setup: `cp -r ./node_modules_bak/my-comps ./node_modules;`,
build: `yarn setup && next build`,
dev: `yarn setup && next dev`,
build: 'next build',
dev: 'next dev',
start: 'next start',
},
},
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'),
buildCommand: `yarn build`,
buildCommand: 'yarn build',
installCommand: 'yarn',
})
})
afterAll(() => next.destroy())
Expand Down
6 changes: 3 additions & 3 deletions test/lib/create-next-install.js
Expand Up @@ -7,12 +7,12 @@ const { randomBytes } = require('crypto')
const { linkPackages } =
require('../../.github/actions/next-stats-action/src/prepare/repo-setup')()

async function createNextInstall(
async function createNextInstall({
dependencies,
installCommand,
packageJson = {},
packageLockPath = ''
) {
packageLockPath = '',
}) {
const tmpDir = await fs.realpath(process.env.NEXT_TEST_DIR || os.tmpdir())
const origRepoDir = path.join(__dirname, '../../')
const installDir = path.join(
Expand Down
32 changes: 26 additions & 6 deletions test/lib/next-modes/base.ts
Expand Up @@ -143,16 +143,29 @@ export class NextInstance {
) {
await fs.copy(process.env.NEXT_TEST_STARTER, this.testDir)
} else if (!skipIsolatedNext) {
this.testDir = await createNextInstall(
finalDependencies,
this.installCommand,
this.packageJson,
this.packageLockPath
)
this.testDir = await createNextInstall({
dependencies: finalDependencies,
installCommand: this.installCommand,
packageJson: this.packageJson,
packageLockPath: this.packageLockPath,
})
}
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 nodeModulesStats = await fs.stat(nodeModulesDir)
const hasNodeModulesDir = nodeModulesStats.isDirectory()
if (hasNodeModulesDir) {
// Move node_modules to temp folder
await fs.move(nodeModulesDir, tempNodeModulesPath)
}

if (this.files instanceof FileRef) {
// if a FileRef is passed directly to `files` we copy the
// entire folder to the test directory
Expand All @@ -163,6 +176,7 @@ export class NextInstance {
`FileRef passed to "files" in "createNext" is not a directory ${this.files.fsPath}`
)
}

await fs.copy(this.files.fsPath, this.testDir)
} else {
for (const filename of Object.keys(this.files)) {
Expand All @@ -178,6 +192,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) =>
file.startsWith('next.config.')
)
Expand Down

0 comments on commit 1354951

Please sign in to comment.