/
index.test.ts
74 lines (66 loc) · 1.82 KB
/
index.test.ts
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
70
71
72
73
74
/* eslint-env jest */
import {
findPort,
killApp,
launchApp,
nextBuild,
nextStart,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
const appDir = join(__dirname, '../')
let appPort
let app
describe('Image Component Trailing Slash Tests', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
it('should include trailing slash when trailingSlash is set on config file during next dev', async () => {
expect.assertions(1)
let browser
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
} finally {
if (browser) {
await browser.close()
}
}
})
})
describe('server mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
it('should include trailing slash when trailingSlash is set on config file during next start', async () => {
expect.assertions(1)
let browser
try {
browser = await webdriver(appPort, '/')
const id = 'test1'
const srcImage = await browser.eval(
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
} finally {
if (browser) {
await browser.close()
}
}
})
})
})