Skip to content

Commit

Permalink
Fix output: standalone test for app directory (#43618)
Browse files Browse the repository at this point in the history
This test was ensuring `app` directory is working correctly with
`output: 'standalone'`. Instead of removing config we should
conditionally set it for the test.

Reverts #43607

x-ref:
https://github.com/vercel/next.js/actions/runs/3594732606/jobs/6055832699
x-ref:
https://github.com/vercel/next.js/actions/runs/3594732606/jobs/6055832421
  • Loading branch information
ijjk committed Dec 2, 2022
1 parent 70d89bc commit 0590988
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 46 deletions.
1 change: 0 additions & 1 deletion test/e2e/app-dir/app/next.config.js
Expand Up @@ -5,7 +5,6 @@ module.exports = {
algorithm: 'sha256',
},
},
// TODO: (wyattjoh) enable once we've resolved issues with app directory and standalone output mode
// output: 'standalone',
rewrites: async () => {
return {
Expand Down
45 changes: 0 additions & 45 deletions test/e2e/app-dir/index.test.ts
@@ -1,22 +1,17 @@
import os from 'os'
import { createNext, FileRef } from 'e2e-utils'
import crypto from 'crypto'
import { NextInstance } from 'test/lib/next-modes/base'
import {
check,
fetchViaHTTP,
findPort,
getRedboxHeader,
initNextServerScript,
killApp,
renderViaHTTP,
waitFor,
waitForAndOpenRuntimeError,
} from 'next-test-utils'
import path from 'path'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
import fs from 'fs-extra'

describe('app dir', () => {
const isDev = (global as any).isNextDev
Expand Down Expand Up @@ -2554,44 +2549,4 @@ describe('app dir', () => {
}

runTests()

if ((global as any).isNextStart) {
it('should work correctly with output standalone', async () => {
const tmpFolder = path.join(os.tmpdir(), 'next-standalone-' + Date.now())
await fs.move(path.join(next.testDir, '.next/standalone'), tmpFolder)
let server

try {
const testServer = path.join(tmpFolder, 'server.js')
const appPort = await findPort()
server = await initNextServerScript(
testServer,
/Listening on/,
{
...process.env,
PORT: appPort,
},
undefined,
{
cwd: tmpFolder,
}
)

for (const testPath of [
'/',
'/api/hello',
'/blog/first',
'/dashboard',
'/dashboard/deployments/123',
'/catch-all/first',
]) {
const res = await fetchViaHTTP(appPort, testPath)
expect(res.status).toBe(200)
}
} finally {
if (server) await killApp(server)
await fs.remove(tmpFolder)
}
})
}
})
80 changes: 80 additions & 0 deletions test/e2e/app-dir/standalone.test.ts
@@ -0,0 +1,80 @@
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
import {
fetchViaHTTP,
findPort,
initNextServerScript,
killApp,
} from 'next-test-utils'

describe('output: standalone with app dir', () => {
let next: NextInstance

if (!(global as any).isNextStart) {
it('should skip for non-next start', () => {})
return
}

beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'app')),
dependencies: {
swr: '2.0.0-rc.0',
react: 'latest',
'react-dom': 'latest',
sass: 'latest',
},
skipStart: true,
})

await next.patchFile(
'next.config.js',
(await next.readFile('next.config.js')).replace('// output', 'output')
)
await next.start()
})
afterAll(async () => {
await next.destroy()
})

it('should work correctly with output standalone', async () => {
const tmpFolder = path.join(os.tmpdir(), 'next-standalone-' + Date.now())
await fs.move(path.join(next.testDir, '.next/standalone'), tmpFolder)
let server

try {
const testServer = path.join(tmpFolder, 'server.js')
const appPort = await findPort()
server = await initNextServerScript(
testServer,
/Listening on/,
{
...process.env,
PORT: appPort,
},
undefined,
{
cwd: tmpFolder,
}
)

for (const testPath of [
'/',
'/api/hello',
'/blog/first',
'/dashboard',
'/dashboard/deployments/123',
'/catch-all/first',
]) {
const res = await fetchViaHTTP(appPort, testPath)
expect(res.status).toBe(200)
}
} finally {
if (server) await killApp(server)
await fs.remove(tmpFolder)
}
})
})

0 comments on commit 0590988

Please sign in to comment.