index.js 1.1 KB
Newer Older
N
nkzawa 已提交
1
import test from 'ava'
N
nkzawa 已提交
2
import { join } from 'path'
N
nkzawa 已提交
3 4 5
import build from '../server/build'
import { render as _render } from '../server/render'

N
nkzawa 已提交
6
const dir = join(__dirname, 'fixtures', 'basic')
N
nkzawa 已提交
7 8 9

test.before(() => build(dir))

10
test(async t => {
N
nkzawa 已提交
11
  const html = await render('/stateless')
Z
zpnk 已提交
12
  t.true(html.includes('<meta charset="utf-8" class="next-head"/>'))
N
nkzawa 已提交
13 14 15
  t.true(html.includes('<h1>My component!</h1>'))
})

16
test(async t => {
N
nkzawa 已提交
17
  const html = await render('/css')
D
Dan Zajdband 已提交
18 19
  t.true(html.includes('.css-im3wl1'))
  t.true(html.includes('<div class="css-im3wl1">This is red</div>'))
N
nkzawa 已提交
20 21
})

22
test(async t => {
D
Dan Zajdband 已提交
23
  const html = await render('/stateful')
24 25 26 27 28
  t.true(html.includes('<div><p>The answer is 42</p></div>'))
})

test(async t => {
  const html = await (render('/head'))
Z
zpnk 已提交
29
  t.true(html.includes('<meta charset="iso-8859-5" class="next-head"/>'))
30 31 32 33
  t.true(html.includes('<meta content="my meta" class="next-head"/>'))
  t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
})

D
Dan Zajdband 已提交
34 35 36 37 38
test(async t => {
  const html = await render('/async-props')
  t.true(html.includes('<p>Diego Milito</p>'))
})

N
nkzawa 已提交
39 40 41
function render (url, ctx) {
  return _render(url, ctx, { dir, staticMarkup: true })
}