Browse Source

First mockup

Phyks (Lucas Verney) 2 years ago
commit
ff591aafb1

+ 18
- 0
.babelrc View File

@@ -0,0 +1,18 @@
1
+{
2
+  "presets": [
3
+    ["env", {
4
+      "modules": false,
5
+      "targets": {
6
+        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7
+      }
8
+    }],
9
+    "stage-2"
10
+  ],
11
+  "plugins": ["transform-runtime"],
12
+  "env": {
13
+    "test": {
14
+      "presets": ["env", "stage-2"],
15
+      "plugins": ["istanbul"]
16
+    }
17
+  }
18
+}

+ 9
- 0
.editorconfig View File

@@ -0,0 +1,9 @@
1
+root = true
2
+
3
+[*]
4
+charset = utf-8
5
+indent_style = space
6
+indent_size = 2
7
+end_of_line = lf
8
+insert_final_newline = true
9
+trim_trailing_whitespace = true

+ 2
- 0
.eslintignore View File

@@ -0,0 +1,2 @@
1
+build/*.js
2
+config/*.js

+ 49
- 0
.eslintrc.js View File

@@ -0,0 +1,49 @@
1
+// http://eslint.org/docs/user-guide/configuring
2
+
3
+module.exports = {
4
+  root: true,
5
+  parser: 'babel-eslint',
6
+  parserOptions: {
7
+    sourceType: 'module'
8
+  },
9
+  env: {
10
+    browser: true,
11
+  },
12
+  extends: 'airbnb-base',
13
+  // required to lint *.vue files
14
+  plugins: [
15
+    'html'
16
+  ],
17
+  // check if imports actually resolve
18
+  'settings': {
19
+    'import/resolver': {
20
+      'webpack': {
21
+        'config': 'build/webpack.base.conf.js'
22
+      }
23
+    }
24
+  },
25
+  // add your custom rules here
26
+  'rules': {
27
+    // don't require .vue extension when importing
28
+    'import/extensions': ['error', 'always', {
29
+      'js': 'never',
30
+      'vue': 'never'
31
+    }],
32
+    // allow optionalDependencies
33
+    'import/no-extraneous-dependencies': ['error', {
34
+      'optionalDependencies': ['test/unit/index.js']
35
+    }],
36
+    // allow debugger during development
37
+    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
38
+    // Use 4 spaces indent
39
+    'indent': ['error', 4],
40
+    // Ignore assignment to state
41
+    'no-param-reassign': [
42
+        "error",
43
+        {
44
+            "props": true,
45
+            "ignorePropertyModificationsFor": ["state"]
46
+        }
47
+    ],
48
+  }
49
+}

+ 16
- 0
.gitignore View File

@@ -0,0 +1,16 @@
1
+.DS_Store
2
+node_modules/
3
+dist/
4
+npm-debug.log*
5
+yarn-debug.log*
6
+yarn-error.log*
7
+test/unit/coverage
8
+test/e2e/reports
9
+selenium-debug.log
10
+
11
+# Editor directories and files
12
+.idea
13
+*.suo
14
+*.ntvs*
15
+*.njsproj
16
+*.sln

+ 8
- 0
.postcssrc.js View File

@@ -0,0 +1,8 @@
1
+// https://github.com/michael-ciniawsky/postcss-load-config
2
+
3
+module.exports = {
4
+  "plugins": {
5
+    // to edit target browsers: use "browserslist" field in package.json
6
+    "autoprefixer": {}
7
+  }
8
+}

+ 30
- 0
README.md View File

@@ -0,0 +1,30 @@
1
+# hungergames
2
+
3
+> OpenFoodFacts gamification
4
+
5
+## Build Setup
6
+
7
+``` bash
8
+# install dependencies
9
+npm install
10
+
11
+# serve with hot reload at localhost:8080
12
+npm run dev
13
+
14
+# build for production with minification
15
+npm run build
16
+
17
+# build for production and view the bundle analyzer report
18
+npm run build --report
19
+
20
+# run unit tests
21
+npm run unit
22
+
23
+# run e2e tests
24
+npm run e2e
25
+
26
+# run all tests
27
+npm test
28
+```
29
+
30
+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).

+ 40
- 0
build/build.js View File

@@ -0,0 +1,40 @@
1
+require('./check-versions')()
2
+
3
+process.env.NODE_ENV = 'production'
4
+
5
+var ora = require('ora')
6
+var rm = require('rimraf')
7
+var path = require('path')
8
+var chalk = require('chalk')
9
+var webpack = require('webpack')
10
+var config = require('../config')
11
+var webpackConfig = require('./webpack.prod.conf')
12
+
13
+var spinner = ora('building for production...')
14
+spinner.start()
15
+
16
+rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
17
+  if (err) throw err
18
+  webpack(webpackConfig, function (err, stats) {
19
+    spinner.stop()
20
+    if (err) throw err
21
+    process.stdout.write(stats.toString({
22
+      colors: true,
23
+      modules: false,
24
+      children: false,
25
+      chunks: false,
26
+      chunkModules: false
27
+    }) + '\n\n')
28
+
29
+    if (stats.hasErrors()) {
30
+      console.log(chalk.red('  Build failed with errors.\n'))
31
+      process.exit(1)
32
+    }
33
+
34
+    console.log(chalk.cyan('  Build complete.\n'))
35
+    console.log(chalk.yellow(
36
+      '  Tip: built files are meant to be served over an HTTP server.\n' +
37
+      '  Opening index.html over file:// won\'t work.\n'
38
+    ))
39
+  })
40
+})

+ 48
- 0
build/check-versions.js View File

@@ -0,0 +1,48 @@
1
+var chalk = require('chalk')
2
+var semver = require('semver')
3
+var packageConfig = require('../package.json')
4
+var shell = require('shelljs')
5
+function exec (cmd) {
6
+  return require('child_process').execSync(cmd).toString().trim()
7
+}
8
+
9
+var versionRequirements = [
10
+  {
11
+    name: 'node',
12
+    currentVersion: semver.clean(process.version),
13
+    versionRequirement: packageConfig.engines.node
14
+  }
15
+]
16
+
17
+if (shell.which('npm')) {
18
+  versionRequirements.push({
19
+    name: 'npm',
20
+    currentVersion: exec('npm --version'),
21
+    versionRequirement: packageConfig.engines.npm
22
+  })
23
+}
24
+
25
+module.exports = function () {
26
+  var warnings = []
27
+  for (var i = 0; i < versionRequirements.length; i++) {
28
+    var mod = versionRequirements[i]
29
+    if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
30
+      warnings.push(mod.name + ': ' +
31
+        chalk.red(mod.currentVersion) + ' should be ' +
32
+        chalk.green(mod.versionRequirement)
33
+      )
34
+    }
35
+  }
36
+
37
+  if (warnings.length) {
38
+    console.log('')
39
+    console.log(chalk.yellow('To use this template, you must update following to modules:'))
40
+    console.log()
41
+    for (var i = 0; i < warnings.length; i++) {
42
+      var warning = warnings[i]
43
+      console.log('  ' + warning)
44
+    }
45
+    console.log()
46
+    process.exit(1)
47
+  }
48
+}

+ 9
- 0
build/dev-client.js View File

@@ -0,0 +1,9 @@
1
+/* eslint-disable */
2
+require('eventsource-polyfill')
3
+var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
4
+
5
+hotClient.subscribe(function (event) {
6
+  if (event.action === 'reload') {
7
+    window.location.reload()
8
+  }
9
+})

+ 92
- 0
build/dev-server.js View File

@@ -0,0 +1,92 @@
1
+require('./check-versions')()
2
+
3
+var config = require('../config')
4
+if (!process.env.NODE_ENV) {
5
+  process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
6
+}
7
+
8
+var opn = require('opn')
9
+var path = require('path')
10
+var express = require('express')
11
+var webpack = require('webpack')
12
+var proxyMiddleware = require('http-proxy-middleware')
13
+var webpackConfig = (process.env.NODE_ENV === 'testing' || process.env.NODE_ENV === 'production')
14
+  ? require('./webpack.prod.conf')
15
+  : require('./webpack.dev.conf')
16
+
17
+// default port where dev server listens for incoming traffic
18
+var port = process.env.PORT || config.dev.port
19
+// automatically open browser, if not set will be false
20
+var autoOpenBrowser = !!config.dev.autoOpenBrowser
21
+// Define HTTP proxies to your custom API backend
22
+// https://github.com/chimurai/http-proxy-middleware
23
+var proxyTable = config.dev.proxyTable
24
+
25
+var app = express()
26
+var compiler = webpack(webpackConfig)
27
+
28
+var devMiddleware = require('webpack-dev-middleware')(compiler, {
29
+  publicPath: webpackConfig.output.publicPath,
30
+  quiet: true
31
+})
32
+
33
+var hotMiddleware = require('webpack-hot-middleware')(compiler, {
34
+  log: false,
35
+  heartbeat: 2000
36
+})
37
+// force page reload when html-webpack-plugin template changes
38
+compiler.plugin('compilation', function (compilation) {
39
+  compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
40
+    hotMiddleware.publish({ action: 'reload' })
41
+    cb()
42
+  })
43
+})
44
+
45
+// proxy api requests
46
+Object.keys(proxyTable).forEach(function (context) {
47
+  var options = proxyTable[context]
48
+  if (typeof options === 'string') {
49
+    options = { target: options }
50
+  }
51
+  app.use(proxyMiddleware(options.filter || context, options))
52
+})
53
+
54
+// handle fallback for HTML5 history API
55
+app.use(require('connect-history-api-fallback')())
56
+
57
+// serve webpack bundle output
58
+app.use(devMiddleware)
59
+
60
+// enable hot-reload and state-preserving
61
+// compilation error display
62
+app.use(hotMiddleware)
63
+
64
+// serve pure static assets
65
+var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
66
+app.use(staticPath, express.static('./static'))
67
+
68
+var uri = 'http://localhost:' + port
69
+
70
+var _resolve
71
+var readyPromise = new Promise(resolve => {
72
+  _resolve = resolve
73
+})
74
+
75
+console.log('> Starting dev server...')
76
+devMiddleware.waitUntilValid(() => {
77
+  console.log('> Listening at ' + uri + '\n')
78
+  // when env is testing, don't need open it
79
+  if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
80
+    opn(uri)
81
+  }
82
+  _resolve()
83
+})
84
+
85
+var server = app.listen(port)
86
+
87
+module.exports = {
88
+  ready: readyPromise,
89
+  close: () => {
90
+    server.close()
91
+  }
92
+}

+ 71
- 0
build/utils.js View File

@@ -0,0 +1,71 @@
1
+var path = require('path')
2
+var config = require('../config')
3
+var ExtractTextPlugin = require('extract-text-webpack-plugin')
4
+
5
+exports.assetsPath = function (_path) {
6
+  var assetsSubDirectory = process.env.NODE_ENV === 'production'
7
+    ? config.build.assetsSubDirectory
8
+    : config.dev.assetsSubDirectory
9
+  return path.posix.join(assetsSubDirectory, _path)
10
+}
11
+
12
+exports.cssLoaders = function (options) {
13
+  options = options || {}
14
+
15
+  var cssLoader = {
16
+    loader: 'css-loader',
17
+    options: {
18
+      minimize: process.env.NODE_ENV === 'production',
19
+      sourceMap: options.sourceMap
20
+    }
21
+  }
22
+
23
+  // generate loader string to be used with extract text plugin
24
+  function generateLoaders (loader, loaderOptions) {
25
+    var loaders = [cssLoader]
26
+    if (loader) {
27
+      loaders.push({
28
+        loader: loader + '-loader',
29
+        options: Object.assign({}, loaderOptions, {
30
+          sourceMap: options.sourceMap
31
+        })
32
+      })
33
+    }
34
+
35
+    // Extract CSS when that option is specified
36
+    // (which is the case during production build)
37
+    if (options.extract) {
38
+      return ExtractTextPlugin.extract({
39
+        use: loaders,
40
+        fallback: 'vue-style-loader'
41
+      })
42
+    } else {
43
+      return ['vue-style-loader'].concat(loaders)
44
+    }
45
+  }
46
+
47
+  // https://vue-loader.vuejs.org/en/configurations/extract-css.html
48
+  return {
49
+    css: generateLoaders(),
50
+    postcss: generateLoaders(),
51
+    less: generateLoaders('less'),
52
+    sass: generateLoaders('sass', { indentedSyntax: true }),
53
+    scss: generateLoaders('sass'),
54
+    stylus: generateLoaders('stylus'),
55
+    styl: generateLoaders('stylus')
56
+  }
57
+}
58
+
59
+// Generate loaders for standalone style files (outside of .vue)
60
+exports.styleLoaders = function (options) {
61
+  var output = []
62
+  var loaders = exports.cssLoaders(options)
63
+  for (var extension in loaders) {
64
+    var loader = loaders[extension]
65
+    output.push({
66
+      test: new RegExp('\\.' + extension + '$'),
67
+      use: loader
68
+    })
69
+  }
70
+  return output
71
+}

+ 18
- 0
build/vue-loader.conf.js View File

@@ -0,0 +1,18 @@
1
+var utils = require('./utils')
2
+var config = require('../config')
3
+var isProduction = process.env.NODE_ENV === 'production'
4
+
5
+module.exports = {
6
+  loaders: utils.cssLoaders({
7
+    sourceMap: isProduction
8
+      ? config.build.productionSourceMap
9
+      : config.dev.cssSourceMap,
10
+    extract: isProduction
11
+  }),
12
+  transformToRequire: {
13
+    video: 'src',
14
+    source: 'src',
15
+    img: 'src',
16
+    image: 'xlink:href'
17
+  }
18
+}

+ 75
- 0
build/webpack.base.conf.js View File

@@ -0,0 +1,75 @@
1
+var path = require('path')
2
+var utils = require('./utils')
3
+var config = require('../config')
4
+var vueLoaderConfig = require('./vue-loader.conf')
5
+
6
+function resolve (dir) {
7
+  return path.join(__dirname, '..', dir)
8
+}
9
+
10
+module.exports = {
11
+  entry: {
12
+    app: './src/main.js'
13
+  },
14
+  output: {
15
+    path: config.build.assetsRoot,
16
+    filename: '[name].js',
17
+    publicPath: process.env.NODE_ENV === 'production'
18
+      ? config.build.assetsPublicPath
19
+      : config.dev.assetsPublicPath
20
+  },
21
+  resolve: {
22
+    extensions: ['.js', '.vue', '.json'],
23
+    alias: {
24
+      'vue$': 'vue/dist/vue.esm.js',
25
+      '@': resolve('src'),
26
+    }
27
+  },
28
+  module: {
29
+    rules: [
30
+      {
31
+        test: /\.(js|vue)$/,
32
+        loader: 'eslint-loader',
33
+        enforce: 'pre',
34
+        include: [resolve('src'), resolve('test')],
35
+        options: {
36
+          formatter: require('eslint-friendly-formatter')
37
+        }
38
+      },
39
+      {
40
+        test: /\.vue$/,
41
+        loader: 'vue-loader',
42
+        options: vueLoaderConfig
43
+      },
44
+      {
45
+        test: /\.js$/,
46
+        loader: 'babel-loader',
47
+        include: [resolve('src'), resolve('test')]
48
+      },
49
+      {
50
+        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
51
+        loader: 'url-loader',
52
+        options: {
53
+          limit: 10000,
54
+          name: utils.assetsPath('img/[name].[hash:7].[ext]')
55
+        }
56
+      },
57
+      {
58
+        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
59
+        loader: 'url-loader',
60
+        options: {
61
+          limit: 10000,
62
+          name: utils.assetsPath('media/[name].[hash:7].[ext]')
63
+        }
64
+      },
65
+      {
66
+        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
67
+        loader: 'url-loader',
68
+        options: {
69
+          limit: 10000,
70
+          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
71
+        }
72
+      }
73
+    ]
74
+  }
75
+}

+ 35
- 0
build/webpack.dev.conf.js View File

@@ -0,0 +1,35 @@
1
+var utils = require('./utils')
2
+var webpack = require('webpack')
3
+var config = require('../config')
4
+var merge = require('webpack-merge')
5
+var baseWebpackConfig = require('./webpack.base.conf')
6
+var HtmlWebpackPlugin = require('html-webpack-plugin')
7
+var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
8
+
9
+// add hot-reload related code to entry chunks
10
+Object.keys(baseWebpackConfig.entry).forEach(function (name) {
11
+  baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
12
+})
13
+
14
+module.exports = merge(baseWebpackConfig, {
15
+  module: {
16
+    rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
17
+  },
18
+  // cheap-module-eval-source-map is faster for development
19
+  devtool: '#cheap-module-eval-source-map',
20
+  plugins: [
21
+    new webpack.DefinePlugin({
22
+      'process.env': config.dev.env
23
+    }),
24
+    // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
25
+    new webpack.HotModuleReplacementPlugin(),
26
+    new webpack.NoEmitOnErrorsPlugin(),
27
+    // https://github.com/ampedandwired/html-webpack-plugin
28
+    new HtmlWebpackPlugin({
29
+      filename: 'index.html',
30
+      template: 'index.html',
31
+      inject: true
32
+    }),
33
+    new FriendlyErrorsPlugin()
34
+  ]
35
+})

+ 126
- 0
build/webpack.prod.conf.js View File

@@ -0,0 +1,126 @@
1
+var path = require('path')
2
+var utils = require('./utils')
3
+var webpack = require('webpack')
4
+var config = require('../config')
5
+var merge = require('webpack-merge')
6
+var baseWebpackConfig = require('./webpack.base.conf')
7
+var CopyWebpackPlugin = require('copy-webpack-plugin')
8
+var HtmlWebpackPlugin = require('html-webpack-plugin')
9
+var ExtractTextPlugin = require('extract-text-webpack-plugin')
10
+var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
11
+
12
+var env = process.env.NODE_ENV === 'testing'
13
+  ? require('../config/test.env')
14
+  : config.build.env
15
+
16
+var webpackConfig = merge(baseWebpackConfig, {
17
+  module: {
18
+    rules: utils.styleLoaders({
19
+      sourceMap: config.build.productionSourceMap,
20
+      extract: true
21
+    })
22
+  },
23
+  devtool: config.build.productionSourceMap ? '#source-map' : false,
24
+  output: {
25
+    path: config.build.assetsRoot,
26
+    filename: utils.assetsPath('js/[name].[chunkhash].js'),
27
+    chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
28
+  },
29
+  plugins: [
30
+    // http://vuejs.github.io/vue-loader/en/workflow/production.html
31
+    new webpack.DefinePlugin({
32
+      'process.env': env
33
+    }),
34
+    new webpack.optimize.UglifyJsPlugin({
35
+      compress: {
36
+        warnings: false
37
+      },
38
+      sourceMap: true
39
+    }),
40
+    // extract css into its own file
41
+    new ExtractTextPlugin({
42
+      filename: utils.assetsPath('css/[name].[contenthash].css')
43
+    }),
44
+    // Compress extracted CSS. We are using this plugin so that possible
45
+    // duplicated CSS from different components can be deduped.
46
+    new OptimizeCSSPlugin({
47
+      cssProcessorOptions: {
48
+        safe: true
49
+      }
50
+    }),
51
+    // generate dist index.html with correct asset hash for caching.
52
+    // you can customize output by editing /index.html
53
+    // see https://github.com/ampedandwired/html-webpack-plugin
54
+    new HtmlWebpackPlugin({
55
+      filename: process.env.NODE_ENV === 'testing'
56
+        ? 'index.html'
57
+        : config.build.index,
58
+      template: 'index.html',
59
+      inject: true,
60
+      minify: {
61
+        removeComments: true,
62
+        collapseWhitespace: true,
63
+        removeAttributeQuotes: true
64
+        // more options:
65
+        // https://github.com/kangax/html-minifier#options-quick-reference
66
+      },
67
+      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
68
+      chunksSortMode: 'dependency'
69
+    }),
70
+    // keep module.id stable when vender modules does not change
71
+    new webpack.HashedModuleIdsPlugin(),
72
+    // split vendor js into its own file
73
+    new webpack.optimize.CommonsChunkPlugin({
74
+      name: 'vendor',
75
+      minChunks: function (module, count) {
76
+        // any required modules inside node_modules are extracted to vendor
77
+        return (
78
+          module.resource &&
79
+          /\.js$/.test(module.resource) &&
80
+          module.resource.indexOf(
81
+            path.join(__dirname, '../node_modules')
82
+          ) === 0
83
+        )
84
+      }
85
+    }),
86
+    // extract webpack runtime and module manifest to its own file in order to
87
+    // prevent vendor hash from being updated whenever app bundle is updated
88
+    new webpack.optimize.CommonsChunkPlugin({
89
+      name: 'manifest',
90
+      chunks: ['vendor']
91
+    }),
92
+    // copy custom static assets
93
+    new CopyWebpackPlugin([
94
+      {
95
+        from: path.resolve(__dirname, '../static'),
96
+        to: config.build.assetsSubDirectory,
97
+        ignore: ['.*']
98
+      }
99
+    ])
100
+  ]
101
+})
102
+
103
+if (config.build.productionGzip) {
104
+  var CompressionWebpackPlugin = require('compression-webpack-plugin')
105
+
106
+  webpackConfig.plugins.push(
107
+    new CompressionWebpackPlugin({
108
+      asset: '[path].gz[query]',
109
+      algorithm: 'gzip',
110
+      test: new RegExp(
111
+        '\\.(' +
112
+        config.build.productionGzipExtensions.join('|') +
113
+        ')$'
114
+      ),
115
+      threshold: 10240,
116
+      minRatio: 0.8
117
+    })
118
+  )
119
+}
120
+
121
+if (config.build.bundleAnalyzerReport) {
122
+  var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
123
+  webpackConfig.plugins.push(new BundleAnalyzerPlugin())
124
+}
125
+
126
+module.exports = webpackConfig

+ 31
- 0
build/webpack.test.conf.js View File

@@ -0,0 +1,31 @@
1
+// This is the webpack config used for unit tests.
2
+
3
+var utils = require('./utils')
4
+var webpack = require('webpack')
5
+var merge = require('webpack-merge')
6
+var baseConfig = require('./webpack.base.conf')
7
+
8
+var webpackConfig = merge(baseConfig, {
9
+  // use inline sourcemap for karma-sourcemap-loader
10
+  module: {
11
+    rules: utils.styleLoaders()
12
+  },
13
+  devtool: '#inline-source-map',
14
+  resolveLoader: {
15
+    alias: {
16
+      // necessary to to make lang="scss" work in test when using vue-loader's ?inject option
17
+      // see discussion at https://github.com/vuejs/vue-loader/issues/724
18
+      'scss-loader': 'sass-loader'
19
+    }
20
+  },
21
+  plugins: [
22
+    new webpack.DefinePlugin({
23
+      'process.env': require('../config/test.env')
24
+    })
25
+  ]
26
+})
27
+
28
+// no need for app entry during tests
29
+delete webpackConfig.entry
30
+
31
+module.exports = webpackConfig

+ 6
- 0
config/dev.env.js View File

@@ -0,0 +1,6 @@
1
+var merge = require('webpack-merge')
2
+var prodEnv = require('./prod.env')
3
+
4
+module.exports = merge(prodEnv, {
5
+  NODE_ENV: '"development"'
6
+})

+ 38
- 0
config/index.js View File

@@ -0,0 +1,38 @@
1
+// see http://vuejs-templates.github.io/webpack for documentation.
2
+var path = require('path')
3
+
4
+module.exports = {
5
+  build: {
6
+    env: require('./prod.env'),
7
+    index: path.resolve(__dirname, '../dist/index.html'),
8
+    assetsRoot: path.resolve(__dirname, '../dist'),
9
+    assetsSubDirectory: 'static',
10
+    assetsPublicPath: '/',
11
+    productionSourceMap: true,
12
+    // Gzip off by default as many popular static hosts such as
13
+    // Surge or Netlify already gzip all static assets for you.
14
+    // Before setting to `true`, make sure to:
15
+    // npm install --save-dev compression-webpack-plugin
16
+    productionGzip: false,
17
+    productionGzipExtensions: ['js', 'css'],
18
+    // Run the build command with an extra argument to
19
+    // View the bundle analyzer report after build finishes:
20
+    // `npm run build --report`
21
+    // Set to `true` or `false` to always turn it on or off
22
+    bundleAnalyzerReport: process.env.npm_config_report
23
+  },
24
+  dev: {
25
+    env: require('./dev.env'),
26
+    port: 8080,
27
+    autoOpenBrowser: true,
28
+    assetsSubDirectory: 'static',
29
+    assetsPublicPath: '/',
30
+    proxyTable: {},
31
+    // CSS Sourcemaps off by default because relative paths are "buggy"
32
+    // with this option, according to the CSS-Loader README
33
+    // (https://github.com/webpack/css-loader#sourcemaps)
34
+    // In our experience, they generally work as expected,
35
+    // just be aware of this issue when enabling this option.
36
+    cssSourceMap: false
37
+  }
38
+}

+ 3
- 0
config/prod.env.js View File

@@ -0,0 +1,3 @@
1
+module.exports = {
2
+  NODE_ENV: '"production"'
3
+}

+ 6
- 0
config/test.env.js View File

@@ -0,0 +1,6 @@
1
+var merge = require('webpack-merge')
2
+var devEnv = require('./dev.env')
3
+
4
+module.exports = merge(devEnv, {
5
+  NODE_ENV: '"testing"'
6
+})

+ 13
- 0
index.html View File

@@ -0,0 +1,13 @@
1
+<!DOCTYPE html>
2
+<html>
3
+  <head>
4
+    <meta charset="utf-8">
5
+    <title>HungerGames</title>
6
+    <link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons' rel="stylesheet">
7
+    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
8
+  </head>
9
+  <body>
10
+    <div id="app"></div>
11
+    <!-- built files will be auto injected -->
12
+  </body>
13
+</html>

+ 98
- 0
package.json View File

@@ -0,0 +1,98 @@
1
+{
2
+  "name": "hungergames",
3
+  "version": "1.0.0",
4
+  "description": "OpenFoodFacts gamification",
5
+  "author": "Phyks (Lucas Verney) <phyks@phyks.me>",
6
+  "private": true,
7
+  "scripts": {
8
+    "dev": "node build/dev-server.js",
9
+    "start": "node build/dev-server.js",
10
+    "build": "node build/build.js",
11
+    "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
12
+    "e2e": "node test/e2e/runner.js",
13
+    "test": "npm run unit && npm run e2e",
14
+    "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
15
+  },
16
+  "dependencies": {
17
+    "es6-promise": "^4.1.1",
18
+    "isomorphic-fetch": "^2.2.1",
19
+    "vue": "^2.4.2",
20
+    "vue-router": "^2.7.0",
21
+    "vuetify": "^0.15.7",
22
+    "vuex": "^2.4.1"
23
+  },
24
+  "devDependencies": {
25
+    "autoprefixer": "^7.1.2",
26
+    "babel-core": "^6.22.1",
27
+    "babel-eslint": "^7.1.1",
28
+    "babel-loader": "^7.1.1",
29
+    "babel-plugin-transform-runtime": "^6.22.0",
30
+    "babel-preset-env": "^1.3.2",
31
+    "babel-preset-stage-2": "^6.22.0",
32
+    "babel-register": "^6.22.0",
33
+    "chalk": "^2.0.1",
34
+    "connect-history-api-fallback": "^1.3.0",
35
+    "copy-webpack-plugin": "^4.0.1",
36
+    "css-loader": "^0.28.0",
37
+    "cssnano": "^3.10.0",
38
+    "eslint": "^3.19.0",
39
+    "eslint-friendly-formatter": "^3.0.0",
40
+    "eslint-loader": "^1.7.1",
41
+    "eslint-plugin-html": "^3.0.0",
42
+    "eslint-config-airbnb-base": "^11.1.3",
43
+    "eslint-import-resolver-webpack": "^0.8.1",
44
+    "eslint-plugin-import": "^2.2.0",
45
+    "eventsource-polyfill": "^0.9.6",
46
+    "express": "^4.14.1",
47
+    "extract-text-webpack-plugin": "^2.0.0",
48
+    "file-loader": "^0.11.1",
49
+    "friendly-errors-webpack-plugin": "^1.1.3",
50
+    "html-webpack-plugin": "^2.28.0",
51
+    "http-proxy-middleware": "^0.17.3",
52
+    "webpack-bundle-analyzer": "^2.2.1",
53
+    "cross-env": "^5.0.1",
54
+    "karma": "^1.4.1",
55
+    "karma-coverage": "^1.1.1",
56
+    "karma-mocha": "^1.3.0",
57
+    "karma-phantomjs-launcher": "^1.0.2",
58
+    "karma-phantomjs-shim": "^1.4.0",
59
+    "karma-sinon-chai": "^1.3.1",
60
+    "karma-sourcemap-loader": "^0.3.7",
61
+    "karma-spec-reporter": "0.0.31",
62
+    "karma-webpack": "^2.0.2",
63
+    "mocha": "^3.2.0",
64
+    "chai": "^3.5.0",
65
+    "sinon": "^2.1.0",
66
+    "sinon-chai": "^2.8.0",
67
+    "inject-loader": "^3.0.0",
68
+    "babel-plugin-istanbul": "^4.1.1",
69
+    "phantomjs-prebuilt": "^2.1.14",
70
+    "chromedriver": "^2.27.2",
71
+    "cross-spawn": "^5.0.1",
72
+    "nightwatch": "^0.9.12",
73
+    "selenium-server": "^3.0.1",
74
+    "semver": "^5.3.0",
75
+    "shelljs": "^0.7.6",
76
+    "opn": "^5.1.0",
77
+    "optimize-css-assets-webpack-plugin": "^2.0.0",
78
+    "ora": "^1.2.0",
79
+    "rimraf": "^2.6.0",
80
+    "url-loader": "^0.5.8",
81
+    "vue-loader": "^13.0.4",
82
+    "vue-style-loader": "^3.0.1",
83
+    "vue-template-compiler": "^2.4.2",
84
+    "webpack": "^2.6.1",
85
+    "webpack-dev-middleware": "^1.10.0",
86
+    "webpack-hot-middleware": "^2.18.0",
87
+    "webpack-merge": "^4.1.0"
88
+  },
89
+  "engines": {
90
+    "node": ">= 4.0.0",
91
+    "npm": ">= 3.0.0"
92
+  },
93
+  "browserslist": [
94
+    "> 1%",
95
+    "last 2 versions",
96
+    "not ie <= 8"
97
+  ]
98
+}

+ 43
- 0
src/App.vue View File

@@ -0,0 +1,43 @@
1
+<template>
2
+    <v-app toolbar>
3
+        <NavigationDrawer v-model="isDrawerVisible"/>
4
+        <v-toolbar class="indigo" dark fixed>
5
+            <v-toolbar-side-icon @click.stop="showHideDrawer"></v-toolbar-side-icon>
6
+            <v-toolbar-title>HungerGames</v-toolbar-title>
7
+            <v-spacer></v-spacer>
8
+            <v-menu bottom left offset-y>
9
+                <v-btn icon slot="activator">
10
+                    <v-icon>more_vert</v-icon>
11
+                </v-btn>
12
+                <v-list>
13
+                    <v-list-tile>
14
+                        <v-list-tile-title>Skip quest</v-list-tile-title>
15
+                    </v-list-tile>
16
+                </v-list>
17
+            </v-menu>
18
+        </v-toolbar>
19
+        <main>
20
+            <router-view></router-view>
21
+        </main>
22
+    </v-app>
23
+</template>
24
+
25
+<script>
26
+import NavigationDrawer from '@/components/NavigationDrawer';
27
+
28
+export default {
29
+    components: {
30
+        NavigationDrawer,
31
+    },
32
+    data() {
33
+        return {
34
+            isDrawerVisible: false,
35
+        };
36
+    },
37
+    methods: {
38
+        showHideDrawer() {
39
+            this.isDrawerVisible = !this.isDrawerVisible;
40
+        },
41
+    },
42
+};
43
+</script>

+ 46
- 0
src/api/index.js View File

@@ -0,0 +1,46 @@
1
+require('es6-promise').polyfill();
2
+require('isomorphic-fetch');
3
+
4
+export const BASEURL = 'https://world.openfoodfacts.org/';
5
+
6
+function missingCategories() {
7
+    return fetch(
8
+        `${BASEURL}state/categories-to-be-completed.json`,
9
+    )
10
+        .then(response => response.json())
11
+        .then(response => response.products.map(product => ({
12
+            id: product.id,
13
+            name: product.product_name,
14
+            icon: product.image_front_url,
15
+            brands: product.brands,
16
+            predictedCategories: {
17
+                'en:fresh-foods': {
18
+                    name: 'Fresh foods',
19
+                    isOK: true,
20
+                },
21
+                'en:meats': {
22
+                    name: 'Meats',
23
+                    isOK: true,
24
+                },
25
+                'en:prepared-meats': {
26
+                    name: 'Prepared meats',
27
+                    isOK: true,
28
+                },
29
+                'en:hams': {
30
+                    name: 'Hams',
31
+                    isOK: true,
32
+                },
33
+                'fr:charcuteries-crues': {
34
+                    name: 'Charcuteries crues',
35
+                    isOK: true,
36
+                },
37
+                'en:beverages': {
38
+                    name: 'Beverages',
39
+                    isOK: true,
40
+                },
41
+            },
42
+        })))
43
+        .catch(exc => console.error(`Unable to fetch products with missing categories: ${exc}.`));
44
+}
45
+
46
+export { missingCategories };

BIN
src/assets/logo.png View File


+ 40
- 0
src/components/NavigationDrawer.vue View File

@@ -0,0 +1,40 @@
1
+<template>
2
+    <v-navigation-drawer
3
+        persistent
4
+        clipped
5
+        enable-resize-watcher
6
+        v-model="isActive"
7
+        >
8
+        <v-list>
9
+            <v-list-tile :to="{ name: 'Home' }" exact>
10
+                <v-list-tile-action>
11
+                    <v-icon>play_arrow</v-icon>
12
+                </v-list-tile-action>
13
+                <v-list-tile-content>
14
+                    <v-list-tile-title>Play!</v-list-tile-title>
15
+                </v-list-tile-content>
16
+            </v-list-tile>
17
+        </v-list>
18
+    </v-navigation-drawer>
19
+</template>
20
+
21
+<script>
22
+/**
23
+ * TODO: Should stick to the toolbar on xs screens. Should be fixed by Vuetify 0.16.
24
+ */
25
+export default {
26
+    props: {
27
+        value: Boolean,
28
+    },
29
+    computed: {
30
+        isActive: {
31
+            get() {
32
+                return this.value;
33
+            },
34
+            set(val) {
35
+                this.$emit('input', val);
36
+            },
37
+        },
38
+    },
39
+};
40
+</script>

+ 72
- 0
src/components/QuestMissingCategories/index.vue View File

@@ -0,0 +1,72 @@
1
+<template>
2
+    <v-container fluid grid-list-lg class="text-xs-center">
3
+        <v-layout row mb-3 align-center>
4
+            <v-flex xs5>
5
+                <v-dialog v-model="dialog" lazy absolute>
6
+                    <v-avatar
7
+                        size="100%"
8
+                        class="pointable"
9
+                        slot="activator"
10
+                        >
11
+                        <!-- TODO: Should be closable by ESC -->
12
+                        <img class="icon" :src="data.icon" />
13
+                    </v-avatar>
14
+                    <v-card>
15
+                        <v-card-text>
16
+                            <img style="width: 100%;" :src="data.icon" />
17
+                        </v-card-text>
18
+                    </v-card>
19
+                </v-dialog>
20
+            </v-flex>
21
+            <v-flex xs7 class="text-xs-center">
22
+                <div>
23
+                    <div class="headline">{{ data.brands }}</div>
24
+                    <h2 class="title">{{ data.name }}</h2>
25
+                </div>
26
+            </v-flex>
27
+        </v-layout>
28
+        <v-divider />
29
+        <v-layout row>
30
+            <v-flex xs12>
31
+                <h2 class="title">Unselect all incorrect categories:</h2>
32
+            </v-flex>
33
+        </v-layout>
34
+        <v-layout row wrap>
35
+            <v-btn
36
+                v-for="(category, key) in data.predictedCategories" :key="key"
37
+                round primary dark :class="{ green: category.isOK, red: !category.isOK }"
38
+                @click.stop="data.predictedCategories[key].isOK = !data.predictedCategories[key].isOK"
39
+                >
40
+                {{ category.name }}
41
+            </v-btn>
42
+        </v-layout>
43
+        <v-layout row>
44
+            <v-flex xs12>
45
+                <v-btn>submit</v-btn>
46
+            </v-flex>
47
+        </v-layout>
48
+    </v-container>
49
+</template>
50
+
51
+<script>
52
+export default {
53
+    props: {
54
+        data: Object,
55
+    },
56
+    data() {
57
+        return {
58
+            dialog: false,
59
+        };
60
+    },
61
+};
62
+</script>
63
+
64
+<style scoped>
65
+.pointable {
66
+    cursor: pointer;
67
+}
68
+
69
+.pointable:hover {
70
+    opacity: 0.8;
71
+}
72
+</style>

+ 22
- 0
src/main.js View File

@@ -0,0 +1,22 @@
1
+// The Vue build version to load with the `import` command
2
+// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3
+import Vue from 'vue';
4
+import Vuetify from 'vuetify';
5
+import 'vuetify/dist/vuetify.min.css';
6
+
7
+import App from './App';
8
+import router from './router';
9
+import store from './store';
10
+
11
+Vue.config.productionTip = false;
12
+
13
+Vue.use(Vuetify);
14
+
15
+/* eslint-disable no-new */
16
+new Vue({
17
+    el: '#app',
18
+    router,
19
+    store,
20
+    template: '<App/>',
21
+    components: { App },
22
+});

+ 15
- 0
src/router/index.js View File

@@ -0,0 +1,15 @@
1
+import Vue from 'vue';
2
+import Router from 'vue-router';
3
+import Quest from '@/views/Quest';
4
+
5
+Vue.use(Router);
6
+
7
+export default new Router({
8
+    routes: [
9
+        {
10
+            path: '/',
11
+            name: 'Quest',
12
+            component: Quest,
13
+        },
14
+    ],
15
+});

+ 20
- 0
src/store/actions.js View File

@@ -0,0 +1,20 @@
1
+import * as types from './mutations-types';
2
+import quests from './quests';
3
+
4
+export default {
5
+    preloadQuests({ commit }) {
6
+        commit(types.IS_LOADING_QUESTS);
7
+
8
+        Object.keys(quests).forEach((quest) => {
9
+            quests[quest]().then(
10
+                items => commit(
11
+                    types.STORE_QUESTS_ITEMS,
12
+                    {
13
+                        type: 'missingCategories',
14
+                        items,
15
+                    },
16
+                ),
17
+            );
18
+        });
19
+    },
20
+};

+ 18
- 0
src/store/getters.js View File

@@ -0,0 +1,18 @@
1
+import pickRandomFromArray from '@/tools';
2
+
3
+function popQuest(state) {
4
+    const availableQuests = [];
5
+    Object.keys(state.questsItems).forEach((quest) => {
6
+        if (state.questsItems[quest].length > 0) {
7
+            availableQuests.push(quest);
8
+        }
9
+    });
10
+
11
+    if (availableQuests.length === 0) {
12
+        return null;
13
+    }
14
+    const randomQuestsList = pickRandomFromArray(availableQuests);
15
+    return pickRandomFromArray(state.questsItems[randomQuestsList]);
16
+}
17
+
18
+export default { popQuest };

+ 15
- 0
src/store/index.js View File

@@ -0,0 +1,15 @@
1
+import Vue from 'vue';
2
+import Vuex from 'vuex';
3
+
4
+import actions from './actions';
5
+import { initialState as state, mutations } from './mutations';
6
+import getters from './getters';
7
+
8
+Vue.use(Vuex);
9
+
10
+export default new Vuex.Store({
11
+    state,
12
+    actions,
13
+    mutations,
14
+    getters,
15
+});

+ 2
- 0
src/store/mutations-types.js View File

@@ -0,0 +1,2 @@
1
+export const IS_LOADING_QUESTS = 'IS_LOADING_QUESTS';
2
+export const STORE_QUESTS_ITEMS = 'STORE_QUESTS_ITEMS';

+ 17
- 0
src/store/mutations.js View File

@@ -0,0 +1,17 @@
1
+import Vue from 'vue';
2
+
3
+import * as types from './mutations-types';
4
+
5
+export const initialState = {
6
+    isLoading: false,
7
+    questsItems: {},
8
+};
9
+
10
+export const mutations = {
11
+    [types.IS_LOADING_QUESTS](state) {
12
+        state.isLoading = true;
13
+    },
14
+    [types.STORE_QUESTS_ITEMS](state, { type, items }) {
15
+        Vue.set(state.questsItems, type, items);
16
+    },
17
+};

+ 5
- 0
src/store/quests.js View File

@@ -0,0 +1,5 @@
1
+import { missingCategories } from '@/api';
2
+
3
+export default {
4
+    missingCategories,
5
+};

+ 4
- 0
src/tools/index.js View File

@@ -0,0 +1,4 @@
1
+export default function pickRandomFromArray(list) {
2
+    const randomIndex = Math.floor(Math.random() * list.length);
3
+    return list[randomIndex];
4
+}

+ 31
- 0
src/views/Quest.vue View File

@@ -0,0 +1,31 @@
1
+<template>
2
+    <QuestMissingCategories v-if="questData" :data="questData" />
3
+</template>
4
+
5
+<script>
6
+import QuestMissingCategories from '@/components/QuestMissingCategories/index';
7
+
8
+
9
+export default {
10
+    components: {
11
+        QuestMissingCategories,
12
+    },
13
+    created() {
14
+        this.fetchData();
15
+    },
16
+    watch: {
17
+        // Fetch again when the component is updated
18
+        $route: 'fetchData',
19
+    },
20
+    methods: {
21
+        fetchData() {
22
+            this.$store.dispatch('preloadQuests');
23
+        },
24
+    },
25
+    computed: {
26
+        questData() {
27
+            return this.$store.getters.popQuest;
28
+        },
29
+    },
30
+};
31
+</script>

+ 78
- 0
src/views/Quest2.vue View File

@@ -0,0 +1,78 @@
1
+<template>
2
+    <v-container fluid grid-list-lg class="text-xs-center">
3
+        <v-layout row mb-3 align-center>
4
+            <v-flex xs5>
5
+                <v-avatar size="100%">
6
+                    <img class="icon" src="https://static.openfoodfacts.org/images/products/761/303/423/2465/front_fr.6.400.jpg" />
7
+                </v-avatar>
8
+            </v-flex>
9
+            <v-flex xs7 class="text-xs-center">
10
+                <div>
11
+                    <div class="headline">Herta</div>
12
+                    <h2 class="title">Le Bon Paris, À l'Étouffée (6 Tranches)</h2>
13
+                </div>
14
+            </v-flex>
15
+        </v-layout>
16
+        <v-divider />
17
+        <v-layout row>
18
+            <v-flex xs12>
19
+                <h2 class="title">Fix ingredients list:</h2>
20
+            </v-flex>
21
+        </v-layout>
22
+        <v-layout row wrap>
23
+            <v-flex xs12>
24
+                <img style="max-width: 100%;" src="https://static.openfoodfacts.org/images/products/761/303/423/2465/ingredients_fr.8.400.jpg" />
25
+            </v-flex>
26
+        </v-layout>
27
+        <v-layout row>
28
+            <v-flex xs12>
29
+                <v-text-field
30
+                    value="Jambon frais de porc, Bouillon (eau, couennes de porc, oignons, os de porc, carottes, sel, persil, ail, clou de girofle, poivre, laurier) ; sel, dextrose de maïs, arômes naturels, Conservateur (nitrite de sodium) ; Antioxydant (isoascorbate de sodium)."
31
+                    class="input-group--focused"
32
+                    multi-line
33
+                    />
34
+                </v-text-field>
35
+            </v-flex>
36
+        </v-layout>
37
+        <v-layout row>
38
+            <v-flex xs12>
39
+                <v-btn>submit</v-btn>
40
+            </v-flex>
41
+        </v-layout>
42
+    </v-container>
43
+</template>
44
+
45
+<script>
46
+export default {
47
+    data() {
48
+        return {
49
+            items: {
50
+                'en:fresh-foods': {
51
+                    name: 'Fresh foods',
52
+                    isOK: true,
53
+                },
54
+                'en:meats': {
55
+                    name: 'Meats',
56
+                    isOK: true,
57
+                },
58
+                'en:prepared-meats': {
59
+                    name: 'Prepared meats',
60
+                    isOK: true,
61
+                },
62
+                'en:hams': {
63
+                    name: 'Hams',
64
+                    isOK: true,
65
+                },
66
+                'fr:charcuteries-crues': {
67
+                    name: 'Charcuteries crûes',
68
+                    isOK: false,
69
+                },
70
+                'en:beverages': {
71
+                    name: 'Beverages',
72
+                    isOK: false,
73
+                },
74
+            },
75
+        };
76
+    },
77
+};
78
+</script>

+ 0
- 0
static/.gitkeep View File


+ 24
- 0
test/e2e/custom-assertions/elementCount.js View File

@@ -0,0 +1,24 @@
1
+// A custom Nightwatch assertion.
2
+// the name of the method is the filename.
3
+// can be used in tests like this:
4
+//
5
+//   browser.assert.elementCount(selector, count)
6
+//
7
+// for how to write custom assertions see
8
+// http://nightwatchjs.org/guide#writing-custom-assertions
9
+exports.assertion = function (selector, count) {
10
+    this.message = `Testing if element <${selector}> has count: ${count}`;
11
+    this.expected = count;
12
+    this.pass = function (val) {
13
+        return val === this.expected;
14
+    };
15
+    this.value = function (res) {
16
+        return res.value;
17
+    };
18
+    this.command = function (cb) {
19
+        const self = this;
20
+        return this.api.execute(selector => document.querySelectorAll(selector).length, [selector], (res) => {
21
+            cb.call(self, res);
22
+        });
23
+    };
24
+};

+ 46
- 0
test/e2e/nightwatch.conf.js View File

@@ -0,0 +1,46 @@
1
+require('babel-register');
2
+const config = require('../../config');
3
+
4
+// http://nightwatchjs.org/gettingstarted#settings-file
5
+module.exports = {
6
+    src_folders: ['test/e2e/specs'],
7
+    output_folder: 'test/e2e/reports',
8
+    custom_assertions_path: ['test/e2e/custom-assertions'],
9
+
10
+    selenium: {
11
+        start_process: true,
12
+        server_path: require('selenium-server').path,
13
+        host: '127.0.0.1',
14
+        port: 4444,
15
+        cli_args: {
16
+            'webdriver.chrome.driver': require('chromedriver').path,
17
+        },
18
+    },
19
+
20
+    test_settings: {
21
+        default: {
22
+            selenium_port: 4444,
23
+            selenium_host: 'localhost',
24
+            silent: true,
25
+            globals: {
26
+                devServerURL: `http://localhost:${process.env.PORT || config.dev.port}`,
27
+            },
28
+        },
29
+
30
+        chrome: {
31
+            desiredCapabilities: {
32
+                browserName: 'chrome',
33
+                javascriptEnabled: true,
34
+                acceptSslCerts: true,
35
+            },
36
+        },
37
+
38
+        firefox: {
39
+            desiredCapabilities: {
40
+                browserName: 'firefox',
41
+                javascriptEnabled: true,
42
+                acceptSslCerts: true,
43
+            },
44
+        },
45
+    },
46
+};

+ 33
- 0
test/e2e/runner.js View File

@@ -0,0 +1,33 @@
1
+// 1. start the dev server using production config
2
+process.env.NODE_ENV = 'testing';
3
+const server = require('../../build/dev-server.js');
4
+
5
+server.ready.then(() => {
6
+  // 2. run the nightwatch test suite against it
7
+  // to run in additional browsers:
8
+  //    1. add an entry in test/e2e/nightwatch.conf.json under "test_settings"
9
+  //    2. add it to the --env flag below
10
+  // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
11
+  // For more information on Nightwatch's config file, see
12
+  // http://nightwatchjs.org/guide#settings-file
13
+    let opts = process.argv.slice(2);
14
+    if (opts.indexOf('--config') === -1) {
15
+        opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']);
16
+    }
17
+    if (opts.indexOf('--env') === -1) {
18
+        opts = opts.concat(['--env', 'chrome']);
19
+    }
20
+
21
+    const spawn = require('cross-spawn');
22
+    const runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' });
23
+
24
+    runner.on('exit', (code) => {
25
+        server.close();
26
+        process.exit(code);
27
+    });
28
+
29
+    runner.on('error', (err) => {
30
+        server.close();
31
+        throw err;
32
+    });
33
+});

+ 19
- 0
test/e2e/specs/test.js View File

@@ -0,0 +1,19 @@
1
+// For authoring Nightwatch tests, see
2
+// http://nightwatchjs.org/guide#usage
3
+
4
+module.exports = {
5
+    'default e2e tests': function test(browser) {
6
+    // automatically uses dev Server port from /config.index.js
7
+    // default: http://localhost:8080
8
+    // see nightwatch.conf.js
9
+        const devServer = browser.globals.devServerURL;
10
+
11
+        browser
12
+      .url(devServer)
13
+      .waitForElementVisible('#app', 5000)
14
+      .assert.elementPresent('.hello')
15
+      .assert.containsText('h1', 'Welcome to Your Vue.js App')
16
+      .assert.elementCount('img', 1)
17
+      .end();
18
+    },
19
+};

+ 9
- 0
test/unit/.eslintrc View File

@@ -0,0 +1,9 @@
1
+{
2
+  "env": {
3
+    "mocha": true
4
+  },
5
+  "globals": {
6
+    "expect": true,
7
+    "sinon": true
8
+  }
9
+}

+ 13
- 0
test/unit/index.js View File

@@ -0,0 +1,13 @@
1
+import Vue from 'vue';
2
+
3
+Vue.config.productionTip = false;
4
+
5
+// require all test files (files that ends with .spec.js)
6
+const testsContext = require.context('./specs', true, /\.spec$/);
7
+testsContext.keys().forEach(testsContext);
8
+
9
+// require all src files except main.js for coverage.
10
+// you can also change this to match only the subset of files that
11
+// you want coverage for.
12
+const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/);
13
+srcContext.keys().forEach(srcContext);

+ 33
- 0
test/unit/karma.conf.js View File

@@ -0,0 +1,33 @@
1
+// This is a karma config file. For more details see
2
+//   http://karma-runner.github.io/0.13/config/configuration-file.html
3
+// we are also using it with karma-webpack
4
+//   https://github.com/webpack/karma-webpack
5
+
6
+const webpackConfig = require('../../build/webpack.test.conf');
7
+
8
+module.exports = function (config) {
9
+    config.set({
10
+    // to run in additional browsers:
11
+    // 1. install corresponding karma launcher
12
+    //    http://karma-runner.github.io/0.13/config/browsers.html
13
+    // 2. add it to the `browsers` array below.
14
+        browsers: ['PhantomJS'],
15
+        frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'],
16
+        reporters: ['spec', 'coverage'],
17
+        files: ['./index.js'],
18
+        preprocessors: {
19
+            './index.js': ['webpack', 'sourcemap'],
20
+        },
21
+        webpack: webpackConfig,
22
+        webpackMiddleware: {
23
+            noInfo: true,
24
+        },
25
+        coverageReporter: {
26
+            dir: './coverage',
27
+            reporters: [
28
+        { type: 'lcov', subdir: '.' },
29
+        { type: 'text-summary' },
30
+            ],
31
+        },
32
+    });
33
+};

+ 11
- 0
test/unit/specs/Hello.spec.js View File

@@ -0,0 +1,11 @@
1
+import Vue from 'vue';
2
+import Hello from '@/components/Hello';
3
+
4
+describe('Hello.vue', () => {
5
+    it('should render correct contents', () => {
6
+        const Constructor = Vue.extend(Hello);
7
+        const vm = new Constructor().$mount();
8
+        expect(vm.$el.querySelector('.hello h1').textContent)
9
+      .to.equal('Welcome to Your Vue.js App');
10
+    });
11
+});