/vue-starter-kit

🍍 Vue2 with webpack mock-server unit-test hot-loader

Primary LanguageVue

vue-starter-kit

A Vue.js project with mock-server and unit-test

components

plugins

  • toast

mock-server

we use json-server to get a full fake REST API, use mock.js to build mock data ( as local database :) ), for example:

// db.js
var Mock = require('mockjs');

module.exports = {
  project_comments: Mock.mock({
    "error": 0,
    "message": "success",
    "result|40": [{
      "author": "@name",
      "comment": "@cparagraph",
      "date": "@datetime"
    }]
  }),
  push_comment: Mock.mock({
    "error": 0,
    "message": "success",
    "result": []
  })
};
// routes.json
{
  "/project/:page/comments.action": "/project_comments?_page=:page&_limit=5",
  "/comment/add.action": "/push_comment"
}

unit test

test components and vuex( include mutations actions getters ), test result:

build setup

# install dependencies
npm install

# serve with hot reload at localhost:8181
npm run dev

# run mock server at localhost:3000
npm run mock

# run unit test
npm run test

# build for production with minification
npm run build

TODO

  • add vuex to manage app state
  • add unit test
  • refresh the mock server after modifying mock/db.js