Skip to content

Instantly share code, notes, and snippets.

@imrvelj
Forked from PMK/TestComponent.test.js
Created January 31, 2020 13:25
Show Gist options
  • Save imrvelj/2630f60f0e7fc1da6a8af4fe5ad9d6d3 to your computer and use it in GitHub Desktop.
Save imrvelj/2630f60f0e7fc1da6a8af4fe5ad9d6d3 to your computer and use it in GitHub Desktop.
Mocha-webpack with Vue
require('browser-env')()
const Vue = require('vue')
Vue.config.productionTip = false
// more options for Vue?
module.exports = {
output: {
// use absolute paths in sourcemaps (important for debugging via IDE)
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
},
module: {
rules: [
{
test: /\.js$|\.vue$/,
use: {
loader: 'istanbul-instrumenter-loader',
options: { esModules: true }
},
enforce: 'post',
exclude: /node_modules|\.spec\.js$/
},
{
test: /\.vue$/,
loader: 'vue-loader',
exclude: /node_modules/,
options: {
optimizeSSR: false,
loaders: {
scss: ['vue-style-loader', 'css-loader']
}
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
},
devServer: {
historyApiFallback: true,
noInfo: true
},
performance: {
hints: false
},
externals: [require('webpack-node-externals')()], // in order to ignore all modules in node_modules folder
devtool: 'inline-cheap-module-source-map',
target: 'node' // webpack should compile node compatible code
}
{
"scripts": {
"test": "NODE_ENV=test nyc --clean mocha-webpack --webpack-config ./mocha-webpack.config.js --colors --require ./test/_helpers/mocha-setup.js ./test/**/*.spec.js"
},
"devDependencies": {
"@vue/test-utils": "^v1.0.0-beta.16",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"browser-env": "^3.2.5",
"chai": "^4.1.2",
"istanbul-instrumenter-loader": "^3.0.0",
"mocha": "^5.1.1",
"mocha-webpack": "^1.0.1",
"nyc": "^11.8.0",
"vue-webpack-loaders": "^1.0.6",
"webpack-node-externals": "^1.6.0"
},
"nyc": {
"include": [
"src/**/*.(js|vue)"
],
"instrument": false,
"sourceMap": false
}
}
import { mount } from '@vue/test-utils'
import { assert } from 'chai'
import Component from '../../../../src/components/TestComponent.vue'
describe('TestComponent.vue', () => {
it('renders', () => {
const wrapper = mount(Component)
assert.isTrue(
wrapper.is(true)
)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment