Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix output: standalone test for app directory #43618

Merged
merged 4 commits into from Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}
})
})