-
Notifications
You must be signed in to change notification settings - Fork 26k
/
index.test.ts
70 lines (63 loc) · 1.93 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
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { hasRedbox, renderViaHTTP } from 'next-test-utils'
import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
describe('Type module interop', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`,
'pages/modules.jsx': `
import Link from 'next/link'
import Image from 'next/image'
export default function Modules() {
return (
<>
<Link href="/">
<a id="link-to-home">link to home</a>
</Link>
<Image src="/static/image.png" width="100" height="100" />
</>
)
}
`,
},
dependencies: {},
})
const contents = await next.readFile('package.json')
const pkg = JSON.parse(contents)
await next.patchFile(
'package.json',
JSON.stringify({
...pkg,
type: 'module',
})
)
})
afterAll(() => next.destroy())
it('should render server-side', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('hello world')
})
it('should render client-side', async () => {
const browser = await webdriver(next.url, '/')
expect(await hasRedbox(browser)).toBe(false)
await browser.close()
})
it('should render server-side with modules', async () => {
const html = await renderViaHTTP(next.url, '/modules')
const $ = cheerio.load(html)
expect($('#link-to-home').text()).toBe('link to home')
})
it('should render client-side with modules', async () => {
const browser = await webdriver(next.url, '/modules')
expect(await hasRedbox(browser)).toBe(false)
await browser.close()
})
})