Skip to content

Commit

Permalink
Merge pull request misterGF#50 from Cambalab/fix_unit_tests
Browse files Browse the repository at this point in the history
Fix test unit run: example spec on 404 component
  • Loading branch information
misterGF authored Oct 2, 2017
2 parents 2ce2f21 + 05d0b2a commit 7a7289f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 52 deletions.
1 change: 1 addition & 0 deletions build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
'utils': resolve('src/utils')
}
},
module: {
Expand Down
4 changes: 4 additions & 0 deletions build/webpack.test.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ var webpackConfig = merge(baseConfig, {
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/test.env')
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
})
]
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"copy-webpack-plugin": "^4.0.1",
"cross-env": "^3.1.4",
"css-loader": "^0.26.1",
"es6-promise": "^4.1.0",
"eslint": "^3.14.1",
"eslint-config-standard": "^6.2.1",
"eslint-friendly-formatter": "^2.0.7",
Expand All @@ -66,7 +67,6 @@
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"inject-loader": "^2.0.1",
"isparta-loader": "^2.0.0",
"json-loader": "^0.5.4",
"karma": "^1.4.1",
"karma-coverage": "^1.1.1",
Expand Down Expand Up @@ -110,4 +110,4 @@
"last 2 versions",
"not ie <= 8"
]
}
}
6 changes: 5 additions & 1 deletion test/unit/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"env": {
"jasmine": true
"mocha": true
},
"globals": {
"expect": true,
"sinon": true
}
}
2 changes: 2 additions & 0 deletions test/unit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* eslint-disable no-extend-native */
Function.prototype.bind = require('function-bind')

require('es6-promise').polyfill()

// require all test files (files that ends with .spec.js)
var testsContext = require.context('./specs', true, /\.spec$/)
testsContext.keys().forEach(testsContext)
Expand Down
37 changes: 3 additions & 34 deletions test/unit/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,17 @@
// we are also using it with karma-webpack
// https://github.com/webpack/karma-webpack

var path = require('path')
var merge = require('webpack-merge')
var baseConfig = require('../../build/webpack.base.conf')
var projectRoot = path.resolve(__dirname, '../../')

var webpackConfig = merge(baseConfig, {
// use inline sourcemap for karma-sourcemap-loader
devtool: '#inline-source-map',
vue: {
loaders: {
js: 'isparta'
}
}
})

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

// make sure isparta loader is applied before eslint
webpackConfig.module.preLoaders.unshift({
test: /\.js$/,
loader: 'isparta',
include: projectRoot,
exclude: /test\/unit|node_modules/
})

// only apply babel for test files when using isparta
webpackConfig.module.loaders.some(function (loader, i) {
if (loader.loader === 'babel') {
loader.include = /test\/unit/
return true
}
})
var webpackConfig = require('../../build/webpack.test.conf')

module.exports = function (config) {
config.set({
// to run in additional browsers:
// 1. install corresponding karma launcher
// http://karma-runner.github.io/0.13/config/browsers.html
// 2. add it to the `browsers` array below.
logLevel: config.LOG_INFO,
browsers: ['PhantomJS'],
frameworks: ['jasmine'],
frameworks: ['mocha', 'sinon-chai'],
reporters: ['spec', 'coverage'],
files: ['./index.js'],
preprocessors: {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/specs/404.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Vue from 'vue'
import c404 from '@/components/404.vue'

describe('404.vue', () => {
it('should render correct contents', () => {
const Constructor = Vue.extend(c404)
const vm = new Constructor().$mount()
expect(vm.$el.querySelector('h1').textContent)
.to.equal('You are lost.')
})
})
15 changes: 0 additions & 15 deletions test/unit/specs/Hello.spec.js

This file was deleted.

0 comments on commit 7a7289f

Please sign in to comment.