Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
],
"ava": {
"files": [
"tests/**/*.js"
"tests/**/*.js",
"!tests/example/**/*.js"
],
"source": [
"src/**/*.js",
Expand Down Expand Up @@ -50,8 +51,8 @@
"scripts": {
"release": "generate-release",
"flow": "flow",
"debug": "npm run build && node --inspect example/app.js",
"start": "npm run build && node example/app.js",
"debug": "npm run build && node --inspect tests/example/app.js",
"start": "npm run build && node tests/example/app.js",
"prepublish": "npm run build && nsp check",
"pretest": "eslint . --fix",
"test": "eslint src && nyc ava",
Expand Down
75 changes: 75 additions & 0 deletions tests/example/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @flow
const path = require('path');
const express = require('express');
const uuidv4 = require('uuid/v4');

const expressVueRenderer = require('../lib');
const expressVue = require('./expressVue');

var exampleMixin = {
methods: {
hello: function () {
console.log('Hello');
}
}
};

const options = {
rootPath: path.join(__dirname, 'vueFiles'),
vue: {
head: {
meta: [{
property: 'og:title',
content: 'Page Title'
},
{
name: 'twitter:title',
content: 'Page Title'
},
{
script: 'https://unpkg.com/vue@2.4.2/dist/vue.js'
}, {
name: 'viewport',
content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'
}
]
}
},
data: {
thing: true
}
};


renderer = expressVue.init(options);

const app = express();
app.use(express.static('./dist'));

app.use(renderer);

app.get('/', (req, res) => {
const data = {
title: 'Express Vue',
message: 'Hello world',
uuid: uuidv4(),
uuid2: uuidv4()
};
const vueOptions = {
head: {
title: 'Page Title',
meta: [
{
property: 'og:title2',
content: 'Page Title2'
}
]
}
}
res.renderVue('main.vue', data, vueOptions)
});

app.listen(3000);

console.log('express example start in 127.0.0.1:3000');
module.exports = app;
16 changes: 16 additions & 0 deletions tests/example/components/inner.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div>
<p>Inner Text</p>
</div>
</template>

<script>
export default {
data: function () {
return {}
}
}
</script>

<style lang="css">
</style>
25 changes: 25 additions & 0 deletions tests/example/components/uuid.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template>
<div>
<inner></inner>
<h2 class="test">Uuid: {{uuid ? uuid : 'no uuid'}}</h2>
</div>
</template>

<script>
import inner from '../components/inner.vue';
export default {
props: ['uuid'],
data: function () {
return {}
},
components: {
inner: inner
}
}
</script>

<style lang="css">
.test {
color: blue;
}
</style>
20 changes: 20 additions & 0 deletions tests/example/components/uuid2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<template>
<div>
<h3 class="red">Uuid2: {{uuid2 ? uuid2 : 'no uuid'}}</h3>
</div>
</template>

<script>
export default {
props: ['uuid2'],
data: function () {
return {}
}
}
</script>

<style lang="css">
.red {
color: yellowgreen;
}
</style>
26 changes: 26 additions & 0 deletions tests/example/expressVue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const ExpressVueRenderer = require('../lib');

//This is the Middlewarein express-vue this wont be in the file
function init(options) {
//Make new object
const Renderer = new ExpressVueRenderer(options);
//Middleware init
return (req, res, next) => {
//Res RenderVUE function
res.renderVue = (componentPath, data = {}, vueOptions = {}) => {
res.set('Content-Type', 'text/html');
Renderer.renderToStream(componentPath, data, vueOptions)
.then(stream => {
stream.on('data', chunk => res.write(chunk));
stream.on('end', () => res.end());
})
.catch(error => {
console.error(error);
res.send(error);
});
};
return next();
};
}

module.exports.init = init;
10 changes: 10 additions & 0 deletions tests/example/mixins/exampleMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const exampleMixin = {
methods: {
hello: function () {
console.log('Hello');
}
}
};

module.exports = exampleMixin;
exports.default = exampleMixin;
37 changes: 37 additions & 0 deletions tests/example/vueFiles/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<div>
<h1>{{title}}</h1>
<p>Welcome to the {{title}} demo. Click a link:</p>
<input v-model="message" placeholder="edit me">
<p>{{message}}</p>
<uuid :uuid="uuid"></uuid>
<uuid2 :uuid2="uuid2"></uuid2>
<button type="button" name="button" v-on:click="this.hello">Test mixin</button>
<button type="button" name="button" v-on:click="this.test">Test method</button>
</div>
</template>

<script>
import exampleMixin from '../mixins/exampleMixin';
import uuid from '../components/uuid.vue';
import uuid2 from '../components/uuid2.vue';
export default {
mixins: [exampleMixin],
data: function () {
return {}
},
methods: {
test: function () {
console.error('test');
}
},
components: {
uuid: uuid,
uuid2: uuid2
}
}
</script>

<style lang="css">

</style>
2 changes: 1 addition & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Models = require('../src/models');
const path = require('path');

const options = {
rootPath: path.join(__dirname, '../example')
rootPath: path.join(__dirname, 'example/vueFiles')
};

const data = {
Expand Down
4 changes: 2 additions & 2 deletions tests/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var cacheOptions = {
var lruCache = LRU(cacheOptions);

let types = new Types();
const component = __dirname + '/../../example/components/uuid.vue';
const component = path.join(__dirname, '../example/components/uuid.vue');
const options = {
rootPath: path.join(__dirname, '../../example'),
rootPath: path.join(__dirname, '../example/vueFiles'),
component: 'uuid.vue'
};

Expand Down
8 changes: 4 additions & 4 deletions tests/utils/checkPathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '../../src/utils';
import Models from '../../src/models';

const rootPath = path.join(__dirname, '../../example/');
const rootPath = path.join(__dirname, '../example/vueFiles');
const defaults = new Models.Defaults();
var LRU = require('lru-cache');
var cacheOptions = {
Expand All @@ -15,8 +15,8 @@ var cacheOptions = {
var lruCache = LRU(cacheOptions);

test('correctPath Path', t => {
const filePath = path.join(rootPath, '../example/components/uuid.vue');
const correctPath = rootPath + 'components/uuid.vue';
const filePath = path.join(rootPath, '/../components/uuid.vue');
const correctPath = path.join(rootPath + '/../components/uuid.vue');

return PathUtils.getCorrectPathForFile(filePath, 'view', defaults, lruCache)
.then(returnedPath => {
Expand All @@ -29,7 +29,7 @@ test('correctPath Path', t => {
test('shows error for fake test Path ', t => {

const filePath = path.join(rootPath, 'componentDoesntExist.vue');
const errMessage = `Could not find test file at ${rootPath}componentDoesntExist.vue`
const errMessage = `Could not find test file at ${rootPath}/componentDoesntExist.vue`

return PathUtils.getCorrectPathForFile(filePath, 'test', defaults, lruCache)
.catch(error => {
Expand Down