Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Dec 8, 2019
1 parent e57c73d commit 7be587a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
@@ -0,0 +1,9 @@
let hello
let another = ''

export default () => (
<>
<p>result1: {hello ?? 'fallback'}</p>
<p>result2: {another ?? 'fallback'}</p>
</>
)
@@ -0,0 +1,9 @@
let hello
let another = { thing: 1 }

export default () => (
<>
<p>result1: {hello?.world ? 'something' : 'nothing'}</p>
<p>result2: {another?.thing ? 'something' : 'nothing'}</p>
</>
)
@@ -0,0 +1,75 @@
/* 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()
})
})

0 comments on commit 7be587a

Please sign in to comment.