76 lines
1.7 KiB
JavaScript
76 lines
1.7 KiB
JavaScript
|
/* eslint-env jest */
|
||
|
/* global jasmine */
|
||
|
import fs from 'fs-extra'
|
||
|
import { join } from 'path'
|
||
|
import {
|
||
|
renderViaHTTP,
|
||
|
launchApp,
|
||
|
nextBuild,
|
||
|
nextStart,
|
||
|
killApp,
|
||
|
findPort,
|
||
|
} from 'next-test-utils'
|
||
|
|
||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
|
||
|
|
||
|
const appDir = join(__dirname, '..')
|
||
|
const nextConfig = join(appDir, 'next.config.js')
|
||
|
let appPort
|
||
|
let app
|
||
|
|
||
|
const runTests = () => {
|
||
|
it('should support optional chaining', async () => {
|
||
|
const html = await renderViaHTTP(appPort, '/optional-chaining')
|
||
|
expect(html).toMatch(/result1:.*?nothing/)
|
||
|
expect(html).toMatch(/result2:.*?something/)
|
||
|
})
|
||
|
|
||
|
it('should support nullish coalescing', async () => {
|
||
|
const html = await renderViaHTTP(appPort, '/nullish-coalescing')
|
||
|
expect(html).toMatch(/result1:.*?fallback/)
|
||
|
expect(html).not.toMatch(/result2:.*?fallback/)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
describe('Optional chaining and nullish coalescing support', () => {
|
||
|
describe('dev mode', () => {
|
||
|
beforeAll(async () => {
|
||
|
appPort = await findPort()
|
||
|
app = await launchApp(appDir, appPort)
|
||
|
})
|
||
|
afterAll(() => killApp(app))
|
||
|
|
||
|
runTests()
|
||
|
})
|
||
|
|
||
|
describe('server mode', () => {
|
||
|
beforeAll(async () => {
|
||
|
await fs.remove(nextConfig)
|
||
|
await nextBuild(appDir)
|
||
|
appPort = await findPort()
|
||
|
app = await nextStart(appDir, appPort)
|
||
|
})
|
||
|
afterAll(() => killApp(app))
|
||
|
|
||
|
runTests()
|
||
|
})
|
||
|
|
||
|
describe('serverless mode', () => {
|
||
|
beforeAll(async () => {
|
||
|
await fs.writeFile(
|
||
|
nextConfig,
|
||
|
`module.exports = { target: 'serverless' }`
|
||
|
)
|
||
|
await nextBuild(appDir)
|
||
|
appPort = await findPort()
|
||
|
app = await nextStart(appDir, appPort)
|
||
|
})
|
||
|
afterAll(async () => {
|
||
|
await killApp(app)
|
||
|
await fs.remove(nextConfig)
|
||
|
})
|
||
|
|
||
|
runTests()
|
||
|
})
|
||
|
})
|