/
index.test.ts
90 lines (83 loc) · 2.33 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
90
/* eslint-env jest */
import { join } from 'path'
import {
findPort,
getRedboxHeader,
getRedboxSource,
hasRedbox,
killApp,
launchApp,
nextBuild,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import stripAnsi from 'strip-ansi'
const appDir = join(__dirname, '../')
let appPort: number
let app
let stderr = ''
function runTests({ isDev }) {
it('should show error', async () => {
if (isDev) {
const browser = await webdriver(appPort, '/')
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toMatch('Failed to compile')
const source = await getRedboxSource(browser)
if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(`
"./test/integration/next-image-new/invalid-image-import/public/invalid.svg
Processing image failed
Failed to parse svg source code for image dimensions
Caused by:
- Source code does not contain a <svg> root element"
`)
} else {
expect(source).toMatchInlineSnapshot(`
"./pages/index.js:3
Error: Image import "../public/invalid.svg" is not a valid image file. The image may be corrupted or an unsupported format."
`)
}
} else {
expect(stripAnsi(stderr)).toContain(
'Error: Image import "../public/invalid.svg" is not a valid image file. The image may be corrupted or an unsupported format.'
)
}
})
}
describe('Missing Import Image Tests', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
stderr = ''
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
})
afterAll(async () => {
if (app) {
await killApp(app)
}
})
runTests({ isDev: true })
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
beforeAll(async () => {
stderr = ''
const result = await nextBuild(appDir, [], { stderr: true })
stderr = result.stderr
})
afterAll(async () => {
if (app) {
await killApp(app)
}
})
runTests({ isDev: false })
}
)
})