Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
test/integration/optional-chaining-nullish-coalescing/pages/nullish-coalescing.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
let hello | ||
let another = '' | ||
|
||
export default () => ( | ||
<> | ||
<p>result1: {hello ?? 'fallback'}</p> | ||
<p>result2: {another ?? 'fallback'}</p> | ||
</> | ||
) |
9 changes: 9 additions & 0 deletions
9
test/integration/optional-chaining-nullish-coalescing/pages/optional-chaining.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
</> | ||
) |
75 changes: 75 additions & 0 deletions
75
test/integration/optional-chaining-nullish-coalescing/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
}) |