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

Commit ec19488

Browse files
Alid CastanoAlid Castano
authored andcommitted
added e2e and fixed fixtures
2 parents da574f5 + 2362b81 commit ec19488

File tree

21 files changed

+249
-204
lines changed

21 files changed

+249
-204
lines changed

.babelrc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,26 @@
33
["es2015", { "modules": false }],
44
"stage-2"
55
],
6-
76
"plugins": [
87
"transform-async-to-generator"
98
],
10-
9+
"env": {
10+
"test": {
11+
"presets": [
12+
"es2015",
13+
"stage-2"
14+
],
15+
"plugins": [
16+
"istanbul",
17+
[
18+
"transform-object-rest-spread",
19+
{
20+
"useBuiltIns": true
21+
}
22+
]
23+
],
24+
"sourceMaps": "inline"
25+
}
26+
},
1127
"comments": false
1228
}

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const nuxtentModule = require("./dist/module.js");
2+
3+
module.exports = nuxtentModule.default;
4+
module.exports.meta = nuxtentModule.meta;

lib/module.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1+
import { resolve, join } from 'path'
2+
13
import createRouter from './content/api'
24
import buildContent from './content/build'
35
import { mdParser, yamlParser } from './util/parsers'
46

5-
const { existsSync } = require('fs')
6-
const { resolve, join } = require('path')
7+
import pkg from '../package.json'
78

89
const port = process.env.PORT || process.env.npm_package_config_nuxt_port || 3000
910
const host = process.env.HOST || process.env.npm_package_config_nuxt_host || 'localhost'
1011

1112
const nuxtentConfig = (nuxtOpts) => {
1213
const rootConfig = resolve(nuxtOpts.rootDir, 'nuxtent.config.js')
13-
if (existsSync(rootConfig)) {
14-
try {
15-
return require(rootConfig)
16-
} catch (err) {
17-
throw new Error (`[Invalid Nuxtent configuration] ${err}`)
14+
try {
15+
return require(rootConfig)
16+
} catch (err) {
17+
if (err.code === "MODULE_NOT_FOUND") {
18+
return nuxtOpts.nuxtent
1819
}
19-
} else return nuxtOpts.nuxtent
20+
throw new Error (`[Invalid Nuxtent configuration] ${err}`)
21+
}
2022
}
2123

2224
const contentOptions = (content, defaults) => {
@@ -111,9 +113,9 @@ export default function ContentModule(moduleOpts) {
111113
src: resolve(__dirname, 'plugin.js'),
112114
options: {
113115
...options,
114-
srcDirFromPlugin: join('../', srcDir) // TODO
116+
srcDirFromPlugin: join('~/', srcDir)
115117
}
116118
})
117119
}
118120

119-
module.exports.meta = require('../package.json')
121+
export { pkg as meta };

lib/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ function toQuery (options = {}) {
9494

9595
if (Array.isArray(exclude)) return 'exclude=' + exclude.join(',')
9696

97-
return `exclude=${exclude}`
97+
return 'exclude=' + exclude
9898
}

package.json

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nuxtent",
33
"version": "0.2.77",
44
"description": "Content Module for Nuxt.js.",
5-
"main": "dist/module.js",
5+
"main": "index.js",
66
"contributors": [
77
"Alid Castano (@alidcastano)"
88
],
@@ -27,7 +27,7 @@
2727
},
2828
"scripts": {
2929
"unit": "cross-env NODE_ENV=development karma start test/unit/karma.conf.js",
30-
"e2e": "cross-env NODE_ENV=test ava --verbose --serial tests/e2e",
30+
"e2e": "cross-env NODE_ENV=test ava --verbose --serial test/e2e",
3131
"test": "npm run unit --single-run && npm run e2e",
3232
"build": "NODE_ENV=production rollup -c rollup.config.js",
3333
"watch": "npm run build -- -w",
@@ -50,12 +50,16 @@
5050
},
5151
"devDependencies": {
5252
"@nuxtjs/axios": "^3.0.1",
53-
"ava": "^0.21.0",
53+
"ava": "^0.22.0",
54+
"babel-cli": "^6.26.0",
55+
"babel-plugin-external-helpers": "^6.22.0",
56+
"babel-plugin-istanbul": "^4.1.5",
5457
"babel-plugin-transform-async-to-generator": "^6.24.1",
58+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
5559
"babel-plugin-transform-runtime": "^6.23.0",
5660
"babel-preset-es2015": "^6.24.1",
57-
"babel-preset-es2015-rollup": "^3.0.0",
5861
"babel-preset-stage-2": "^6.24.1",
62+
"babel-register": "^6.26.0",
5963
"chai": "^4.1.0",
6064
"cross-env": "^5.0.1",
6165
"express": "^4.15.3",
@@ -65,9 +69,10 @@
6569
"karma-rollup-preprocessor": "^4.0.2",
6670
"karma-sinon-chai": "^1.3.1",
6771
"mocha": "^3.5.0",
68-
"nuxt": "^1.0.0-alpha.4",
69-
"rollup": "^0.43.0",
70-
"rollup-plugin-babel": "^2.7.1",
72+
"nuxt": "^1.0.0-rc11",
73+
"request-promise-native": "^1.0.4",
74+
"rollup": "^0.50.0",
75+
"rollup-plugin-babel": "^3.0.2",
7176
"rollup-plugin-commonjs": "^8.0.2",
7277
"rollup-plugin-copy": "^0.2.3",
7378
"rollup-plugin-filesize": "^1.2.1",
@@ -79,6 +84,12 @@
7984
"sinon": "^3.0.0",
8085
"sinon-chai": "^2.12.0"
8186
},
87+
"ava": {
88+
"require": [
89+
"babel-register"
90+
],
91+
"babel": "inherit"
92+
},
8293
"bugs": {
8394
"url": "https://github.com/nuxt-community/nuxtent-module/issues"
8495
},

rollup.config.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import resolve from 'rollup-plugin-node-resolve'
2+
import json from 'rollup-plugin-json'
23
import builtins from 'rollup-plugin-node-builtins'
34
import babel from 'rollup-plugin-babel'
45
import commonjs from 'rollup-plugin-commonjs'
@@ -9,21 +10,29 @@ import copy from 'rollup-plugin-copy'
910
const version = process.env.VERSION || require('./package.json').version
1011

1112
const corePlugins = () => [
12-
babel(),
1313
resolve(),
14-
commonjs(),
14+
commonjs({
15+
include: 'node_modules/**'
16+
}),
17+
babel({
18+
plugins: ['external-helpers']
19+
}),
1520
builtins(),
1621
uglify(),
1722
filesize()
1823
]
1924

2025
const bundle = (name, options) => ({
21-
entry: `lib/${name}.js`,
22-
dest: `dist/${name}.js`,
23-
format: 'umd',
24-
moduleName: `nuxtContent`,
26+
input: `lib/${name}.js`,
27+
output: {
28+
file: `dist/${name}.js`,
29+
format: 'cjs',
30+
exports: 'named'
31+
},
32+
name: `nuxtContent`,
2533
plugins: options.plugins || [],
2634
external: options.external || [],
35+
globals: options.globals || {},
2736
banner: `
2837
/**
2938
* Nuxt Content v${version}
@@ -36,6 +45,7 @@ const bundle = (name, options) => ({
3645
export default [
3746
bundle('module', {
3847
plugins: [
48+
json(),
3949
copy({
4050
'lib/plugin.js': 'dist/plugin.js',
4151
'lib/loader.js': 'dist/loader.js'
@@ -45,6 +55,9 @@ export default [
4555
external: [
4656
'express',
4757
'axios'
48-
]
58+
],
59+
globals: {
60+
express: 'express'
61+
}
4962
})
5063
]

test/e2e/complex.test.js

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,64 @@
1-
const { Nuxt, Builder } = require('nuxt')
2-
const test = require('ava')
3-
const { resolve } = require('path')
1+
import { resolve } from 'path'
42

5-
const host = 'localhost'
6-
const port = 3000
7-
const url = (route) => `http://${host}:${port}/${route}`
3+
import test from 'ava'
84

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+
]
3626
]
37-
}]
38-
]
27+
},
28+
{
29+
srcDir: resolve(__dirname, '../fixtures/multiple-content-types')
30+
}
31+
)()
3932
})
4033

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>'))
5337
})
5438

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

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+
})
6561

66-
test.after('Closing server', t => {
67-
nuxt.close()
62+
test.after('Closing server and nuxt.js', async () => {
63+
await commonAfter()
6864
})

0 commit comments

Comments
 (0)