|
1 | | -const { Nuxt, Builder } = require('nuxt') |
2 | | -const test = require('ava') |
3 | | -const { resolve } = require('path') |
| 1 | +import { resolve } from 'path' |
4 | 2 |
|
5 | | -const host = 'localhost' |
6 | | -const port = 3000 |
7 | | -const url = (route) => `http://${host}:${port}/${route}` |
| 3 | +import test from 'ava' |
8 | 4 |
|
9 | | -const basicConfig = require(resolve(__dirname, 'fixtures/nuxt.config.js'))({ |
10 | | - content: [ |
11 | | - ['posts', { |
12 | | - permalink: ":year/:slug", |
13 | | - routes: [ |
14 | | - { |
15 | | - path: "/_post", |
16 | | - method: "get" |
17 | | - }, |
18 | | - { |
19 | | - path: "/archives", |
20 | | - method: "getAll" |
21 | | - } |
22 | | - ] |
23 | | - }], |
24 | | - ['projects', { |
25 | | - permalink: "/:slug", |
26 | | - isPost: false, |
27 | | - routes: [ |
28 | | - { |
29 | | - path: "/projects/_slug", |
30 | | - method: "get" |
31 | | - }, |
32 | | - { |
33 | | - path: "/projects", |
34 | | - method: "getAll" |
35 | | - } |
| 5 | +import { get, commonBefore, commonAfter } from "../fixtures/nuxt"; |
| 6 | + |
| 7 | +test.before('Init Nuxt and Nuxtent', async () => { |
| 8 | + await commonBefore( |
| 9 | + { |
| 10 | + content: [ |
| 11 | + [ |
| 12 | + 'posts', |
| 13 | + { |
| 14 | + page: '/posts/_slug', |
| 15 | + permalink: '/:year/:slug', |
| 16 | + } |
| 17 | + ], |
| 18 | + [ |
| 19 | + 'projects', |
| 20 | + { |
| 21 | + page: '/projects/_slug', |
| 22 | + permalink: "/projects/:slug", |
| 23 | + isPost: false |
| 24 | + } |
| 25 | + ] |
36 | 26 | ] |
37 | | - }] |
38 | | - ] |
| 27 | + }, |
| 28 | + { |
| 29 | + srcDir: resolve(__dirname, '../fixtures/multiple-content-types') |
| 30 | + } |
| 31 | + )() |
39 | 32 | }) |
40 | 33 |
|
41 | | -let nuxt = null |
42 | | -let server = null |
43 | | - |
44 | | -test.before('Init Nuxt and Nuxtent', async () => { |
45 | | - const config = Object.assign({}, { |
46 | | - rootDir: resolve(__dirname, 'fixtures'), |
47 | | - srcDir: resolve(__dirname, 'fixtures/multiple-content-types'), |
48 | | - dev: false |
49 | | - }, basicConfig) |
50 | | - nuxt = new Nuxt(config) |
51 | | - // await new Builder(nuxt).build() |
52 | | - await nuxt.listen(port, host) |
| 34 | +test('index', async t => { |
| 35 | + const html = await get('/') |
| 36 | + t.true(html.includes('<section class="home-container"><h1>Nuxtent</h1><a href="/2015/first-post">See my first post</a><a href="/archives">See all my posts</a><a href="/projects/ency">See my first project</a><a href="/projects">See all my projects</a></section>')) |
53 | 37 | }) |
54 | 38 |
|
55 | 39 | test('posts content - get', async t => { |
56 | | - const { html } = await nuxt.renderRoute('2016/first-post') |
| 40 | + const html = await get('/2016/first-post') |
57 | 41 | t.true(html.includes('<h1>My First Post</h1><div><p>This is my first post!</p>')) |
58 | 42 | }) |
59 | 43 |
|
60 | | -// test('content - getAll', async t => { |
61 | | -// const { html } = await nuxt.renderRoute('archives') |
62 | | -// t.true(html.includes('<li><a href="/2016/first-post">My First Post</a></li><li><a href="/2017/second-post">My Second Post</a></li>' |
63 | | -// )) |
64 | | -// }) |
| 44 | +test('posts content - getAll', async t => { |
| 45 | + const html = await get('/archives') |
| 46 | + t.true(html.includes('<section class="container"><h1>Posts</h1><ul><li><a href="/2016/first-post">My First Post</a></li></ul></section>')) |
| 47 | +}) |
| 48 | + |
| 49 | +test('projects content - get', async t => { |
| 50 | + const html = await get('/projects/ency') |
| 51 | + t.true(html.includes( |
| 52 | +`<section class="container"><h1>Project: Ency.js</h1><div><p>Pretty cool plugin!</p> |
| 53 | +</div></section>` |
| 54 | + )) |
| 55 | +}) |
| 56 | + |
| 57 | +test('projects content - getAll', async t => { |
| 58 | + const html = await get('/projects/') |
| 59 | + t.true(html.includes('<section class="container"><h1>Projects</h1><ul><li><a href="/projects/projects/nuxtent">Nuxt Content</a></li><li><a href="/projects/projects/ency">Ency.js</a></li></ul></section>')) |
| 60 | +}) |
65 | 61 |
|
66 | | -test.after('Closing server', t => { |
67 | | - nuxt.close() |
| 62 | +test.after('Closing server and nuxt.js', async () => { |
| 63 | + await commonAfter() |
68 | 64 | }) |
0 commit comments