/
index.test.js
69 lines (57 loc) · 1.72 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* eslint-env jest */
import { join } from 'path'
import webdriver, { USE_SELENIUM } from 'next-webdriver'
import {
findPort,
killApp,
launchApp,
nextBuild,
nextStart,
} from 'next-test-utils'
jest.setTimeout(1000 * 60 * 2)
const context = {}
context.appDir = join(__dirname, '../')
const itif = (condition) => (condition ? it : it.skip)
describe('Middleware base tests', () => {
describe('dev mode', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.app = await launchApp(context.appDir, context.appPort)
})
afterAll(() => killApp(context.app))
runTests()
})
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(context.appDir, undefined, {
stderr: true,
stdout: true,
})
context.appPort = await findPort()
context.app = await nextStart(context.appDir, context.appPort)
})
afterAll(() => killApp(context.app))
runTests()
})
})
function runTests() {
itif(!USE_SELENIUM)(
`should send preflight for specified locale`,
async () => {
const browser = await webdriver(context.appPort, '/', {
locale: 'en-US,en',
})
await browser.waitForElementByCss('.en')
await browser.elementByCss('#link-ja').click()
await browser.waitForElementByCss('.ja')
await browser.elementByCss('#link-en').click()
await browser.waitForElementByCss('.en')
await browser.elementByCss('#link-fr').click()
await browser.waitForElementByCss('.fr')
await browser.elementByCss('#link-ja2').click()
await browser.waitForElementByCss('.ja')
await browser.elementByCss('#link-en2').click()
await browser.waitForElementByCss('.en')
}
)
}