Skip to content

Commit

Permalink
Revert "Merge e2e test node_modules (#40926)" (#40974)
Browse files Browse the repository at this point in the history
This reverts commit b508fef.

Fixes: https://github.com/vercel/next.js/actions/runs/3139454323/jobs/5100342131

We aren't able to modify the filesystem for E2E deployments so this reverts the change introduced in the above PR to ensure deployment tests are able to run correctly with custom `node_modules`.
  • Loading branch information
ijjk authored Sep 28, 2022
1 parent 91f0a7c commit 070239e
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 51 deletions.
12 changes: 6 additions & 6 deletions packages/next/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@ const configSchema = {
appDir: {
type: 'boolean',
},
optoutServerComponentsBundle: {
items: {
type: 'string',
},
type: 'array',
},
browsersListForSwc: {
type: 'boolean',
},
Expand Down Expand Up @@ -326,6 +320,12 @@ const configSchema = {
optimisticClientCache: {
type: 'boolean',
},
optoutServerComponentsBundle: {
items: {
type: 'string',
},
type: 'array',
},
outputFileTracingRoot: {
minLength: 1,
type: 'string',
Expand Down
6 changes: 2 additions & 4 deletions run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,8 @@ 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({
dependencies: {
react: reactVersion,
'react-dom': reactVersion,
},
react: reactVersion,
'react-dom': reactVersion,
})
process.env.NEXT_TEST_STARTER = testStarter
}
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/app-dir/rsc-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ describe('app dir - react server components', () => {
next = await createNext({
files: new FileRef(path.join(__dirname, './rsc-basic')),
dependencies: {
'styled-components': '6.0.0-beta.2',
'styled-components': '6.0.0-alpha.5',
react: 'experimental',
'react-dom': 'experimental',
},
packageJson: {
scripts: {
build: 'next build',
dev: 'next dev',
setup: `cp -r ./node_modules_bak/* ./node_modules`,
build: 'yarn setup && next build',
dev: 'yarn setup && next dev',
start: 'next start',
},
},
Expand Down
14 changes: 6 additions & 8 deletions test/e2e/styled-jsx/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,23 @@ function runTest() {
beforeAll(async () => {
next = await createNext({
files: {
node_modules: new FileRef(path.join(appDir, 'node_modules')),
node_modules_bak: new FileRef(path.join(appDir, 'node_modules_bak')),
pages: new FileRef(path.join(appDir, 'pages')),
'.npmrc': new FileRef(path.join(appDir, '.npmrc')),
},
packageJson: {
scripts: {
build: 'next build',
dev: 'next dev',
setup: `cp -r ./node_modules_bak/my-comps ./node_modules;`,
build: `yarn setup && next build`,
dev: `yarn setup && next dev`,
start: 'next start',
},
},
dependencies: {
// 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',
'styled-jsx': '5.0.0', // styled-jsx on user side
},
startCommand: 'yarn ' + ((global as any).isNextDev ? 'dev' : 'start'),
buildCommand: 'yarn build',
installCommand: 'yarn',
buildCommand: `yarn build`,
})
})
afterAll(() => next.destroy())
Expand Down
6 changes: 3 additions & 3 deletions test/lib/create-next-install.js
Original file line number Diff line number Diff line change
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
33 changes: 6 additions & 27 deletions test/lib/next-modes/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,16 @@ export class NextInstance {
) {
await fs.copy(process.env.NEXT_TEST_STARTER, this.testDir)
} else if (!skipIsolatedNext) {
this.testDir = await createNextInstall({
dependencies: finalDependencies,
installCommand: this.installCommand,
packageJson: this.packageJson,
packageLockPath: this.packageLockPath,
})
this.testDir = await createNextInstall(
finalDependencies,
this.installCommand,
this.packageJson,
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 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 a FileRef is passed directly to `files` we copy the
// entire folder to the test directory
Expand All @@ -177,7 +163,6 @@ 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 @@ -193,12 +178,6 @@ 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 070239e

Please sign in to comment.