refactor: add examples to lint

This commit is contained in:
Clark Du 2017-10-31 21:43:55 +08:00
parent b132decf9d
commit 3e637c5d83
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
94 changed files with 360 additions and 330 deletions

4
.eslintignore Normal file
View File

@ -0,0 +1,4 @@
app
node_modules
dist
.nuxt

View File

@ -12,7 +12,7 @@ const getPost = (slug) => ({
})
export default {
beforeCreate () {
beforeCreate() {
this.component = () => getPost(this.$route.params.slug)
}
}

View File

@ -12,7 +12,7 @@ module.exports = {
},
generate: {
routes: [
'/posts/1',
'/posts/1'
]
}
}

View File

@ -11,12 +11,12 @@
import axios from 'axios'
export default {
async asyncData ({ params }) {
async asyncData({ params }) {
// We can use async/await ES6 feature
let { data } = await axios.get(`https://jsonplaceholder.typicode.com/posts/${params.id}`)
return { post: data }
},
head () {
head() {
return {
title: this.post.title
}

View File

@ -15,12 +15,12 @@
import axios from 'axios'
export default {
asyncData ({ req, params }) {
asyncData({ req, params }) {
// We can return a Promise instead of calling the callback
return axios.get('https://jsonplaceholder.typicode.com/posts')
.then((res) => {
return { posts: res.data.slice(0, 5) }
})
.then((res) => {
return { posts: res.data.slice(0, 5) }
})
},
head: {
title: 'List of posts'

View File

@ -20,7 +20,7 @@
<script>
export default {
data () {
data() {
return {
formError: null,
formUsername: '',
@ -28,7 +28,7 @@ export default {
}
},
methods: {
async login () {
async login() {
try {
await this.$store.dispatch('login', {
username: this.formUsername,
@ -37,11 +37,11 @@ export default {
this.formUsername = ''
this.formPassword = ''
this.formError = null
} catch(e) {
} catch (e) {
this.formError = e.message
}
},
async logout () {
async logout() {
try {
await this.$store.dispatch('logout')
} catch (e) {

View File

@ -12,12 +12,12 @@ export const mutations = {
export const actions = {
// nuxtServerInit is called by Nuxt.js before server-rendering every page
nuxtServerInit ({ commit }, { req }) {
nuxtServerInit({ commit }, { req }) {
if (req.session && req.session.authUser) {
commit('SET_USER', req.session.authUser)
}
},
async login ({ commit }, { username, password }) {
async login({ commit }, { username, password }) {
try {
const { data } = await axios.post('/api/login', { username, password })
commit('SET_USER', data)
@ -29,7 +29,7 @@ export const actions = {
}
},
async logout ({ commit }) {
async logout({ commit }) {
await axios.post('/api/logout')
commit('SET_USER', null)
}

View File

@ -9,7 +9,7 @@
export default {
async asyncData ({ app }) {
async asyncData({ app }) {
const { data: { message: dog } } = await app.$axios.get('/dog')
return { dog }
}

View File

@ -9,11 +9,11 @@
<script>
export default {
name: 'date',
serverCacheKey () {
serverCacheKey() {
// Will change every 10 secondes
return Math.floor(Date.now() / 10000)
},
data () {
data() {
return { date: Date.now() }
}
}

View File

@ -7,7 +7,7 @@ module.exports = {
app: 'app.[chunkhash].js' // default: nuxt.bundle.[chunkhash].js
},
vendor: ['lodash'],
extend (config, { isDev }) {
extend(config, { isDev }) {
if (isDev) {
config.devtool = 'eval-source-map'
}

View File

@ -8,7 +8,7 @@
<script>
export default {
layout: 'dark',
asyncData ({ req }) {
asyncData({ req }) {
return {
name: req ? 'server' : 'client'
}

View File

@ -10,10 +10,10 @@ export default {
loading: false
}),
methods: {
start () {
start() {
this.loading = true
},
finish () {
finish() {
this.loading = false
}
}

View File

@ -7,7 +7,7 @@
<script>
export default {
asyncData () {
asyncData() {
return new Promise((resolve) => {
setTimeout(function () {
resolve({})

View File

@ -7,7 +7,7 @@
<script>
export default {
asyncData () {
asyncData() {
return new Promise((resolve) => {
setTimeout(function () {
resolve({ name: 'world' })

View File

@ -13,7 +13,7 @@
import axios from 'axios'
export default {
async asyncData () {
async asyncData() {
const { data } = await axios.get('https://jsonplaceholder.typicode.com/users')
return { users: data }
}

View File

@ -11,10 +11,10 @@
import axios from 'axios'
export default {
validate ({ params }) {
validate({ params }) {
return !isNaN(+params.id)
},
async asyncData ({ params, error }) {
async asyncData({ params, error }) {
try {
const { data } = await axios.get(`https://jsonplaceholder.typicode.com/users/${+params.id}`)
return data

View File

@ -1,7 +1,6 @@
{
"name": "nuxt-custom-server",
"dependencies": {
"chalk": "^2.2.0",
"express": "^4.15.3",
"nuxt": "latest"
},

View File

@ -1,6 +1,5 @@
const app = require('express')()
const { Nuxt, Builder } = require('nuxt')
const chalk = require('chalk')
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000
@ -22,4 +21,3 @@ app.use(nuxt.render)
// Start express server
app.listen(port, host)
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${host}:${port}`))

View File

@ -5,7 +5,7 @@ export default async () => {
return VueChart.Bar.extend({
props: ['data'],
mounted () {
mounted() {
this.renderChart(this.data)
}
})

View File

@ -13,12 +13,12 @@ export default {
data: () => ({
loaded: false
}),
beforeMount () {
beforeMount() {
// Preload image
const img = new Image()
img.onload = () => {
this.loaded = true
};
}
img.src = this.data
}
}

View File

@ -18,7 +18,7 @@ export const messages = [
{ component: 'vText', data: 'End of demo 🎉' }
]
async function streamMessages (fn, i = 0) {
async function streamMessages(fn, i = 0) {
if (i >= messages.length) return
await fn(messages[i])
setTimeout(() => streamMessages(fn, i + 1), 1500)

View File

@ -23,7 +23,7 @@ export default {
data: () => ({
messages: []
}),
mounted () {
mounted() {
// Listen for incoming messages
streamMessages(async (message) => {
// Wait for the component to load before displaying it

View File

@ -8,7 +8,7 @@
<script>
export default {
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default',
asyncData ({ req }) {
asyncData({ req }) {
return {
name: req ? 'server' : 'client'
}

View File

@ -7,6 +7,6 @@
<script>
export default {
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default',
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default'
}
</script>

View File

@ -1,11 +1,11 @@
<script>
export default {
asyncData ({ req }) {
asyncData({ req }) {
return {
name: req ? 'server' : 'client'
}
},
render (h) {
render(h) {
return <div>
<p>Hi from {this.name}</p>
<nuxt-link to="/">Home page</nuxt-link>

View File

@ -1,5 +1,5 @@
export default {
render (h) {
render(h) {
return <div>
<h1>Welcome !</h1>
<nuxt-link to="/about">About page</nuxt-link>

View File

@ -7,7 +7,7 @@
<script>
export default {
asyncData () {
asyncData() {
return {
name: process.static ? 'static' : (process.server ? 'server' : 'client')
}

View File

@ -26,7 +26,7 @@
<script>
export default {
methods: {
path (url) {
path(url) {
return (this.$i18n.locale === 'en' ? url : '/' + this.$i18n.locale + url)
}
}

View File

@ -6,7 +6,7 @@ module.exports = {
router: {
middleware: 'i18n'
},
plugins: ['~/plugins/i18n.js',],
plugins: ['~/plugins/i18n.js'],
generate: {
routes: ['/', '/about', '/fr', '/fr/about']
}

View File

@ -9,7 +9,7 @@
<script>
export default {
head () {
head() {
return { title: this.$t('about.title') }
}
}

View File

@ -9,7 +9,7 @@
<script>
export default {
head () {
head() {
return { title: this.$t('home.title') }
}
}

View File

@ -4,7 +4,7 @@ export const state = () => ({
})
export const mutations = {
SET_LANG (state, locale) {
SET_LANG(state, locale) {
if (state.locales.indexOf(locale) !== -1) {
state.locale = locale
}

View File

@ -19,11 +19,11 @@
import axios from 'axios'
export default {
transition (to, from) {
transition(to, from) {
if (!from) return 'slide-left'
return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
},
async asyncData ({ query }) {
async asyncData({ query }) {
const page = query.page || 1
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
return {

View File

@ -12,7 +12,7 @@
<script>
export default {
data () {
data() {
return {
model: 'I am index'
}

View File

@ -9,7 +9,7 @@
<script>
export default {
data () {
data() {
return {
model: 'I am pug'
}

View File

@ -7,12 +7,12 @@
<script>
export default {
computed: {
visits () {
visits() {
return this.$store.state.visits.slice().reverse()
}
},
filters: {
hours (date) {
hours(date) {
return date.split('T')[1].split('.')[0]
}
}

View File

@ -11,7 +11,7 @@
<script>
export default {
asyncData ({ store, route, userAgent }) {
asyncData({ store, route, userAgent }) {
return {
userAgent,
slugs: [

View File

@ -3,7 +3,7 @@ export const state = () => ({
})
export const mutations = {
ADD_VISIT (state, path) {
ADD_VISIT(state, path) {
state.visits.push({
path,
date: new Date().toJSON()

View File

@ -16,7 +16,7 @@
<script>
export default {
asyncData ({ env }) {
asyncData({ env }) {
return { users: env.users }
}
}

View File

@ -7,17 +7,17 @@
<script>
export default {
validate ({ params }) {
validate({ params }) {
return !isNaN(+params.id)
},
asyncData ({ params, env, error }) {
asyncData({ params, env, error }) {
const user = env.users.find((user) => String(user.id) === params.id)
if (!user) {
return error({ message: 'User not found', statusCode: 404 })
}
return user
},
head () {
head() {
return {
title: this.name
}

View File

@ -9,7 +9,7 @@
import axios from 'axios'
export default {
asyncData () {
asyncData() {
const nb = Math.max(1, Math.round(Math.random() * 10))
return axios.get(`https://jsonplaceholder.typicode.com/photos/${nb}`).then(res => res.data)
}

View File

@ -12,7 +12,7 @@ if (process.browser) {
}
export default {
mounted () {
mounted() {
miniToastr.init()
},
notifications: {

View File

@ -19,11 +19,11 @@
import axios from 'axios'
export default {
transition (to, from) {
transition(to, from) {
if (!from) return 'slide-left'
return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
},
async asyncData ({ query }) {
async asyncData({ query }) {
const page = +query.page || 1
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
return {

View File

@ -7,7 +7,7 @@
<script>
export default {
asyncData () {
asyncData() {
return {
name: (process.server ? 'server' : 'client')
}

View File

@ -9,7 +9,7 @@
<script>
export default {
asyncData ({ req }) {
asyncData({ req }) {
return {
name: req ? 'server' : 'client'
}

View File

@ -9,10 +9,10 @@
</template>
// **PLEASE NOTE** All "Nuxt Class Components" require at minimum a script tag that exports a default object
<script lang="ts">
import Vue from "vue"
import Component from "nuxt-class-component"
import Vue from 'vue'
import Component from 'nuxt-class-component'
import { Prop } from 'vue-property-decorator'
import { Action } from "vuex-class"
import { Action } from 'vuex-class'
@Component({})
export default class Card extends Vue {

View File

@ -1,12 +1,12 @@
module.exports = function(options) {
module.exports = function (options) {
// Extend build
this.extendBuild(config => {
const tsLoader = {
loader: "ts-loader",
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
};
}
// Add TypeScript loader
config.module.rules.push(
Object.assign(
@ -15,12 +15,12 @@ module.exports = function(options) {
},
tsLoader
)
);
)
// Add TypeScript loader for vue files
for (let rule of config.module.rules) {
if (rule.loader === "vue-loader") {
rule.options.loaders.ts = tsLoader;
if (rule.loader === 'vue-loader') {
rule.options.loaders.ts = tsLoader
}
}
});
};
})
}

View File

@ -14,10 +14,10 @@
</template>
<script lang="ts">
import Vue from "vue";
import Component from "nuxt-class-component"
import Card from "~/components/Card"
import { State, Getter } from "vuex-class"
import Vue from 'vue'
import Component from 'nuxt-class-component'
import Card from '~/components/Card'
import { State, Getter } from 'vuex-class'
@Component({
components: {

View File

@ -10,7 +10,7 @@
<script>
export default {
asyncData ({ req }) {
asyncData({ req }) {
return {
name: req ? 'server' : 'client'
}

View File

@ -2,4 +2,4 @@ import UIkit from 'uikit'
import Icons from 'uikit/dist/js/uikit-icons'
// loads the Icon plugin
UIkit.use(Icons);
UIkit.use(Icons)

View File

@ -30,7 +30,7 @@ export default {
return formatter.format(num)
}
},
head () {
head() {
return {
title: (this.Car ? `${this.Car.make} ${this.Car.model}` : 'Loading')
}

View File

@ -2,7 +2,7 @@ import { Bar } from 'vue-chartjs'
export default Bar.extend({
props: ['data', 'options'],
mounted () {
mounted() {
this.renderChart(this.data, this.options)
}
})

View File

@ -2,7 +2,7 @@ import { Doughnut } from 'vue-chartjs'
export default Doughnut.extend({
props: ['data', 'options'],
mounted () {
mounted() {
this.renderChart(this.data, this.options)
}
})

View File

@ -7,15 +7,14 @@
<script>
import DoughnutChart from '~/components/doughnut-chart'
import axios from 'axios'
import moment from 'moment'
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
var letters = '0123456789ABCDEF'
var color = '#'
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
color += letters[Math.floor(Math.random() * 16)]
}
return color;
return color
}
export default {

View File

@ -23,18 +23,18 @@ export default class Base extends Vue {
msg = 123
// lifecycle hook
mounted () {
mounted() {
this.greet()
}
// computed
get computedMsg () {
get computedMsg() {
return 'computed ' + this.msg
}
// method
greet () {
console.log('base greeting: ' + this.msg)
greet() {
console.log('base greeting: ' + this.msg) // eslint-disable-line no-console
}
}
</script>

View File

@ -16,8 +16,8 @@ import Base from '@/components/Base'
@Component
export default class Child extends Base {
// override parent method
greet () {
console.log('child greeting: ' + this.msg)
greet() {
console.log('child greeting: ' + this.msg) // eslint-disable-line no-console
}
}
</script>

View File

@ -11,7 +11,7 @@ import Child from '@/components/Child'
components: { Child }
})
export default class App extends Vue {
asyncData ({ req }) {
asyncData({ req }) {
return { env: req ? 'server' : 'client' }
}
}

View File

@ -23,14 +23,14 @@ import { mapState } from 'vuex'
export default {
// fetch(context) is called by the server-side
// and before instantiating the component
fetch ({ store }) {
fetch({ store }) {
store.commit('increment')
},
computed: mapState([
'counter'
]),
methods: {
increment () {
increment() {
this.$store.commit('increment')
}
}

View File

@ -20,7 +20,7 @@ export default {
todos: 'todos/todos'
}),
methods: {
addTodo (e) {
addTodo(e) {
var text = e.target.value
if (text.trim()) {
this.$store.commit('todos/add', { text })

View File

@ -7,13 +7,13 @@ export const state = () => ({
})
export const mutations = {
add (state, title) {
add(state, title) {
state.list.push(title)
}
}
export const getters = {
get (state) {
get(state) {
return state.list
}
}

View File

@ -7,13 +7,13 @@ export const state = () => ({
})
export const mutations = {
add (state, title) {
add(state, title) {
state.list.push(title)
}
}
export const getters = {
get (state) {
get(state) {
return state.list
}
}

View File

@ -3,7 +3,7 @@ export const state = () => ({
})
export const mutations = {
increment (state) {
increment(state) {
state.counter++
}
}

View File

@ -3,20 +3,20 @@ export const state = () => ({
})
export const mutations = {
add (state, { text }) {
add(state, { text }) {
state.list.push({
text,
done: false
})
},
toggle (state, todo) {
toggle(state, todo) {
todo.done = !todo.done
}
}
export const getters = {
todos (state) {
todos(state) {
return state.list
}
}

View File

@ -13,14 +13,14 @@ import { mapState } from 'vuex'
export default {
// fetch(context) is called by the server-side
// and nuxt before instantiating the component
fetch ({ store }) {
fetch({ store }) {
store.commit('increment')
},
computed: mapState([
'counter'
]),
methods: {
increment () {
increment() {
this.$store.commit('increment')
}
}

View File

@ -1,7 +1,7 @@
const mutations = {
increment (state) {
state.counter++
}
increment(state) {
state.counter++
}
}
export default mutations

View File

@ -4,7 +4,7 @@
<script>
export default {
data () {
data() {
return { name: 'world' }
}
}

View File

@ -33,7 +33,7 @@ export default {
}
}),
computed: {
cookies () {
cookies() {
return this.$cookies.cookies
}
},

View File

@ -0,0 +1,36 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true,
node: true,
mocha: true
},
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
rules: {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
// do not allow console.logs etc...
'no-console': 2,
'space-before-function-paren': [
2,
{
anonymous: 'always',
named: 'never'
}
],
},
globals: {}
}

View File

@ -2,4 +2,4 @@ module.exports = {
loading: {
color: 'purple'
}
};
}

View File

@ -37,6 +37,7 @@
"winston": "^2.3.0"
},
"devDependencies": {
"eslint-plugin-mocha": "^4.11.0",
"jshint": "^2.9.4",
"mocha": "^3.2.0",
"nodemon": "^1.11.0",

View File

@ -7,7 +7,7 @@
<script>
export default {
asyncData () {
asyncData() {
return {
name: process.server ? 'server' : 'client'
}

View File

@ -1,30 +1,30 @@
'use strict';
'use strict'
const path = require('path');
const compress = require('compression');
const cors = require('cors');
const feathers = require('feathers');
const configuration = require('feathers-configuration');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest');
const bodyParser = require('body-parser');
const socketio = require('feathers-socketio');
const middleware = require('./middleware');
const services = require('./services');
const path = require('path')
const compress = require('compression')
const cors = require('cors')
const feathers = require('feathers')
const configuration = require('feathers-configuration')
const hooks = require('feathers-hooks')
const rest = require('feathers-rest')
const bodyParser = require('body-parser')
const socketio = require('feathers-socketio')
const middleware = require('./middleware')
const services = require('./services')
const app = feathers();
const app = feathers()
app.configure(configuration(path.join(__dirname, '..')));
app.configure(configuration(path.join(__dirname, '..')))
app.use(compress())
.options('*', cors())
.use(cors())
.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
.configure(hooks())
.configure(rest())
.configure(socketio())
.configure(services)
.configure(middleware);
.options('*', cors())
.use(cors())
.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
.configure(hooks())
.configure(rest())
.configure(socketio())
.configure(services)
.configure(middleware)
module.exports = app;
module.exports = app

View File

@ -1,4 +1,4 @@
'use strict';
'use strict'
// Add any common hooks you want to share across services in here.
//
@ -6,8 +6,8 @@
// see http://docs.feathersjs.com/hooks/readme.html for more details
// on hooks.
exports.myHook = function(options) {
return function(hook) {
console.log('My custom global hook ran. Feathers is awesome!');
};
};
exports.myHook = function (options) {
return function (hook) {
console.log('My custom global hook ran. Feathers is awesome!') // eslint-disable-line no-console
}
}

View File

@ -1,15 +1,15 @@
'use strict';
'use strict'
const app = require('./app');
const port = app.get('port');
const app = require('./app')
const port = app.get('port')
process.on('nuxt:build:done', (err) => {
if (err) {
console.error(err);
process.exit(1);
console.error(err) // eslint-disable-line no-console
process.exit(1)
}
const server = app.listen(port);
const server = app.listen(port)
server.on('listening', () =>
console.log(`Feathers application started on ${app.get('host')}:${port}`)
);
});
console.log(`Feathers application started on ${app.get('host')}:${port}`) // eslint-disable-line no-console
)
})

View File

@ -1,12 +1,12 @@
'use strict';
'use strict'
const nuxt = require('./nuxt');
const nuxt = require('./nuxt')
module.exports = function() {
module.exports = function () {
// Add your custom middleware here. Remember, that
// just like Express the order matters, so error
// handling middleware should go last.
const app = this;
const app = this
app.use(nuxt);
};
app.use(nuxt)
}

View File

@ -1,14 +1,11 @@
'use strict';
'use strict'
const authentication = require('feathers-authentication');
const authentication = require('feathers-authentication')
module.exports = function () {
const app = this
module.exports = function() {
const app = this;
let config = app.get('auth')
let config = app.get('auth');
app.configure(authentication(config));
};
app.configure(authentication(config))
}

View File

@ -1,11 +1,10 @@
'use strict';
const authentication = require('./authentication');
const user = require('./user');
'use strict'
const authentication = require('./authentication')
const user = require('./user')
module.exports = function() {
const app = this;
module.exports = function () {
const app = this
app.configure(authentication);
app.configure(user);
};
app.configure(authentication)
app.configure(user)
}

View File

@ -1,8 +1,8 @@
'use strict';
'use strict'
const globalHooks = require('../../../hooks');
const hooks = require('feathers-hooks');
const auth = require('feathers-authentication').hooks;
require('../../../hooks')
const hooks = require('feathers-hooks')
const auth = require('feathers-authentication').hooks
exports.before = {
all: [],
@ -38,7 +38,7 @@ exports.before = {
auth.restrictToAuthenticated(),
auth.restrictToOwner({ ownerField: '_id' })
]
};
}
exports.after = {
all: [hooks.remove('password')],
@ -48,4 +48,4 @@ exports.after = {
update: [],
patch: [],
remove: []
};
}

View File

@ -1,17 +1,17 @@
'use strict';
'use strict'
const path = require('path');
const NeDB = require('nedb');
const service = require('feathers-nedb');
const hooks = require('./hooks');
const path = require('path')
const NeDB = require('nedb')
const service = require('feathers-nedb')
const hooks = require('./hooks')
module.exports = function(){
const app = this;
module.exports = function () {
const app = this
const db = new NeDB({
filename: path.join(app.get('nedb'), 'users.db'),
autoload: true
});
})
let options = {
Model: db,
@ -19,17 +19,17 @@ module.exports = function(){
default: 5,
max: 25
}
};
}
// Initialize our service with any options it requires
app.use('/users', service(options));
app.use('/users', service(options))
// Get our initialize service to that we can bind hooks
const userService = app.service('/users');
const userService = app.service('/users')
// Set up our before hooks
userService.before(hooks.before);
userService.before(hooks.before)
// Set up our after hooks
userService.after(hooks.after);
};
userService.after(hooks.after)
}

View File

@ -1,38 +1,38 @@
'use strict';
'use strict'
const assert = require('assert');
const request = require('request');
const app = require('../src/app');
const assert = require('assert')
const request = require('request')
const app = require('../src/app')
describe('Feathers application tests', function() {
before(function(done) {
this.server = app.listen(3030);
this.server.once('listening', () => done());
});
describe('Feathers application tests', function () {
before(function (done) {
this.server = app.listen(3030)
this.server.once('listening', () => done())
})
after(function(done) {
this.server.close(done);
});
after(function (done) {
this.server.close(done)
})
it('starts and shows the index page', function(done) {
request('http://localhost:3030', function(err, res, body) {
assert.ok(body.indexOf('<h1>Welcome!</h1>') !== -1);
done(err);
});
});
it('starts and shows the index page', function (done) {
request('http://localhost:3030', function (err, res, body) {
assert.ok(body.indexOf('<h1>Welcome!</h1>') !== -1)
done(err)
})
})
describe('404', function() {
it('shows a 404 HTML page', function(done) {
describe('404', function () {
it('shows a 404 HTML page', function (done) {
request({
url: 'http://localhost:3030/path/to/nowhere',
headers: {
'Accept': 'text/html'
}
}, function(err, res, body) {
assert.equal(res.statusCode, 404);
assert.ok(body.indexOf('This page could not be found.') !== -1);
done(err);
});
});
});
});
}, function (err, res, body) {
assert.equal(res.statusCode, 404)
assert.ok(body.indexOf('This page could not be found.') !== -1)
done(err)
})
})
})
})

View File

@ -1,10 +1,10 @@
'use strict';
'use strict'
const assert = require('assert');
const app = require('../../../src/app');
const assert = require('assert')
const app = require('../../../src/app')
describe('user service', function() {
describe('user service', function () {
it('registered the users service', () => {
assert.ok(app.service('users'));
});
});
assert.ok(app.service('users'))
})
})

View File

@ -31,7 +31,7 @@
import axios from '~/plugins/axios'
export default {
async asyncData () {
async asyncData() {
const { data: users } = await axios.get('users.json')
return { users }
}

View File

@ -14,7 +14,7 @@
import axios from '~/plugins/axios'
export default {
async asyncData ({ route }) {
async asyncData({ route }) {
const { key } = route.params
const { data: user } = await axios.get(`users/${key}.json`)
return { user }

View File

@ -1,26 +1,26 @@
module.exports = {
head: {
meta: [
{
name: 'viewport',
content: 'width=device-width, initial-scale=1'
}
],
link: [
{
rel: 'stylesheet',
href:
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic'
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/icon?family=Material+Icons'
},
{
rel: 'stylesheet',
href: 'https://unpkg.com/muse-ui@2.1.0/dist/muse-ui.css'
}
]
},
plugins: ['~/plugins/museui']
};
head: {
meta: [
{
name: 'viewport',
content: 'width=device-width, initial-scale=1'
}
],
link: [
{
rel: 'stylesheet',
href:
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic'
},
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/icon?family=Material+Icons'
},
{
rel: 'stylesheet',
href: 'https://unpkg.com/muse-ui@2.1.0/dist/muse-ui.css'
}
]
},
plugins: ['~/plugins/museui']
}

View File

@ -23,16 +23,16 @@
<script>
export default {
data() {
return {
open: false
}
},
methods: {
toggle(flag) {
this.open = !this.open;
}
}
data() {
return {
open: false
}
},
methods: {
toggle(flag) {
this.open = !this.open
}
}
}
</script>

View File

@ -1,4 +1,4 @@
import Vue from 'vue';
import MuseUI from 'muse-ui';
import Vue from 'vue'
import MuseUI from 'muse-ui'
Vue.use(MuseUI);
Vue.use(MuseUI)

View File

@ -17,7 +17,7 @@
import socket from '~/plugins/socket.io.js'
export default {
asyncData (context, callback) {
asyncData(context, callback) {
socket.emit('last-messages', function (messages) {
callback(null, {
messages,
@ -28,16 +28,16 @@ export default {
watch: {
'messages': 'scrollToBottom'
},
beforeMount () {
beforeMount() {
socket.on('new-message', (message) => {
this.messages.push(message)
})
},
mounted () {
mounted() {
this.scrollToBottom()
},
methods: {
sendMessage () {
sendMessage() {
if (!this.message.trim()) return
let message = {
date: new Date().toJSON(),
@ -47,7 +47,7 @@ export default {
this.message = ''
socket.emit('send-message', message)
},
scrollToBottom () {
scrollToBottom() {
this.$nextTick(() => {
this.$refs.messages.scrollTop = this.$refs.messages.scrollHeight
})

View File

@ -7,14 +7,14 @@
<script>
export default {
data() {
return { name: 'world', className: 'red' }
},
methods: {
changeColor() {
this.className = this.className === 'red' ? 'blue' : 'green'
}
}
data() {
return { name: 'world', className: 'red' }
},
methods: {
changeColor() {
this.className = this.className === 'red' ? 'blue' : 'green'
}
}
}
</script>

View File

@ -3,41 +3,41 @@ import { shallow } from 'vue-test-utils'
import Index from '../pages/index.vue'
test('renders Index.vue correctly', t => {
t.plan(4)
t.plan(4)
const wrapper = shallow(Index, {
data: {
name: 'nuxt'
}
})
const wrapper = shallow(Index, {
data: {
name: 'nuxt'
}
})
const button = wrapper.find('button')
const button = wrapper.find('button')
t.equal(
wrapper.find('h1').text(),
'Hello nuxt!',
'renders "Hello nuxt!" text'
)
t.equal(
wrapper.find('h1').text(),
'Hello nuxt!',
'renders "Hello nuxt!" text'
)
t.equal(
wrapper.find('h1').hasClass('red'),
true,
'h1 has a red class [default]'
)
t.equal(
wrapper.find('h1').hasClass('red'),
true,
'h1 has a red class [default]'
)
button.trigger('click')
button.trigger('click')
t.equal(
wrapper.find('h1').hasClass('blue'),
true,
'h1 class changes to blue [after 1st click]'
)
t.equal(
wrapper.find('h1').hasClass('blue'),
true,
'h1 class changes to blue [after 1st click]'
)
button.trigger('click')
button.trigger('click')
t.equal(
wrapper.find('h1').hasClass('green'),
true,
'h1 class changes to green [after 2nd click]'
)
t.equal(
wrapper.find('h1').hasClass('green'),
true,
'h1 class changes to green [after 2nd click]'
)
})

View File

@ -5,10 +5,10 @@ require('browser-env')()
// Setup vue files to be processed by `require-extension-hooks-vue`
hooks('vue')
.plugin('vue')
.push()
.plugin('vue')
.push()
// Setup vue and js files to be processed by `require-extension-hooks-babel`
hooks(['vue', 'js'])
.plugin('babel')
.push()
.plugin('babel')
.push()

View File

@ -1,6 +1,3 @@
const { join } = require('path')
module.exports = {
/*
** Head elements

View File

@ -49,7 +49,7 @@
"scripts": {
"test": "npm run lint && cross-env NODE_ENV=test npm run build:nuxt && nyc ava --verbose --serial test/ -- && nyc report --reporter=html",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "eslint --ext .js,.vue bin/** lib/** test/** --ignore-pattern app --ignore-pattern node_modules --ignore-pattern dist/",
"lint": "eslint --ext .js,.vue bin/** lib/** test/*.js examples/**",
"build": "rimraf dist/ && npm run build:nuxt && npm run build:core",
"build:nuxt": "rollup -c build/rollup.config.js --environment TARGET:nuxt",
"build:core": "rollup -c build/rollup.config.js --environment TARGET:core",