/
index.test.ts
89 lines (83 loc) · 2.19 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* 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
function runTests(url: string) {
it('should work with loaderFile config', async () => {
const browser = await webdriver(appPort, url)
expect(await browser.elementById('img1').getAttribute('src')).toBe(
'/logo.png#w:828,q:50'
)
expect(await browser.elementById('img1').getAttribute('srcset')).toBe(
'/logo.png#w:640,q:50 1x, /logo.png#w:828,q:50 2x'
)
})
it('should work with loader prop', async () => {
const browser = await webdriver(appPort, url)
expect(await browser.elementById('img2').getAttribute('src')).toBe(
'/logo.png?wid=640&qual=35'
)
expect(await browser.elementById('img2').getAttribute('srcset')).toBe(
'/logo.png?wid=256&qual=35 1x, /logo.png?wid=640&qual=35 2x'
)
})
}
describe('Image Loader Config new', () => {
describe('development mode - component', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => {
killApp(app)
})
runTests('/')
})
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode - component',
() => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => {
killApp(app)
})
runTests('/')
}
)
describe('development mode - getImageProps', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => {
killApp(app)
})
runTests('/get-img-props')
})
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode - getImageProps',
() => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => {
killApp(app)
})
runTests('/get-img-props')
}
)
})