Skip to content

Instantly share code, notes, and snippets.

@alexrusin
Created November 24, 2018 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexrusin/329b1f388abe51c3ff05a78beacff96e to your computer and use it in GitHub Desktop.
Save alexrusin/329b1f388abe51c3ff05a78beacff96e to your computer and use it in GitHub Desktop.
Laravel Vue testing set up
// package.json
{
"private": true,
"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/JavaScript/setup.js tests/JavaScript/**/*.spec.js"
},
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.25",
"axios": "^0.18",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"expect": "^23.6.0",
"jquery": "^3.2",
"jsdom": "^13.0.0",
"jsdom-global": "^3.0.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.5",
"mocha": "^4.0.1",
"mocha-webpack": "^0.7.0",
"popper.js": "^1.12",
"vue": "^2.5.17"
}
}
// tests/JavaScript/setup.js
require('jsdom-global')();
window.Date = Date; //temp fix for prettier error
// may also need todisable versioning in when testing
"scripts": {
// ...
"test": "cross-env NODE_ENV=test mocha-webpack --webpack-config=node_modules/laravel-mix/setup/webpack.config.js --require tests/JavaScript/setup.js tests/JavaScript/**/*.spec.js"
}
// in webpack.mix.js
if (process.env.NODE_ENV !== 'test') {
mix.version();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment