Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
)
})
})
@PMK

This comment has been minimized.

Copy link
Owner Author

@PMK PMK commented May 23, 2018

Mocha works completely separate from Nuxt. Make sure the paths are correct in the code where you put these files in you project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.