Laravel with vuejs unit test mocha-webpack script error

180 Views Asked by At

I am going to test vue components in Laravel application environment.

My package.json "scripts" are following:

   "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "test": "mocha-webpack --webpack-config=node_modules/laravel-mix/setup/webpack.config.js --require tests/Vue/setup.js tests/Vue/**/*.spec.js"
    },

When I ran "npm run test" it shows a callstack with following error. Did I do anything wrong?

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ test: `mocha-webpack --webpack-config=node_modules/laravel-mix/setup/webpack.config.js --require tests/Vue/setup.js tests/Vue/**/*.spec.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
1

There are 1 best solutions below

0
On

I think you have to setup laravel-mix webpackConfig.

Ex.

resolve: {
    alias: {
        '@': path.resolve(__dirname, 'resources/assets/'),
    },
},