/* global expect, jasmine, describe, test, beforeAll, afterAll */ 'use strict' import { join } from 'path' import next from '../dist/server/next' const dir = join(__dirname, 'fixtures', 'basic') const app = next({ dir, dev: true, staticMarkup: true, quiet: true }) jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000 describe('integration tests', () => { beforeAll(() => app.prepare()) afterAll(() => app.close()) test('renders a stateless component', async () => { const html = await render('/stateless') expect(html.includes('')).toBeTruthy() expect(html.includes('

My component!

')).toBeTruthy() }) test('renders a stateful component', async () => { const html = await render('/stateful') expect(html.includes('

The answer is 42

')).toBeTruthy() }) test('header helper renders header information', async () => { const html = await (render('/head')) expect(html.includes('')).toBeTruthy() expect(html.includes('')).toBeTruthy() expect(html.includes('

I can haz meta tags

')).toBeTruthy() }) test('css helper renders styles', async () => { const html = await render('/css') expect(/\.css-\w+/.test(html)).toBeTruthy() expect(/
This is red<\/div>/.test(html)).toBeTruthy() }) test('renders properties populated asynchronously', async () => { const html = await render('/async-props') expect(html.includes('

Diego Milito

')).toBeTruthy() }) test('renders a link component', async () => { const html = await render('/link') expect(html.includes('About')).toBeTruthy() }) test('error', async () => { const html = await render('/error') expect(html).toMatch(/
Error: This is an expected error\n[^]+<\/pre>/)
  })

  test('error 404', async () => {
    const html = await render('/non-existent')
    expect(html).toMatch(/

404<\/h1>/) expect(html).toMatch(/

This page could not be found\.<\/h2>/) }) test('finishes response', async () => { const res = { finished: false, end () { this.finished = true } } const html = await app.renderToHTML({}, res, '/finish-response', {}) expect(html).toBeFalsy() }) }) function render (pathname, query = {}) { return app.renderToHTML({}, {}, pathname, query) }