Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
configured tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alidcast committed Aug 2, 2017
1 parent 2b9044e commit a9d5f0b
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 5 deletions.
68 changes: 68 additions & 0 deletions tests/complex.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const { Nuxt, Builder } = require('nuxt')
const test = require('ava')
const { resolve } = require('path')

const host = 'localhost'
const port = 3000
const url = (route) => `http://${host}:${port}/${route}`

const basicConfig = require(resolve(__dirname, 'fixtures/nuxt.config.js'))({
content: [
['posts', {
permalink: ":year/:slug",
routes: [
{
path: "/_post",
method: "get"
},
{
path: "/archives",
method: "getAll"
}
]
}],
['projects', {
permalink: "/:slug",
isPost: false,
routes: [
{
path: "/projects/_slug",
method: "get"
},
{
path: "/projects",
method: "getAll"
}
]
}]
]
})

let nuxt = null
let server = null

test.before('Init Nuxt and Nuxtent', async () => {
const config = Object.assign({}, {
rootDir: resolve(__dirname, 'fixtures'),
srcDir: resolve(__dirname, 'fixtures/multiple-content-types'),
dev: false
}, basicConfig)
nuxt = new Nuxt(config)
// await new Builder(nuxt).build()
await nuxt.listen(port, host)
})

test('posts content - get', async t => {
const { html } = await nuxt.renderRoute('2016/first-post')
t.true(html.includes('<h1>My First Post</h1><div><p>This is my first post!</p>'))
})

// test('content - getAll', async t => {
// const { html } = await nuxt.renderRoute('archives')
// 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>'
// ))
// })

test.after('Closing server', t => {
nuxt.close()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: My First Post
---

This is my first post!
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: Ency.js
---

Pretty cool plugin!
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: Nuxt Content
---

It does some pretty awesome things.
16 changes: 16 additions & 0 deletions tests/fixtures/multiple-content-types/pages/_post.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div>
<h1> {{ post.title }} </h1>
<div v-html="post.body" />
</div>
</template>

<script>
export default {
async asyncData ({ app, route, payload }) {
return {
post: payload || await app.$content('/posts').get(route.path)
}
}
}
</script>
20 changes: 20 additions & 0 deletions tests/fixtures/multiple-content-types/pages/archives.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<template>
<section class="container">
<h1> Posts </h1>
<ul>
<li v-for="post in posts">
<nuxt-link :to="post.permalink">{{ post.title }}</nuxt-link>
</li>
</ul>
</section>
</template>

<script>
export default {
async asyncData ({ app, payload }) {
return {
posts: payload || await app.$content('/posts').getAll()
}
}
}
</script>
15 changes: 15 additions & 0 deletions tests/fixtures/multiple-content-types/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<section class="home-container">
<h1>Nuxtent</h1>
<nuxt-link to="/2015/first-post">See my first post</nuxt-link>
<nuxt-link to="/archives">See all my posts</nuxt-link>
<nuxt-link to="/projects/ency">See my first project</nuxt-link>
<nuxt-link to="/projects">See all my projects</nuxt-link>
</section>
</template>

<style>
.home-container a {
padding-right: 1rem;
}
</style>
21 changes: 21 additions & 0 deletions tests/fixtures/multiple-content-types/pages/projects.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<section class="container">
<h1> Projects </h1>
<ul>
<li v-for="project in projects">
<nuxt-link :to="'/projects' + project.permalink">{{ project.name }}</nuxt-link>
</li>
</ul>
<nuxt-child />
</section>
</template>

<script>
export default {
async asyncData ({ app, payload }) {
return {
projects: payload || await app.$content('/projects').getAll()
}
}
}
</script>
16 changes: 16 additions & 0 deletions tests/fixtures/multiple-content-types/pages/projects/_slug.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<section class="container">
<h1> Project: {{ project.name }} </h1>
<nuxtent-body :body="project.body" />
</section>
</template>

<script>
export default {
async asyncData ({ app, route, payload }) {
return {
project: payload || await app.$content('/projects').get(route.params.slug)
}
}
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<section class="container">
<h1> Project </h1>
See all my projects!
</section>
</template>
6 changes: 4 additions & 2 deletions tests/fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"description": "nuxtent single content types example",
"author": "Alid Castano <[email protected]>",
"dependencies": {
"@nuxtjs/axios": "^2.2.1",
"nuxt": "^1.0.0-alpha.4"
"@nuxtjs/axios": "^2.2.1"
},
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"devDependencies": {
"nuxt": "^1.0.0-rc3"
}
}
7 changes: 4 additions & 3 deletions tests/basic.build.test.js → tests/simple.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const host = 'localhost'
const port = 3000
const url = (route) => `http://${host}:${port}/${route}`

const basicConfig =require(resolve(__dirname, 'fixtures/nuxt.config.js'))({
const basicConfig = require(resolve(__dirname, 'fixtures/nuxt.config.js'))({
content: {
permalink: '/:year/:slug',
routes: [
{
name: 'post',
path: '/_post',
method: 'get'
},
{
name: 'archives',
path: '/archives',
method: 'getAll'
}
]
Expand All @@ -33,6 +33,7 @@ test.before('Init Nuxt and Nuxtent', async () => {
}, basicConfig)

nuxt = new Nuxt(config)
// await new Builder(nuxt).build()
await nuxt.listen(port, host)
})

Expand Down

0 comments on commit a9d5f0b

Please sign in to comment.