Initial commit
This commit is contained in:
commit
a2b8fac903
18
.babelrc
Normal file
18
.babelrc
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
["env", {
|
||||||
|
"modules": false,
|
||||||
|
"targets": {
|
||||||
|
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"stage-2"
|
||||||
|
],
|
||||||
|
"plugins": ["transform-runtime"],
|
||||||
|
"env": {
|
||||||
|
"test": {
|
||||||
|
"presets": ["env", "stage-2"],
|
||||||
|
"plugins": ["istanbul"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
2
.eslintignore
Normal file
2
.eslintignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
build/*.js
|
||||||
|
config/*.js
|
41
.eslintrc.js
Normal file
41
.eslintrc.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// http://eslint.org/docs/user-guide/configuring
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
parser: 'babel-eslint',
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'module'
|
||||||
|
},
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
},
|
||||||
|
extends: 'airbnb-base',
|
||||||
|
// required to lint *.vue files
|
||||||
|
plugins: [
|
||||||
|
'html'
|
||||||
|
],
|
||||||
|
// check if imports actually resolve
|
||||||
|
'settings': {
|
||||||
|
'import/resolver': {
|
||||||
|
'webpack': {
|
||||||
|
'config': 'build/webpack.base.conf.js'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// add your custom rules here
|
||||||
|
'rules': {
|
||||||
|
// don't require .vue extension when importing
|
||||||
|
'import/extensions': ['error', 'always', {
|
||||||
|
'js': 'never',
|
||||||
|
'vue': 'never'
|
||||||
|
}],
|
||||||
|
// allow optionalDependencies
|
||||||
|
'import/no-extraneous-dependencies': ['error', {
|
||||||
|
'optionalDependencies': ['test/unit/index.js']
|
||||||
|
}],
|
||||||
|
// allow debugger during development
|
||||||
|
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
|
||||||
|
// Use 4 spaces indent
|
||||||
|
'indent': ['error', 4]
|
||||||
|
}
|
||||||
|
}
|
18
.gitignore
vendored
Normal file
18
.gitignore
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
.DS_Store
|
||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
test/unit/coverage
|
||||||
|
test/e2e/reports
|
||||||
|
selenium-debug.log
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.idea
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
|
||||||
|
build/
|
8
.postcssrc.js
Normal file
8
.postcssrc.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// https://github.com/michael-ciniawsky/postcss-load-config
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
"plugins": {
|
||||||
|
// to edit target browsers: use "browserslist" field in package.json
|
||||||
|
"autoprefixer": {}
|
||||||
|
}
|
||||||
|
}
|
30
README.md
Normal file
30
README.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# food
|
||||||
|
|
||||||
|
> A Vue.js project
|
||||||
|
|
||||||
|
## Build Setup
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# install dependencies
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# serve with hot reload at localhost:8080
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# build for production with minification
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# build for production and view the bundle analyzer report
|
||||||
|
npm run build --report
|
||||||
|
|
||||||
|
# run unit tests
|
||||||
|
npm run unit
|
||||||
|
|
||||||
|
# run e2e tests
|
||||||
|
npm run e2e
|
||||||
|
|
||||||
|
# run all tests
|
||||||
|
npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
|
6
config/dev.env.js
Normal file
6
config/dev.env.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
var merge = require('webpack-merge')
|
||||||
|
var prodEnv = require('./prod.env')
|
||||||
|
|
||||||
|
module.exports = merge(prodEnv, {
|
||||||
|
NODE_ENV: '"development"'
|
||||||
|
})
|
38
config/index.js
Normal file
38
config/index.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// see http://vuejs-templates.github.io/webpack for documentation.
|
||||||
|
var path = require('path')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
build: {
|
||||||
|
env: require('./prod.env'),
|
||||||
|
index: path.resolve(__dirname, '../dist/index.html'),
|
||||||
|
assetsRoot: path.resolve(__dirname, '../dist'),
|
||||||
|
assetsSubDirectory: 'static',
|
||||||
|
assetsPublicPath: '/',
|
||||||
|
productionSourceMap: true,
|
||||||
|
// Gzip off by default as many popular static hosts such as
|
||||||
|
// Surge or Netlify already gzip all static assets for you.
|
||||||
|
// Before setting to `true`, make sure to:
|
||||||
|
// npm install --save-dev compression-webpack-plugin
|
||||||
|
productionGzip: false,
|
||||||
|
productionGzipExtensions: ['js', 'css'],
|
||||||
|
// Run the build command with an extra argument to
|
||||||
|
// View the bundle analyzer report after build finishes:
|
||||||
|
// `npm run build --report`
|
||||||
|
// Set to `true` or `false` to always turn it on or off
|
||||||
|
bundleAnalyzerReport: process.env.npm_config_report
|
||||||
|
},
|
||||||
|
dev: {
|
||||||
|
env: require('./dev.env'),
|
||||||
|
port: 8080,
|
||||||
|
autoOpenBrowser: true,
|
||||||
|
assetsSubDirectory: 'static',
|
||||||
|
assetsPublicPath: '/',
|
||||||
|
proxyTable: {},
|
||||||
|
// CSS Sourcemaps off by default because relative paths are "buggy"
|
||||||
|
// with this option, according to the CSS-Loader README
|
||||||
|
// (https://github.com/webpack/css-loader#sourcemaps)
|
||||||
|
// In our experience, they generally work as expected,
|
||||||
|
// just be aware of this issue when enabling this option.
|
||||||
|
cssSourceMap: false
|
||||||
|
}
|
||||||
|
}
|
3
config/prod.env.js
Normal file
3
config/prod.env.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
NODE_ENV: '"production"'
|
||||||
|
}
|
6
config/test.env.js
Normal file
6
config/test.env.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
var merge = require('webpack-merge')
|
||||||
|
var devEnv = require('./dev.env')
|
||||||
|
|
||||||
|
module.exports = merge(devEnv, {
|
||||||
|
NODE_ENV: '"testing"'
|
||||||
|
})
|
12
index.html
Normal file
12
index.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Food</title>
|
||||||
|
<meta name="viewport" content="width=device-width, user-scalable=no">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<!-- built files will be auto injected -->
|
||||||
|
</body>
|
||||||
|
</html>
|
96
package.json
Normal file
96
package.json
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
{
|
||||||
|
"name": "food",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A Vue.js project",
|
||||||
|
"author": "Phyks (Lucas Verney) <phyks@phyks.me>",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "node build/dev-server.js",
|
||||||
|
"start": "node build/dev-server.js",
|
||||||
|
"build": "node build/build.js",
|
||||||
|
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
|
||||||
|
"e2e": "node test/e2e/runner.js",
|
||||||
|
"test": "npm run unit && npm run e2e",
|
||||||
|
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"quagga": "^0.12.1",
|
||||||
|
"vue": "^2.4.2",
|
||||||
|
"vue-router": "^2.7.0",
|
||||||
|
"webrtc-adapter": "^5.0.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"autoprefixer": "^7.1.2",
|
||||||
|
"babel-core": "^6.22.1",
|
||||||
|
"babel-eslint": "^7.1.1",
|
||||||
|
"babel-loader": "^7.1.1",
|
||||||
|
"babel-plugin-transform-runtime": "^6.22.0",
|
||||||
|
"babel-preset-env": "^1.3.2",
|
||||||
|
"babel-preset-stage-2": "^6.22.0",
|
||||||
|
"babel-register": "^6.22.0",
|
||||||
|
"chalk": "^2.0.1",
|
||||||
|
"connect-history-api-fallback": "^1.3.0",
|
||||||
|
"copy-webpack-plugin": "^4.0.1",
|
||||||
|
"css-loader": "^0.28.0",
|
||||||
|
"cssnano": "^3.10.0",
|
||||||
|
"eslint": "^3.19.0",
|
||||||
|
"eslint-friendly-formatter": "^3.0.0",
|
||||||
|
"eslint-loader": "^1.7.1",
|
||||||
|
"eslint-plugin-html": "^3.0.0",
|
||||||
|
"eslint-config-airbnb-base": "^11.1.3",
|
||||||
|
"eslint-import-resolver-webpack": "^0.8.1",
|
||||||
|
"eslint-plugin-import": "^2.2.0",
|
||||||
|
"eventsource-polyfill": "^0.9.6",
|
||||||
|
"express": "^4.14.1",
|
||||||
|
"extract-text-webpack-plugin": "^2.0.0",
|
||||||
|
"file-loader": "^0.11.1",
|
||||||
|
"friendly-errors-webpack-plugin": "^1.1.3",
|
||||||
|
"html-webpack-plugin": "^2.28.0",
|
||||||
|
"http-proxy-middleware": "^0.17.3",
|
||||||
|
"webpack-bundle-analyzer": "^2.2.1",
|
||||||
|
"cross-env": "^5.0.1",
|
||||||
|
"karma": "^1.4.1",
|
||||||
|
"karma-coverage": "^1.1.1",
|
||||||
|
"karma-mocha": "^1.3.0",
|
||||||
|
"karma-phantomjs-launcher": "^1.0.2",
|
||||||
|
"karma-phantomjs-shim": "^1.4.0",
|
||||||
|
"karma-sinon-chai": "^1.3.1",
|
||||||
|
"karma-sourcemap-loader": "^0.3.7",
|
||||||
|
"karma-spec-reporter": "0.0.31",
|
||||||
|
"karma-webpack": "^2.0.2",
|
||||||
|
"mocha": "^3.2.0",
|
||||||
|
"chai": "^3.5.0",
|
||||||
|
"sinon": "^2.1.0",
|
||||||
|
"sinon-chai": "^2.8.0",
|
||||||
|
"inject-loader": "^3.0.0",
|
||||||
|
"babel-plugin-istanbul": "^4.1.1",
|
||||||
|
"phantomjs-prebuilt": "^2.1.14",
|
||||||
|
"chromedriver": "^2.27.2",
|
||||||
|
"cross-spawn": "^5.0.1",
|
||||||
|
"nightwatch": "^0.9.12",
|
||||||
|
"selenium-server": "^3.0.1",
|
||||||
|
"semver": "^5.3.0",
|
||||||
|
"shelljs": "^0.7.6",
|
||||||
|
"opn": "^5.1.0",
|
||||||
|
"optimize-css-assets-webpack-plugin": "^2.0.0",
|
||||||
|
"ora": "^1.2.0",
|
||||||
|
"rimraf": "^2.6.0",
|
||||||
|
"url-loader": "^0.5.8",
|
||||||
|
"vue-loader": "^13.0.4",
|
||||||
|
"vue-style-loader": "^3.0.1",
|
||||||
|
"vue-template-compiler": "^2.4.2",
|
||||||
|
"webpack": "^2.6.1",
|
||||||
|
"webpack-dev-middleware": "^1.10.0",
|
||||||
|
"webpack-hot-middleware": "^2.18.0",
|
||||||
|
"webpack-merge": "^4.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 4.0.0",
|
||||||
|
"npm": ">= 3.0.0"
|
||||||
|
},
|
||||||
|
"browserslist": [
|
||||||
|
"> 1%",
|
||||||
|
"last 2 versions",
|
||||||
|
"not ie <= 8"
|
||||||
|
]
|
||||||
|
}
|
23
src/App.vue
Normal file
23
src/App.vue
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<template>
|
||||||
|
<div id="app">
|
||||||
|
<h1>Food scanning</h1>
|
||||||
|
<router-view></router-view>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'app',
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#app {
|
||||||
|
font-family: 'Avenir', Helvetica, Arial, sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
text-align: center;
|
||||||
|
color: #2c3e50;
|
||||||
|
margin-top: 60px;
|
||||||
|
}
|
||||||
|
</style>
|
BIN
src/assets/logo.png
Normal file
BIN
src/assets/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
12
src/components/Home.vue
Normal file
12
src/components/Home.vue
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<template>
|
||||||
|
<nav>
|
||||||
|
<ul>
|
||||||
|
<router-link to="scan">Scan something!</router-link>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
};
|
||||||
|
</script>
|
13
src/components/Product.vue
Normal file
13
src/components/Product.vue
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<template>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Barcode</th>
|
||||||
|
<td>{{ $route.params.barcode }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
};
|
||||||
|
</script>
|
19
src/components/Scan.vue
Normal file
19
src/components/Scan.vue
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<h2>Let's scan something!</h2>
|
||||||
|
|
||||||
|
<p>Loading scanning app…</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
mounted() {
|
||||||
|
// TODO: Rework this
|
||||||
|
const host = encodeURIComponent(`${window.location.protocol}//${window.location.host}`);
|
||||||
|
let href = this.$router.resolve({ name: 'Product', params: { barcode: 'CODE' } }).href;
|
||||||
|
href = encodeURIComponent(href.replace('CODE', '{CODE}'));
|
||||||
|
window.location = `zxing://scan/?ret=${host}${href}`;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
73
src/components/ScanQuagga.vue
Normal file
73
src/components/ScanQuagga.vue
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<h2>Let's scan something!</h2>
|
||||||
|
<h2>Found: {{ barcode }}</h2>
|
||||||
|
|
||||||
|
<div ref="video"></div>
|
||||||
|
<p v-if="!playing && error">{{ error }}</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import 'webrtc-adapter';
|
||||||
|
import Quagga from 'quagga';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
error: 'Video stream not available.',
|
||||||
|
playing: false,
|
||||||
|
barcode: 'Not found',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleBarcode(data) {
|
||||||
|
this.barcode = data.codeResult.code;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
const videoElement = this.$refs.video;
|
||||||
|
const barcodeHandler = this.handleBarcode;
|
||||||
|
|
||||||
|
Quagga.init({
|
||||||
|
inputStream: {
|
||||||
|
name: 'Scan',
|
||||||
|
type: 'LiveStream',
|
||||||
|
constraints: {
|
||||||
|
facingMode: 'environment',
|
||||||
|
},
|
||||||
|
target: videoElement,
|
||||||
|
},
|
||||||
|
decoder: {
|
||||||
|
readers: [
|
||||||
|
'ean_reader',
|
||||||
|
],
|
||||||
|
debug: {
|
||||||
|
drawBoundingBox: true,
|
||||||
|
showFrequency: true,
|
||||||
|
drawScanline: true,
|
||||||
|
showPattern: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, (err) => {
|
||||||
|
if (err) {
|
||||||
|
this.error = err.toString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Quagga.start();
|
||||||
|
Quagga.onDetected(barcodeHandler);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
Quagga.offDetected(this.handleBarcode);
|
||||||
|
Quagga.stop();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/*canvas.drawingBuffer {
|
||||||
|
display: none;
|
||||||
|
}*/
|
||||||
|
</style>
|
15
src/main.js
Normal file
15
src/main.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// The Vue build version to load with the `import` command
|
||||||
|
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
|
||||||
|
import Vue from 'vue';
|
||||||
|
import App from './App';
|
||||||
|
import router from './router';
|
||||||
|
|
||||||
|
Vue.config.productionTip = false;
|
||||||
|
|
||||||
|
/* eslint-disable no-new */
|
||||||
|
new Vue({
|
||||||
|
el: '#app',
|
||||||
|
router,
|
||||||
|
template: '<App/>',
|
||||||
|
components: { App },
|
||||||
|
});
|
28
src/router/index.js
Normal file
28
src/router/index.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
|
import Router from 'vue-router';
|
||||||
|
|
||||||
|
import Home from '@/components/Home';
|
||||||
|
import Scan from '@/components/Scan';
|
||||||
|
import Product from '@/components/Product';
|
||||||
|
|
||||||
|
Vue.use(Router);
|
||||||
|
|
||||||
|
export default new Router({
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
name: 'Home',
|
||||||
|
component: Home,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/scan',
|
||||||
|
name: 'Scan',
|
||||||
|
component: Scan,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/barcode/:barcode',
|
||||||
|
name: 'Product',
|
||||||
|
component: Product,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
0
static/.gitkeep
Normal file
0
static/.gitkeep
Normal file
26
test/e2e/custom-assertions/elementCount.js
Normal file
26
test/e2e/custom-assertions/elementCount.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// A custom Nightwatch assertion.
|
||||||
|
// the name of the method is the filename.
|
||||||
|
// can be used in tests like this:
|
||||||
|
//
|
||||||
|
// browser.assert.elementCount(selector, count)
|
||||||
|
//
|
||||||
|
// for how to write custom assertions see
|
||||||
|
// http://nightwatchjs.org/guide#writing-custom-assertions
|
||||||
|
exports.assertion = function (selector, count) {
|
||||||
|
this.message = 'Testing if element <' + selector + '> has count: ' + count;
|
||||||
|
this.expected = count;
|
||||||
|
this.pass = function (val) {
|
||||||
|
return val === this.expected;
|
||||||
|
}
|
||||||
|
this.value = function (res) {
|
||||||
|
return res.value;
|
||||||
|
}
|
||||||
|
this.command = function (cb) {
|
||||||
|
var self = this;
|
||||||
|
return this.api.execute(function (selector) {
|
||||||
|
return document.querySelectorAll(selector).length;
|
||||||
|
}, [selector], function (res) {
|
||||||
|
cb.call(self, res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
46
test/e2e/nightwatch.conf.js
Normal file
46
test/e2e/nightwatch.conf.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
require('babel-register')
|
||||||
|
var config = require('../../config')
|
||||||
|
|
||||||
|
// http://nightwatchjs.org/gettingstarted#settings-file
|
||||||
|
module.exports = {
|
||||||
|
src_folders: ['test/e2e/specs'],
|
||||||
|
output_folder: 'test/e2e/reports',
|
||||||
|
custom_assertions_path: ['test/e2e/custom-assertions'],
|
||||||
|
|
||||||
|
selenium: {
|
||||||
|
start_process: true,
|
||||||
|
server_path: require('selenium-server').path,
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: 4444,
|
||||||
|
cli_args: {
|
||||||
|
'webdriver.chrome.driver': require('chromedriver').path
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
test_settings: {
|
||||||
|
default: {
|
||||||
|
selenium_port: 4444,
|
||||||
|
selenium_host: 'localhost',
|
||||||
|
silent: true,
|
||||||
|
globals: {
|
||||||
|
devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
chrome: {
|
||||||
|
desiredCapabilities: {
|
||||||
|
browserName: 'chrome',
|
||||||
|
javascriptEnabled: true,
|
||||||
|
acceptSslCerts: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
firefox: {
|
||||||
|
desiredCapabilities: {
|
||||||
|
browserName: 'firefox',
|
||||||
|
javascriptEnabled: true,
|
||||||
|
acceptSslCerts: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
test/e2e/runner.js
Normal file
33
test/e2e/runner.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// 1. start the dev server using production config
|
||||||
|
process.env.NODE_ENV = 'testing';
|
||||||
|
var server = require('../../build/dev-server.js');
|
||||||
|
|
||||||
|
server.ready.then(() => {
|
||||||
|
// 2. run the nightwatch test suite against it
|
||||||
|
// to run in additional browsers:
|
||||||
|
// 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings"
|
||||||
|
// 2. add it to the --env flag below
|
||||||
|
// or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
|
||||||
|
// For more information on Nightwatch's config file, see
|
||||||
|
// http://nightwatchjs.org/guide#settings-file
|
||||||
|
var opts = process.argv.slice(2);
|
||||||
|
if (opts.indexOf('--config') === -1) {
|
||||||
|
opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']);
|
||||||
|
}
|
||||||
|
if (opts.indexOf('--env') === -1) {
|
||||||
|
opts = opts.concat(['--env', 'chrome']);
|
||||||
|
}
|
||||||
|
|
||||||
|
var spawn = require('cross-spawn');
|
||||||
|
var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' });
|
||||||
|
|
||||||
|
runner.on('exit', function (code) {
|
||||||
|
server.close();
|
||||||
|
process.exit(code);
|
||||||
|
});
|
||||||
|
|
||||||
|
runner.on('error', function (err) {
|
||||||
|
server.close();
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
});
|
19
test/e2e/specs/test.js
Normal file
19
test/e2e/specs/test.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// For authoring Nightwatch tests, see
|
||||||
|
// http://nightwatchjs.org/guide#usage
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
'default e2e tests': function test(browser) {
|
||||||
|
// automatically uses dev Server port from /config.index.js
|
||||||
|
// default: http://localhost:8080
|
||||||
|
// see nightwatch.conf.js
|
||||||
|
const devServer = browser.globals.devServerURL;
|
||||||
|
|
||||||
|
browser
|
||||||
|
.url(devServer)
|
||||||
|
.waitForElementVisible('#app', 5000)
|
||||||
|
.assert.elementPresent('.hello')
|
||||||
|
.assert.containsText('h1', 'Welcome to Your Vue.js App')
|
||||||
|
.assert.elementCount('img', 1)
|
||||||
|
.end();
|
||||||
|
},
|
||||||
|
};
|
9
test/unit/.eslintrc
Normal file
9
test/unit/.eslintrc
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"mocha": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"expect": true,
|
||||||
|
"sinon": true
|
||||||
|
}
|
||||||
|
}
|
13
test/unit/index.js
Normal file
13
test/unit/index.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
|
|
||||||
|
Vue.config.productionTip = false;
|
||||||
|
|
||||||
|
// require all test files (files that ends with .spec.js)
|
||||||
|
const testsContext = require.context('./specs', true, /\.spec$/);
|
||||||
|
testsContext.keys().forEach(testsContext);
|
||||||
|
|
||||||
|
// require all src files except main.js for coverage.
|
||||||
|
// you can also change this to match only the subset of files that
|
||||||
|
// you want coverage for.
|
||||||
|
const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/);
|
||||||
|
srcContext.keys().forEach(srcContext);
|
33
test/unit/karma.conf.js
Normal file
33
test/unit/karma.conf.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// This is a karma config file. For more details see
|
||||||
|
// http://karma-runner.github.io/0.13/config/configuration-file.html
|
||||||
|
// we are also using it with karma-webpack
|
||||||
|
// https://github.com/webpack/karma-webpack
|
||||||
|
|
||||||
|
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.
|
||||||
|
browsers: ['PhantomJS'],
|
||||||
|
frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'],
|
||||||
|
reporters: ['spec', 'coverage'],
|
||||||
|
files: ['./index.js'],
|
||||||
|
preprocessors: {
|
||||||
|
'./index.js': ['webpack', 'sourcemap']
|
||||||
|
},
|
||||||
|
webpack: webpackConfig,
|
||||||
|
webpackMiddleware: {
|
||||||
|
noInfo: true,
|
||||||
|
},
|
||||||
|
coverageReporter: {
|
||||||
|
dir: './coverage',
|
||||||
|
reporters: [
|
||||||
|
{ type: 'lcov', subdir: '.' },
|
||||||
|
{ type: 'text-summary' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
11
test/unit/specs/Hello.spec.js
Normal file
11
test/unit/specs/Hello.spec.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
|
import Hello from '@/components/Hello';
|
||||||
|
|
||||||
|
describe('Hello.vue', () => {
|
||||||
|
it('should render correct contents', () => {
|
||||||
|
const Constructor = Vue.extend(Hello);
|
||||||
|
const vm = new Constructor().$mount();
|
||||||
|
expect(vm.$el.querySelector('.hello h1').textContent)
|
||||||
|
.to.equal('Welcome to Your Vue.js App');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user