Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
doabit committed Aug 8, 2016
1 parent 184ac96 commit 81efc25
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
9 changes: 9 additions & 0 deletions build/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ module.exports = {
publicPath: '/dist/',
filename: 'client-bundle.js'
},
resolve: {
extensions: ['', '.js', '.vue'],
fallback: [path.join(__dirname, '../node_modules')],
alias: {
'src': path.resolve(__dirname, '../src'),
'assets': path.resolve(__dirname, '../src/assets'),
'components': path.resolve(__dirname, '../src/components')
}
},
resolveLoader: {
root: path.join(__dirname, '../node_modules'),
},
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"dev": "node server",
"build:client": "NODE_ENV=production webpack --config ./build/webpack.client.config.js --progress --hide-modules",
"build:server": "NODE_ENV=production webpack --config ./build/webpack.server.config.js --progress --hide-modules",
"build": "npm run build:client && npm run build:server"
"build": "npm run build:client && npm run build:server",
"unit": "karma start ./test/unit/karma.conf.js"
},
"dependencies": {
"axios": "^0.13.1",
Expand Down Expand Up @@ -56,6 +57,14 @@
"eslint-plugin-standard": "^2.0.0",
"extract-text-webpack-plugin": "^2.0.0-beta.3",
"file-loader": "^0.8.4",
"karma": "^1.1.2",
"karma-mocha": "^1.1.1",
"karma-phantomjs-launcher": "^1.0.1",
"karma-sinon-chai": "^1.2.3",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.26",
"karma-webpack": "^1.8.0",
"phantomjs-prebuilt": "^2.1.10",
"vue-loader": "^9.2.2",
"webpack": "^2.1.0-beta.20",
"webpack-dev-middleware": "^1.6.1",
Expand Down
9 changes: 9 additions & 0 deletions test/unit/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"env": {
"mocha": true
},
"globals": {
"expect": true,
"sinon": true
}
}
3 changes: 3 additions & 0 deletions test/unit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// require all test files (files that ends with .spec.js)
var testsContext = require.context('./specs', true, /\.spec$/)
testsContext.keys().forEach(testsContext)
29 changes: 29 additions & 0 deletions test/unit/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const baseConfig = require('../../build/webpack.base.config')
const webpack = require('webpack')
const webpackConfig = Object.assign({}, baseConfig, {
devtool: '#inline-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"test"'
})
]
})

// no need for app entry during tests
delete webpackConfig.entry

module.exports = function (config) {
config.set({
browsers: ['PhantomJS'],
frameworks: ['mocha', 'sinon-chai'],
reporters: ['spec'],
files: ['./index.js'],
preprocessors: {
'./index.js': ['webpack', 'sourcemap']
},
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true
}
})
}
9 changes: 9 additions & 0 deletions test/unit/specs/Home.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Vue from 'vue'
import Home from 'components/Home'

describe('Home.vue', () => {
it('should render correct home contents', () => {
const vm = new Vue(Home).$mount()
expect(vm.$el.textContent).to.contain('Home')
})
})

0 comments on commit 81efc25

Please sign in to comment.