Jared Norris 8 lat temu
rodzic
commit
c99b1ecc97
46 zmienionych plików z 14659 dodań i 0 usunięć
  1. 14
    0
      VueApp/.babelrc
  2. 6
    0
      VueApp/.dockerignore
  3. 9
    0
      VueApp/.editorconfig
  4. 2
    0
      VueApp/.eslintignore
  5. 27
    0
      VueApp/.eslintrc.js
  6. 10
    0
      VueApp/.gitignore
  7. 8
    0
      VueApp/.postcssrc.js
  8. 1
    0
      VueApp/.vscode/settings.json
  9. 12
    0
      VueApp/Dockerfile
  10. 63
    0
      VueApp/README.md
  11. 35
    0
      VueApp/build/build.js
  12. 45
    0
      VueApp/build/check-versions.js
  13. 9
    0
      VueApp/build/dev-client.js
  14. 83
    0
      VueApp/build/dev-server.js
  15. 71
    0
      VueApp/build/utils.js
  16. 12
    0
      VueApp/build/vue-loader.conf.js
  17. 67
    0
      VueApp/build/webpack.base.conf.js
  18. 35
    0
      VueApp/build/webpack.dev.conf.js
  19. 120
    0
      VueApp/build/webpack.prod.conf.js
  20. 24
    0
      VueApp/build/webpack.test.conf.js
  21. 6
    0
      VueApp/config/dev.env.js
  22. 38
    0
      VueApp/config/index.js
  23. 3
    0
      VueApp/config/prod.env.js
  24. 6
    0
      VueApp/config/test.env.js
  25. 2
    0
      VueApp/exec.ps1
  26. 3
    0
      VueApp/exec.sh
  27. 11
    0
      VueApp/index.html
  28. 13405
    0
      VueApp/package-lock.json
  29. 99
    0
      VueApp/package.json
  30. 73
    0
      VueApp/src/App.vue
  31. 1
    0
      VueApp/src/assets/loading.svg
  32. BIN
      VueApp/src/assets/logo.png
  33. 71
    0
      VueApp/src/auth/AuthService.js
  34. 31
    0
      VueApp/src/components/Callback.vue
  35. 24
    0
      VueApp/src/components/Home.vue
  36. 14
    0
      VueApp/src/main.js
  37. 28
    0
      VueApp/src/router/index.js
  38. 0
    0
      VueApp/static/.gitkeep
  39. 26
    0
      VueApp/test/e2e/custom-assertions/elementCount.js
  40. 46
    0
      VueApp/test/e2e/nightwatch.conf.js
  41. 31
    0
      VueApp/test/e2e/runner.js
  42. 19
    0
      VueApp/test/e2e/specs/test.js
  43. 9
    0
      VueApp/test/unit/.eslintrc
  44. 16
    0
      VueApp/test/unit/index.js
  45. 33
    0
      VueApp/test/unit/karma.conf.js
  46. 11
    0
      VueApp/test/unit/specs/Hello.spec.js

+ 14
- 0
VueApp/.babelrc Wyświetl plik

@@ -0,0 +1,14 @@
1
+{
2
+  "presets": [
3
+    ["env", { "modules": false }],
4
+    "stage-2"
5
+  ],
6
+  "plugins": ["transform-runtime"],
7
+  "comments": false,
8
+  "env": {
9
+    "test": {
10
+      "presets": ["env", "stage-2"],
11
+      "plugins": [ "istanbul" ]
12
+    }
13
+  }
14
+}

+ 6
- 0
VueApp/.dockerignore Wyświetl plik

@@ -0,0 +1,6 @@
1
+package-lock.json
2
+node_modules
3
+.gitignore
4
+exec.sh
5
+exec.ps1
6
+README.md

+ 9
- 0
VueApp/.editorconfig Wyświetl plik

@@ -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
VueApp/.eslintignore Wyświetl plik

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

+ 27
- 0
VueApp/.eslintrc.js Wyświetl plik

@@ -0,0 +1,27 @@
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
+  // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
13
+  extends: 'standard',
14
+  // required to lint *.vue files
15
+  plugins: [
16
+    'html'
17
+  ],
18
+  // add your custom rules here
19
+  'rules': {
20
+    // allow paren-less arrow functions
21
+    'arrow-parens': 0,
22
+    // allow async-await
23
+    'generator-star-spacing': 0,
24
+    // allow debugger during development
25
+    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
26
+  }
27
+}

+ 10
- 0
VueApp/.gitignore Wyświetl plik

@@ -0,0 +1,10 @@
1
+.DS_Store
2
+node_modules/
3
+dist/
4
+npm-debug.log
5
+yarn-error.log
6
+test/unit/coverage
7
+test/e2e/reports
8
+selenium-debug.log
9
+auth0-variables.js
10
+.env

+ 8
- 0
VueApp/.postcssrc.js Wyświetl plik

@@ -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 "browserlist" field in package.json
6
+    "autoprefixer": {}
7
+  }
8
+}

+ 1
- 0
VueApp/.vscode/settings.json Wyświetl plik

@@ -0,0 +1 @@
1
+{}

+ 12
- 0
VueApp/Dockerfile Wyświetl plik

@@ -0,0 +1,12 @@
1
+FROM node:8.7-alpine
2
+
3
+WORKDIR /home/app
4
+
5
+RUN npm install -g create-react-app
6
+ADD package.json /home/app
7
+RUN npm install
8
+ADD . /home/app
9
+
10
+CMD ["npm", "start"]
11
+
12
+EXPOSE 3000

+ 63
- 0
VueApp/README.md Wyświetl plik

@@ -0,0 +1,63 @@
1
+# Auth0 Vue.js Login
2
+
3
+This sample demonstrates how to add authentication to a Vue.js application with Auth0. The sample makes use of Auth0's hosted login page which provides centralized authentication.
4
+
5
+## Getting Started
6
+
7
+If you haven't already done so, [sign up](https://auth0.com) for your free Auth0 account and create a new client in the [dashboard](https://manage.auth0.com). Find the **domain** and **client ID** from the settings area and add the URL for your application to the **Allowed Callback URLs** box.
8
+
9
+Clone the repo or download it from the Vue.js quickstart page in Auth0's documentation.
10
+
11
+```bash
12
+cd 01-Login
13
+npm install
14
+```
15
+
16
+## Set the Client ID and Domain
17
+
18
+If you download the sample from the quickstart page, it will come pre-populated with the **client ID** and **domain** for your application. If you clone the repo directly from Github, rename the `auth0-variables.js.example` file to `auth0-variables.js` and provide the **client ID** and **domain** there. This file is located in `src/auth/`.
19
+
20
+## Run the Application
21
+
22
+```bash
23
+npm start
24
+```
25
+
26
+The application will be served at `http://localhost:3000`.
27
+
28
+## Run the Application With Docker
29
+
30
+In order to run the example with docker you need to have `docker` installed.
31
+
32
+You also need to set the environment variables as explained [previously](#set-the-client-id-and-domain).
33
+
34
+Execute in command line `sh exec.sh` to run the Docker in Linux, or `.\exec.ps1` to run the Docker in Windows.
35
+
36
+## What is Auth0?
37
+
38
+Auth0 helps you to:
39
+
40
+* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, among others**, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
41
+* Add authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**.
42
+* Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user.
43
+* Support for generating signed [Json Web Tokens](https://docs.auth0.com/jwt) to call your APIs and **flow the user identity** securely.
44
+* Analytics of how, when and where users are logging in.
45
+* Pull data from other sources and add it to the user profile, through [JavaScript rules](https://docs.auth0.com/rules).
46
+
47
+## Create a free Auth0 account
48
+
49
+1. Go to [Auth0](https://auth0.com/signup) and click Sign Up.
50
+2. Use Google, GitHub or Microsoft Account to login.
51
+
52
+## Issue Reporting
53
+
54
+If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
55
+
56
+## Author
57
+
58
+[Auth0](https://auth0.com)
59
+
60
+## License
61
+
62
+This project is licensed under the MIT license. See the [LICENSE](LICENSE.txt) file for more info.
63
+

+ 35
- 0
VueApp/build/build.js Wyświetl plik

@@ -0,0 +1,35 @@
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
+    console.log(chalk.cyan('  Build complete.\n'))
30
+    console.log(chalk.yellow(
31
+      '  Tip: built files are meant to be served over an HTTP server.\n' +
32
+      '  Opening index.html over file:// won\'t work.\n'
33
+    ))
34
+  })
35
+})

+ 45
- 0
VueApp/build/check-versions.js Wyświetl plik

@@ -0,0 +1,45 @@
1
+var chalk = require('chalk')
2
+var semver = require('semver')
3
+var packageConfig = require('../package.json')
4
+
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
+    name: 'npm',
17
+    currentVersion: exec('npm --version'),
18
+    versionRequirement: packageConfig.engines.npm
19
+  }
20
+]
21
+
22
+module.exports = function () {
23
+  var warnings = []
24
+  for (var i = 0; i < versionRequirements.length; i++) {
25
+    var mod = versionRequirements[i]
26
+    if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
27
+      warnings.push(mod.name + ': ' +
28
+        chalk.red(mod.currentVersion) + ' should be ' +
29
+        chalk.green(mod.versionRequirement)
30
+      )
31
+    }
32
+  }
33
+
34
+  if (warnings.length) {
35
+    console.log('')
36
+    console.log(chalk.yellow('To use this template, you must update following to modules:'))
37
+    console.log()
38
+    for (var i = 0; i < warnings.length; i++) {
39
+      var warning = warnings[i]
40
+      console.log('  ' + warning)
41
+    }
42
+    console.log()
43
+    process.exit(1)
44
+  }
45
+}

+ 9
- 0
VueApp/build/dev-client.js Wyświetl plik

@@ -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
+})

+ 83
- 0
VueApp/build/dev-server.js Wyświetl plik

@@ -0,0 +1,83 @@
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'
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: () => {}
35
+})
36
+// force page reload when html-webpack-plugin template changes
37
+compiler.plugin('compilation', function (compilation) {
38
+  compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
39
+    hotMiddleware.publish({ action: 'reload' })
40
+    cb()
41
+  })
42
+})
43
+
44
+// proxy api requests
45
+Object.keys(proxyTable).forEach(function (context) {
46
+  var options = proxyTable[context]
47
+  if (typeof options === 'string') {
48
+    options = { target: options }
49
+  }
50
+  app.use(proxyMiddleware(options.filter || context, options))
51
+})
52
+
53
+// handle fallback for HTML5 history API
54
+app.use(require('connect-history-api-fallback')())
55
+
56
+// serve webpack bundle output
57
+app.use(devMiddleware)
58
+
59
+// enable hot-reload and state-preserving
60
+// compilation error display
61
+app.use(hotMiddleware)
62
+
63
+// serve pure static assets
64
+var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
65
+app.use(staticPath, express.static('./static'))
66
+
67
+var uri = 'http://localhost:' + port
68
+
69
+devMiddleware.waitUntilValid(function () {
70
+  console.log('> Listening at ' + uri + '\n')
71
+})
72
+
73
+module.exports = app.listen(port, function (err) {
74
+  if (err) {
75
+    console.log(err)
76
+    return
77
+  }
78
+
79
+  // when env is testing, don't need open it
80
+  if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
81
+    opn(uri)
82
+  }
83
+})

+ 71
- 0
VueApp/build/utils.js Wyświetl plik

@@ -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
+  // http://vuejs.github.io/vue-loader/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
+}

+ 12
- 0
VueApp/build/vue-loader.conf.js Wyświetl plik

@@ -0,0 +1,12 @@
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
+}

+ 67
- 0
VueApp/build/webpack.base.conf.js Wyświetl plik

@@ -0,0 +1,67 @@
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
+        query: {
53
+          limit: 10000,
54
+          name: utils.assetsPath('img/[name].[hash:7].[ext]')
55
+        }
56
+      },
57
+      {
58
+        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
59
+        loader: 'url-loader',
60
+        query: {
61
+          limit: 10000,
62
+          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
63
+        }
64
+      }
65
+    ]
66
+  }
67
+}

+ 35
- 0
VueApp/build/webpack.dev.conf.js Wyświetl plik

@@ -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
+})

+ 120
- 0
VueApp/build/webpack.prod.conf.js Wyświetl plik

@@ -0,0 +1,120 @@
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
+    // generate dist index.html with correct asset hash for caching.
48
+    // you can customize output by editing /index.html
49
+    // see https://github.com/ampedandwired/html-webpack-plugin
50
+    new HtmlWebpackPlugin({
51
+      filename: process.env.NODE_ENV === 'testing'
52
+        ? 'index.html'
53
+        : config.build.index,
54
+      template: 'index.html',
55
+      inject: true,
56
+      minify: {
57
+        removeComments: true,
58
+        collapseWhitespace: true,
59
+        removeAttributeQuotes: true
60
+        // more options:
61
+        // https://github.com/kangax/html-minifier#options-quick-reference
62
+      },
63
+      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
64
+      chunksSortMode: 'dependency'
65
+    }),
66
+    // split vendor js into its own file
67
+    new webpack.optimize.CommonsChunkPlugin({
68
+      name: 'vendor',
69
+      minChunks: function (module, count) {
70
+        // any required modules inside node_modules are extracted to vendor
71
+        return (
72
+          module.resource &&
73
+          /\.js$/.test(module.resource) &&
74
+          module.resource.indexOf(
75
+            path.join(__dirname, '../node_modules')
76
+          ) === 0
77
+        )
78
+      }
79
+    }),
80
+    // extract webpack runtime and module manifest to its own file in order to
81
+    // prevent vendor hash from being updated whenever app bundle is updated
82
+    new webpack.optimize.CommonsChunkPlugin({
83
+      name: 'manifest',
84
+      chunks: ['vendor']
85
+    }),
86
+    // copy custom static assets
87
+    new CopyWebpackPlugin([
88
+      {
89
+        from: path.resolve(__dirname, '../static'),
90
+        to: config.build.assetsSubDirectory,
91
+        ignore: ['.*']
92
+      }
93
+    ])
94
+  ]
95
+})
96
+
97
+if (config.build.productionGzip) {
98
+  var CompressionWebpackPlugin = require('compression-webpack-plugin')
99
+
100
+  webpackConfig.plugins.push(
101
+    new CompressionWebpackPlugin({
102
+      asset: '[path].gz[query]',
103
+      algorithm: 'gzip',
104
+      test: new RegExp(
105
+        '\\.(' +
106
+        config.build.productionGzipExtensions.join('|') +
107
+        ')$'
108
+      ),
109
+      threshold: 10240,
110
+      minRatio: 0.8
111
+    })
112
+  )
113
+}
114
+
115
+if (config.build.bundleAnalyzerReport) {
116
+  var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
117
+  webpackConfig.plugins.push(new BundleAnalyzerPlugin())
118
+}
119
+
120
+module.exports = webpackConfig

+ 24
- 0
VueApp/build/webpack.test.conf.js Wyświetl plik

@@ -0,0 +1,24 @@
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
+  plugins: [
15
+    new webpack.DefinePlugin({
16
+      'process.env': require('../config/test.env')
17
+    })
18
+  ]
19
+})
20
+
21
+// no need for app entry during tests
22
+delete webpackConfig.entry
23
+
24
+module.exports = webpackConfig

+ 6
- 0
VueApp/config/dev.env.js Wyświetl plik

@@ -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
VueApp/config/index.js Wyświetl plik

@@ -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: 3000,
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
VueApp/config/prod.env.js Wyświetl plik

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

+ 6
- 0
VueApp/config/test.env.js Wyświetl plik

@@ -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
+})

+ 2
- 0
VueApp/exec.ps1 Wyświetl plik

@@ -0,0 +1,2 @@
1
+docker build -t auth0-vue-01-login .
2
+docker run -p 3000:3000 -it auth0-vue-01-login

+ 3
- 0
VueApp/exec.sh Wyświetl plik

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env bash
2
+docker build -t auth0-vue-01-login .
3
+docker run -p 3000:3000 -it auth0-vue-01-login

+ 11
- 0
VueApp/index.html Wyświetl plik

@@ -0,0 +1,11 @@
1
+<!DOCTYPE html>
2
+<html>
3
+  <head>
4
+    <meta charset="utf-8">
5
+    <title>auth0-vue-samples</title>
6
+  </head>
7
+  <body>
8
+    <div id="app"></div>
9
+    <!-- built files will be auto injected -->
10
+  </body>
11
+</html>

+ 13405
- 0
VueApp/package-lock.json
Plik diff jest za duży
Wyświetl plik


+ 99
- 0
VueApp/package.json Wyświetl plik

@@ -0,0 +1,99 @@
1
+{
2
+  "name": "auth0-vue-samples",
3
+  "version": "1.0.0",
4
+  "description": "A Vue.js project",
5
+  "author": "Auth0",
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
+    "auth0-js": "^9.2.2",
18
+    "bootstrap": "^3.3.7",
19
+    "eslint-plugin-import": "^2.6.1",
20
+    "eslint-plugin-node": "^5.1.0",
21
+    "eventemitter3": "^2.0.3",
22
+    "vue": "^2.3.4",
23
+    "vue-resource": "^1.3.4",
24
+    "vue-router": "^2.7.0"
25
+  },
26
+  "devDependencies": {
27
+    "autoprefixer": "^7.1.1",
28
+    "babel-core": "^6.25.0",
29
+    "babel-eslint": "^7.2.3",
30
+    "babel-loader": "^7.1.1",
31
+    "babel-plugin-transform-runtime": "^6.23.0",
32
+    "babel-preset-env": "^1.5.2",
33
+    "babel-preset-stage-2": "^6.24.1",
34
+    "babel-register": "^6.24.1",
35
+    "chalk": "^2.0.1",
36
+    "connect-history-api-fallback": "^1.3.0",
37
+    "copy-webpack-plugin": "^4.0.1",
38
+    "css-loader": "^0.28.4",
39
+    "eslint": "^4.1.1",
40
+    "eslint-friendly-formatter": "^3.0.0",
41
+    "eslint-loader": "^1.8.0",
42
+    "eslint-plugin-html": "^3.0.0",
43
+    "eslint-config-standard": "^10.2.1",
44
+    "eslint-plugin-promise": "^3.5.0",
45
+    "eslint-plugin-standard": "^3.0.1",
46
+    "eventsource-polyfill": "^0.9.6",
47
+    "express": "^4.15.3",
48
+    "extract-text-webpack-plugin": "^2.1.2",
49
+    "file-loader": "^0.11.2",
50
+    "friendly-errors-webpack-plugin": "^1.6.1",
51
+    "function-bind": "^1.1.0",
52
+    "html-webpack-plugin": "^2.29.0",
53
+    "http-proxy-middleware": "^0.17.4",
54
+    "webpack-bundle-analyzer": "^2.8.2",
55
+    "cross-env": "^5.0.1",
56
+    "karma": "^1.7.0",
57
+    "karma-coverage": "^1.1.1",
58
+    "karma-mocha": "^1.3.0",
59
+    "karma-phantomjs-launcher": "^1.0.4",
60
+    "karma-sinon-chai": "^1.3.1",
61
+    "karma-sourcemap-loader": "^0.3.7",
62
+    "karma-spec-reporter": "0.0.31",
63
+    "karma-webpack": "^2.0.3",
64
+    "lolex": "^1.6.0",
65
+    "mocha": "^3.4.2",
66
+    "chai": "^4.0.2",
67
+    "sinon": "^2.3.6",
68
+    "sinon-chai": "^2.11.0",
69
+    "inject-loader": "^3.0.0",
70
+    "babel-plugin-istanbul": "^4.1.4",
71
+    "phantomjs-prebuilt": "^2.1.14",
72
+    "chromedriver": "^2.30.1",
73
+    "cross-spawn": "^5.1.0",
74
+    "nightwatch": "^0.9.16",
75
+    "selenium-server": "^3.4.0",
76
+    "semver": "^5.3.0",
77
+    "opn": "^5.1.0",
78
+    "optimize-css-assets-webpack-plugin": "^2.0.0",
79
+    "ora": "^1.3.0",
80
+    "rimraf": "^2.6.1",
81
+    "url-loader": "^0.5.9",
82
+    "vue-loader": "^13.0.0",
83
+    "vue-style-loader": "^3.0.1",
84
+    "vue-template-compiler": "^2.3.4",
85
+    "webpack": "^3.0.0",
86
+    "webpack-dev-middleware": "^1.11.0",
87
+    "webpack-hot-middleware": "^2.18.1",
88
+    "webpack-merge": "^4.1.0"
89
+  },
90
+  "engines": {
91
+    "node": ">= 4.0.0",
92
+    "npm": ">= 3.0.0"
93
+  },
94
+  "browserslist": [
95
+    "> 1%",
96
+    "last 2 versions",
97
+    "not ie <= 8"
98
+  ]
99
+}

+ 73
- 0
VueApp/src/App.vue Wyświetl plik

@@ -0,0 +1,73 @@
1
+<template>
2
+  <div>
3
+    <nav class="navbar navbar-default">
4
+      <div class="container-fluid">
5
+        <div class="navbar-header">
6
+          <a class="navbar-brand" href="#">Auth0 - Vue</a>
7
+
8
+          <router-link :to="'/'"
9
+            class="btn btn-primary btn-margin">
10
+              Home
11
+          </router-link>
12
+
13
+          <button
14
+            id="qsLoginBtn"
15
+            class="btn btn-primary btn-margin"
16
+            v-if="!authenticated"
17
+            @click="login()">
18
+              Log In
19
+          </button>
20
+
21
+          <button
22
+            id="qsLogoutBtn"
23
+            class="btn btn-primary btn-margin"
24
+            v-if="authenticated"
25
+            @click="logout()">
26
+              Log Out
27
+          </button>
28
+
29
+        </div>
30
+      </div>
31
+    </nav>
32
+
33
+    <div class="container">
34
+      <router-view 
35
+        :auth="auth" 
36
+        :authenticated="authenticated">
37
+      </router-view>
38
+    </div>
39
+  </div>
40
+</template>
41
+
42
+<script>
43
+import AuthService from './auth/AuthService'
44
+
45
+const auth = new AuthService()
46
+
47
+const { login, logout, authenticated, authNotifier } = auth
48
+
49
+export default {
50
+  name: 'app',
51
+  data () {
52
+    authNotifier.on('authChange', authState => {
53
+      this.authenticated = authState.authenticated
54
+    })
55
+    return {
56
+      auth,
57
+      authenticated
58
+    }
59
+  },
60
+  methods: {
61
+    login,
62
+    logout
63
+  }
64
+}
65
+</script>
66
+
67
+<style>
68
+@import '../node_modules/bootstrap/dist/css/bootstrap.css';
69
+
70
+.btn-margin {
71
+  margin-top: 7px
72
+}
73
+</style>

+ 1
- 0
VueApp/src/assets/loading.svg Wyświetl plik

@@ -0,0 +1 @@
1
+<?xml version="1.0" encoding="utf-8"?><svg width='120px' height='120px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-ring"><rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect><defs><filter id="uil-ring-shadow" x="-100%" y="-100%" width="300%" height="300%"><feOffset result="offOut" in="SourceGraphic" dx="0" dy="0"></feOffset><feGaussianBlur result="blurOut" in="offOut" stdDeviation="0"></feGaussianBlur><feBlend in="SourceGraphic" in2="blurOut" mode="normal"></feBlend></filter></defs><path d="M10,50c0,0,0,0.5,0.1,1.4c0,0.5,0.1,1,0.2,1.7c0,0.3,0.1,0.7,0.1,1.1c0.1,0.4,0.1,0.8,0.2,1.2c0.2,0.8,0.3,1.8,0.5,2.8 c0.3,1,0.6,2.1,0.9,3.2c0.3,1.1,0.9,2.3,1.4,3.5c0.5,1.2,1.2,2.4,1.8,3.7c0.3,0.6,0.8,1.2,1.2,1.9c0.4,0.6,0.8,1.3,1.3,1.9 c1,1.2,1.9,2.6,3.1,3.7c2.2,2.5,5,4.7,7.9,6.7c3,2,6.5,3.4,10.1,4.6c3.6,1.1,7.5,1.5,11.2,1.6c4-0.1,7.7-0.6,11.3-1.6 c3.6-1.2,7-2.6,10-4.6c3-2,5.8-4.2,7.9-6.7c1.2-1.2,2.1-2.5,3.1-3.7c0.5-0.6,0.9-1.3,1.3-1.9c0.4-0.6,0.8-1.3,1.2-1.9 c0.6-1.3,1.3-2.5,1.8-3.7c0.5-1.2,1-2.4,1.4-3.5c0.3-1.1,0.6-2.2,0.9-3.2c0.2-1,0.4-1.9,0.5-2.8c0.1-0.4,0.1-0.8,0.2-1.2 c0-0.4,0.1-0.7,0.1-1.1c0.1-0.7,0.1-1.2,0.2-1.7C90,50.5,90,50,90,50s0,0.5,0,1.4c0,0.5,0,1,0,1.7c0,0.3,0,0.7,0,1.1 c0,0.4-0.1,0.8-0.1,1.2c-0.1,0.9-0.2,1.8-0.4,2.8c-0.2,1-0.5,2.1-0.7,3.3c-0.3,1.2-0.8,2.4-1.2,3.7c-0.2,0.7-0.5,1.3-0.8,1.9 c-0.3,0.7-0.6,1.3-0.9,2c-0.3,0.7-0.7,1.3-1.1,2c-0.4,0.7-0.7,1.4-1.2,2c-1,1.3-1.9,2.7-3.1,4c-2.2,2.7-5,5-8.1,7.1 c-0.8,0.5-1.6,1-2.4,1.5c-0.8,0.5-1.7,0.9-2.6,1.3L66,87.7l-1.4,0.5c-0.9,0.3-1.8,0.7-2.8,1c-3.8,1.1-7.9,1.7-11.8,1.8L47,90.8 c-1,0-2-0.2-3-0.3l-1.5-0.2l-0.7-0.1L41.1,90c-1-0.3-1.9-0.5-2.9-0.7c-0.9-0.3-1.9-0.7-2.8-1L34,87.7l-1.3-0.6 c-0.9-0.4-1.8-0.8-2.6-1.3c-0.8-0.5-1.6-1-2.4-1.5c-3.1-2.1-5.9-4.5-8.1-7.1c-1.2-1.2-2.1-2.7-3.1-4c-0.5-0.6-0.8-1.4-1.2-2 c-0.4-0.7-0.8-1.3-1.1-2c-0.3-0.7-0.6-1.3-0.9-2c-0.3-0.7-0.6-1.3-0.8-1.9c-0.4-1.3-0.9-2.5-1.2-3.7c-0.3-1.2-0.5-2.3-0.7-3.3 c-0.2-1-0.3-2-0.4-2.8c-0.1-0.4-0.1-0.8-0.1-1.2c0-0.4,0-0.7,0-1.1c0-0.7,0-1.2,0-1.7C10,50.5,10,50,10,50z" fill="#337ab7" filter="url(#uil-ring-shadow)"><animateTransform attributeName="transform" type="rotate" from="0 50 50" to="360 50 50" repeatCount="indefinite" dur="1s"></animateTransform></path></svg>

BIN
VueApp/src/assets/logo.png Wyświetl plik


+ 71
- 0
VueApp/src/auth/AuthService.js Wyświetl plik

@@ -0,0 +1,71 @@
1
+import auth0 from 'auth0-js'
2
+import { AUTH_CONFIG } from './auth0-variables'
3
+import EventEmitter from 'eventemitter3'
4
+import router from './../router'
5
+
6
+export default class AuthService {
7
+  authenticated = this.isAuthenticated()
8
+  authNotifier = new EventEmitter()
9
+
10
+  constructor () {
11
+    this.login = this.login.bind(this)
12
+    this.setSession = this.setSession.bind(this)
13
+    this.logout = this.logout.bind(this)
14
+    this.isAuthenticated = this.isAuthenticated.bind(this)
15
+  }
16
+
17
+  auth0 = new auth0.WebAuth({
18
+    domain: AUTH_CONFIG.domain,
19
+    clientID: AUTH_CONFIG.clientId,
20
+    redirectUri: AUTH_CONFIG.callbackUrl,
21
+    audience: `https://${AUTH_CONFIG.domain}/userinfo`,
22
+    responseType: 'token id_token',
23
+    scope: 'openid'
24
+  })
25
+
26
+  login () {
27
+    this.auth0.authorize()
28
+  }
29
+
30
+  handleAuthentication () {
31
+    this.auth0.parseHash((err, authResult) => {
32
+      if (authResult && authResult.accessToken && authResult.idToken) {
33
+        this.setSession(authResult)
34
+        router.replace('home')
35
+      } else if (err) {
36
+        router.replace('home')
37
+        console.log(err)
38
+        alert(`Error: ${err.error}. Check the console for further details.`)
39
+      }
40
+    })
41
+  }
42
+
43
+  setSession (authResult) {
44
+    // Set the time that the access token will expire at
45
+    let expiresAt = JSON.stringify(
46
+      authResult.expiresIn * 1000 + new Date().getTime()
47
+    )
48
+    localStorage.setItem('access_token', authResult.accessToken)
49
+    localStorage.setItem('id_token', authResult.idToken)
50
+    localStorage.setItem('expires_at', expiresAt)
51
+    this.authNotifier.emit('authChange', { authenticated: true })
52
+  }
53
+
54
+  logout () {
55
+    // Clear access token and ID token from local storage
56
+    localStorage.removeItem('access_token')
57
+    localStorage.removeItem('id_token')
58
+    localStorage.removeItem('expires_at')
59
+    this.userProfile = null
60
+    this.authNotifier.emit('authChange', false)
61
+    // navigate to the home route
62
+    router.replace('home')
63
+  }
64
+
65
+  isAuthenticated () {
66
+    // Check whether the current time is past the
67
+    // access token's expiry time
68
+    let expiresAt = JSON.parse(localStorage.getItem('expires_at'))
69
+    return new Date().getTime() < expiresAt
70
+  }
71
+}

+ 31
- 0
VueApp/src/components/Callback.vue Wyświetl plik

@@ -0,0 +1,31 @@
1
+<template>
2
+  <div class="spinner">
3
+    <img src="../assets/loading.svg" alt="loading"/>
4
+  </div>
5
+</template>
6
+
7
+<script>
8
+  export default {
9
+    name: 'callback',
10
+    props: ['auth'],
11
+    data () {
12
+      this.auth.handleAuthentication()
13
+      return {}
14
+    }
15
+  }
16
+</script>
17
+
18
+<style>
19
+  .spinner {
20
+    position: absolute;
21
+    display: flex;
22
+    justify-content: center;
23
+    height: 100vh;
24
+    width: 100vw;
25
+    background-color: white;
26
+    top: 0;
27
+    bottom: 0;
28
+    left: 0;
29
+    right: 0;
30
+  }
31
+</style>

+ 24
- 0
VueApp/src/components/Home.vue Wyświetl plik

@@ -0,0 +1,24 @@
1
+<template>
2
+  <div>
3
+    <h4 v-if="authenticated">
4
+        You are logged in!
5
+    </h4>
6
+    <h4 v-if="!authenticated">
7
+      You are not logged in! Please <a @click="auth.login()">Log In</a> to continue.
8
+    </h4>
9
+  </div>
10
+</template>
11
+
12
+<script>
13
+  export default {
14
+    name: 'home',
15
+    props: ['auth', 'authenticated']
16
+  }
17
+</script>
18
+
19
+<style>
20
+  a {
21
+    cursor: pointer;
22
+  }
23
+</style>
24
+

+ 14
- 0
VueApp/src/main.js Wyświetl plik

@@ -0,0 +1,14 @@
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 App from './App'
5
+import router from './router'
6
+
7
+Vue.config.productionTip = false
8
+
9
+/* eslint-disable no-new */
10
+new Vue({
11
+  el: '#app',
12
+  router,
13
+  render: h => h(App)
14
+})

+ 28
- 0
VueApp/src/router/index.js Wyświetl plik

@@ -0,0 +1,28 @@
1
+import Vue from 'vue'
2
+import Router from 'vue-router'
3
+import Home from '@/components/Home'
4
+import Callback from '@/components/Callback'
5
+
6
+Vue.use(Router)
7
+
8
+const router = new Router({
9
+  mode: 'history',
10
+  routes: [
11
+    {
12
+      path: '/home',
13
+      name: 'Home',
14
+      component: Home
15
+    },
16
+    {
17
+      path: '/callback',
18
+      name: 'Callback',
19
+      component: Callback
20
+    },
21
+    {
22
+      path: '*',
23
+      redirect: '/home'
24
+    }
25
+  ]
26
+})
27
+
28
+export default router

+ 0
- 0
VueApp/static/.gitkeep Wyświetl plik


+ 26
- 0
VueApp/test/e2e/custom-assertions/elementCount.js Wyświetl plik

@@ -0,0 +1,26 @@
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
+    var self = this
20
+    return this.api.execute(function (selector) {
21
+      return document.querySelectorAll(selector).length
22
+    }, [selector], function (res) {
23
+      cb.call(self, res)
24
+    })
25
+  }
26
+}

+ 46
- 0
VueApp/test/e2e/nightwatch.conf.js Wyświetl plik

@@ -0,0 +1,46 @@
1
+require('babel-register')
2
+var config = require('../../config')
3
+
4
+// http://nightwatchjs.org/getingstarted#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
+}

+ 31
- 0
VueApp/test/e2e/runner.js Wyświetl plik

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

+ 19
- 0
VueApp/test/e2e/specs/test.js Wyświetl plik

@@ -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 (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
VueApp/test/unit/.eslintrc Wyświetl plik

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

+ 16
- 0
VueApp/test/unit/index.js Wyświetl plik

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

+ 33
- 0
VueApp/test/unit/karma.conf.js Wyświetl plik

@@ -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
+var 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'],
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
VueApp/test/unit/specs/Hello.spec.js Wyświetl plik

@@ -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
+})