commit a2b8fac903cf132b4dd9a34d6d0e3a66d3607297 Author: Phyks (Lucas Verney) Date: Tue Sep 19 02:41:00 2017 +0200 Initial commit diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..c06df4d --- /dev/null +++ b/.babelrc @@ -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"] + } + } +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9d08a1a --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..34af377 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +build/*.js +config/*.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..d859677 --- /dev/null +++ b/.eslintrc.js @@ -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] + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f949f5b --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/.postcssrc.js b/.postcssrc.js new file mode 100644 index 0000000..09948d6 --- /dev/null +++ b/.postcssrc.js @@ -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": {} + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..21d4c20 --- /dev/null +++ b/README.md @@ -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). diff --git a/config/dev.env.js b/config/dev.env.js new file mode 100644 index 0000000..efead7c --- /dev/null +++ b/config/dev.env.js @@ -0,0 +1,6 @@ +var merge = require('webpack-merge') +var prodEnv = require('./prod.env') + +module.exports = merge(prodEnv, { + NODE_ENV: '"development"' +}) diff --git a/config/index.js b/config/index.js new file mode 100644 index 0000000..196da1f --- /dev/null +++ b/config/index.js @@ -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 + } +} diff --git a/config/prod.env.js b/config/prod.env.js new file mode 100644 index 0000000..773d263 --- /dev/null +++ b/config/prod.env.js @@ -0,0 +1,3 @@ +module.exports = { + NODE_ENV: '"production"' +} diff --git a/config/test.env.js b/config/test.env.js new file mode 100644 index 0000000..89f90de --- /dev/null +++ b/config/test.env.js @@ -0,0 +1,6 @@ +var merge = require('webpack-merge') +var devEnv = require('./dev.env') + +module.exports = merge(devEnv, { + NODE_ENV: '"testing"' +}) diff --git a/index.html b/index.html new file mode 100644 index 0000000..478b06e --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + + + + Food + + + +
+ + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..71b7461 --- /dev/null +++ b/package.json @@ -0,0 +1,96 @@ +{ + "name": "food", + "version": "1.0.0", + "description": "A Vue.js project", + "author": "Phyks (Lucas Verney) ", + "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" + ] +} diff --git a/src/App.vue b/src/App.vue new file mode 100644 index 0000000..a2710f5 --- /dev/null +++ b/src/App.vue @@ -0,0 +1,23 @@ + + + + + diff --git a/src/assets/logo.png b/src/assets/logo.png new file mode 100644 index 0000000..f3d2503 Binary files /dev/null and b/src/assets/logo.png differ diff --git a/src/components/Home.vue b/src/components/Home.vue new file mode 100644 index 0000000..daf02cf --- /dev/null +++ b/src/components/Home.vue @@ -0,0 +1,12 @@ + + + diff --git a/src/components/Product.vue b/src/components/Product.vue new file mode 100644 index 0000000..351dda6 --- /dev/null +++ b/src/components/Product.vue @@ -0,0 +1,13 @@ + + + diff --git a/src/components/Scan.vue b/src/components/Scan.vue new file mode 100644 index 0000000..f6b7ae8 --- /dev/null +++ b/src/components/Scan.vue @@ -0,0 +1,19 @@ + + + diff --git a/src/components/ScanQuagga.vue b/src/components/ScanQuagga.vue new file mode 100644 index 0000000..7e1ee82 --- /dev/null +++ b/src/components/ScanQuagga.vue @@ -0,0 +1,73 @@ + + + + + diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..f4de9a7 --- /dev/null +++ b/src/main.js @@ -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: '', + components: { App }, +}); diff --git a/src/router/index.js b/src/router/index.js new file mode 100644 index 0000000..74a1b92 --- /dev/null +++ b/src/router/index.js @@ -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, + }, + ], +}); diff --git a/static/.gitkeep b/static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/e2e/custom-assertions/elementCount.js b/test/e2e/custom-assertions/elementCount.js new file mode 100644 index 0000000..696a367 --- /dev/null +++ b/test/e2e/custom-assertions/elementCount.js @@ -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); + }); + } +} diff --git a/test/e2e/nightwatch.conf.js b/test/e2e/nightwatch.conf.js new file mode 100644 index 0000000..f019c0a --- /dev/null +++ b/test/e2e/nightwatch.conf.js @@ -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 + } + } + } +} diff --git a/test/e2e/runner.js b/test/e2e/runner.js new file mode 100644 index 0000000..2702f50 --- /dev/null +++ b/test/e2e/runner.js @@ -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; + }); +}); diff --git a/test/e2e/specs/test.js b/test/e2e/specs/test.js new file mode 100644 index 0000000..ee3514e --- /dev/null +++ b/test/e2e/specs/test.js @@ -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(); + }, +}; diff --git a/test/unit/.eslintrc b/test/unit/.eslintrc new file mode 100644 index 0000000..959a4f4 --- /dev/null +++ b/test/unit/.eslintrc @@ -0,0 +1,9 @@ +{ + "env": { + "mocha": true + }, + "globals": { + "expect": true, + "sinon": true + } +} diff --git a/test/unit/index.js b/test/unit/index.js new file mode 100644 index 0000000..b31d3a0 --- /dev/null +++ b/test/unit/index.js @@ -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); diff --git a/test/unit/karma.conf.js b/test/unit/karma.conf.js new file mode 100644 index 0000000..ec3379c --- /dev/null +++ b/test/unit/karma.conf.js @@ -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' }, + ] + }, + }); +}; diff --git a/test/unit/specs/Hello.spec.js b/test/unit/specs/Hello.spec.js new file mode 100644 index 0000000..d660a5a --- /dev/null +++ b/test/unit/specs/Hello.spec.js @@ -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'); + }); +});