]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test(e2e): refactor configs
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 16 Oct 2019 19:36:54 +0000 (21:36 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 16 Oct 2019 19:36:54 +0000 (21:36 +0200)
e2e/nightwatch.browserstack.js
e2e/runner.js
examples/encoding/index.html
examples/encoding/index.ts
examples/hash/index.html [new file with mode: 0644]
examples/hash/index.ts [new file with mode: 0644]
examples/webpack.config.js
package.json

index 9a08014c3d1d440c434c6d25d7a75d5ac4791d0b..7b207692cf82bcd4860f4b4644211b6a2bea28c4 100644 (file)
@@ -28,6 +28,8 @@ const nwConf = {
     name: 'Bstack-[Nightwatch] Vue Router Parallel Test',
     'browserstack.local': true,
     'browserstack.video': false,
+    // useful to get visual logs
+    // 'browserstack.debug': true,
     acceptSslCerts: true,
     resolution: '1024x768',
   },
index dda6e5c1a0988ca0992fb2aeb746952f896c32e5..d17dee998b119ab1490802e196738415ff0c3b7b 100644 (file)
@@ -61,7 +61,7 @@ if (args.indexOf('-c') < 0) {
 function adaptArgv(argv) {
   // take every remaining argument and treat it as a test file
   // this allows to run `node e2e/runner.js test/e2e/basic.js`
-  argv.retries = 1
+  // argv.retries = 1
   argv.test = argv['_'].slice(0)
 
   if (argv.c === DEFAULT_CONFIG && argv.config === DEFAULT_CONFIG) {
index f8982d2463e6dcad609b4c7220d108a84cee82b5..ca1ab4c84201d13f1ce25dc42cb539e45ae35560 100644 (file)
         <li>
           <router-link to="/">/</router-link>
         </li>
-        <li>
-          <!-- <router-link to="/n/€">/n/€</!-->
-          -->
-        </li>
         <li>
           <router-link to="/documents/%E2%82%AC"
             >/documents/%E2%82%AC</router-link
         <li>
           <router-link
             :to="{ name: 'home', query: { currency: '€uro', 'é': 'e' }}"
-            >/currency=€uro&é=e (object)</router-link
+            >/?currency=€uro&é=e (object)</router-link
           >
         </li>
         <li>
-          <a href="/n/%E2%82%AC">/n/%E2%82%AC (force reload)</a>
+          <a href="/encoding/n/%E2%82%AC">/n/%E2%82%AC (force reload)</a>
         </li>
         <li>
-          <a href="/n/€">/n/€ (force reload): not valid tho</a>
+          <a href="/encoding/n/€">/n/€ (force reload): not valid tho</a>
         </li>
       </ul>
 
index 8cc50cf91d189ff98d074d375fe7f292c8275124..9f4fc5297dbd0433d0cec7f150d60a306f1c6d46 100644 (file)
@@ -14,8 +14,6 @@ const Document: RouteComponent = {
   template: `<div>Document: {{ $route.params.id }}</div>`,
 }
 
-console.log('/' + __dirname)
-
 const router = new Router({
   history: createHistory('/' + __dirname),
   routes: [
diff --git a/examples/hash/index.html b/examples/hash/index.html
new file mode 100644 (file)
index 0000000..8c60324
--- /dev/null
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
+    <title>Vue Router Examples - Hash</title>
+    <!-- TODO: replace with local imports for promises and anything else needed -->
+    <script src="https://polyfill.io/v3/polyfill.min.js?features=default%2Ces2015"></script>
+  </head>
+  <body>
+    <div id="app">
+      <section class="info">
+        Name:
+        <pre id="name">{{ $route.name }}</pre>
+      </section>
+
+      <section class="info">
+        Params:
+        <pre id="params">{{ $route.params }}</pre>
+      </section>
+
+      <section class="info">
+        Query:
+        <pre id="query">{{ $route.query }}</pre>
+      </section>
+
+      <section class="info">
+        Hash:
+        <pre id="hash">{{ $route.hash }}</pre>
+      </section>
+
+      <section class="info">
+        FullPath:
+        <pre id="fullPath">{{ $route.fullPath }}</pre>
+      </section>
+
+      <section class="info">
+        path:
+        <pre id="path">{{ $route.path }}</pre>
+      </section>
+
+      <hr />
+
+      <ul>
+        <li>
+          <router-link to="/">/</router-link>
+        </li>
+        <li>
+          <router-link to="/documents/%E2%82%AC"
+            >/documents/%E2%82%AC</router-link
+          >
+        </li>
+        <li>
+          <router-link :to="{ name: 'docs', params: { id: '€uro' }}"
+            >/documents/€uro (object)</router-link
+          >
+        </li>
+        <li>
+          <router-link
+            :to="{ name: 'home', query: { currency: '€uro', 'é': 'e' }}"
+            >/?currency=€uro&é=e (object)</router-link
+          >
+        </li>
+        <li>
+          <a href="/encoding/n/%E2%82%AC">/n/%E2%82%AC (force reload)</a>
+        </li>
+        <li>
+          <a href="/encoding/n/€">/n/€ (force reload): not valid tho</a>
+        </li>
+      </ul>
+
+      <router-view></router-view>
+    </div>
+  </body>
+</html>
diff --git a/examples/hash/index.ts b/examples/hash/index.ts
new file mode 100644 (file)
index 0000000..04ddab5
--- /dev/null
@@ -0,0 +1,34 @@
+import { Router, plugin, createHashHistory } from '../../src'
+import { RouteComponent } from '../../src/types'
+import Vue from 'vue'
+
+const component: RouteComponent = {
+  template: `<div>A component</div>`,
+}
+
+const Home: RouteComponent = {
+  template: `<div>Home</div>`,
+}
+
+const Document: RouteComponent = {
+  template: `<div>Document: {{ $route.params.id }}</div>`,
+}
+
+const router = new Router({
+  history: createHashHistory('/' + __dirname),
+  routes: [
+    { path: '/', component: Home, name: 'home' },
+    { path: '/documents/:id', name: 'docs', component: Document },
+    { path: encodeURI('/n/€'), name: 'euro', component },
+  ],
+})
+
+// use the router
+Vue.use(plugin)
+
+// @ts-ignore
+window.vm = new Vue({
+  el: '#app',
+  // @ts-ignore
+  router,
+})
index 9ac412180843a474ff1981775f7b7375a550b13f..a8820926d6d3a534460fdcfce0cf28c2e31e80b8 100644 (file)
@@ -1,9 +1,18 @@
+// @ts-check
 const fs = require('fs')
 const { resolve, join } = require('path')
 const HtmlWebpackPlugin = require('html-webpack-plugin')
 const webpack = require('webpack')
 
-const outputPath = resolve(__dirname, '__build__')
+/** @type {string[]} */
+let examples = []
+fs.readdirSync(__dirname).forEach(dir => {
+  const fullDir = join(__dirname, dir)
+  const entry = join(fullDir, 'index.ts')
+  if (fs.statSync(fullDir).isDirectory() && fs.existsSync(entry)) {
+    examples.push(dir)
+  }
+})
 
 module.exports = {
   // Expose __dirname to allow automatically setting basename.
@@ -18,14 +27,26 @@ module.exports = {
   devServer: {
     // contentBase: outputPath,
     historyApiFallback: {
-      rewrites: [{ from: /^\/encoding(?:\/?|\/.*)$/, to: '/encoding.html' }],
+      rewrites: examples.map(name => ({
+        from: new RegExp(`^/${name}(?:\\/?|/.*)$`),
+        to: `/${name}.html`,
+      })),
+      // rewrites: [
+      //   { from: /^\/encoding(?:\/?|\/.*)$/, to: '/encoding.html' },
+      //   { from: /^\/hash(?:\/?|\/.*)$/, to: '/hash.html' },
+      // ],
     },
     // hot: true,
   },
 
-  entry: {
-    encoding: resolve(__dirname, 'encoding/index.ts'),
-  },
+  entry: examples.reduce((entries, name) => {
+    entries[name] = resolve(__dirname, name, 'index.ts')
+    return entries
+  }, {}),
+  // entry: {
+  //   encoding: resolve(__dirname, 'encoding/index.ts'),
+  //   hash: resolve(__dirname, 'hash/index.ts'),
+  // },
   // entry: fs.readdirSync(__dirname).reduce((entries, dir) => {
   //   const fullDir = path.join(__dirname, dir)
   //   const entry = path.join(fullDir, 'index.ts')
@@ -60,13 +81,14 @@ module.exports = {
     extensions: ['.ts', '.tsx', '.js'],
   },
   plugins: [
-    new HtmlWebpackPlugin({
-      // inject: false,
-      // chunks: ['encoding'],
-      filename: 'encoding.html',
-      title: 'Vue Router Examples - encoding',
-      template: resolve(__dirname, 'encoding/index.html'),
-    }),
+    ...examples.map(
+      name =>
+        new HtmlWebpackPlugin({
+          filename: `${name}.html`,
+          chunks: [name],
+          template: resolve(__dirname, name, 'index.html'),
+        })
+    ),
     new webpack.DefinePlugin({
       'process.env': {
         NODE_ENV: JSON.stringify(process.env.NODE_ENV),
index 83b3c485bda8071b2489475e2cb037774c331745..87967edbf8b8cf8b99b986f935dd7ead5a9d9bb5 100644 (file)
@@ -13,7 +13,8 @@
     "test:unit": "jest --coverage",
     "test": "yarn run test:types && yarn run test:unit && yarn build",
     "build": "yarn rollup -c rollup.config.js",
-    "dev": "webpack-dev-server --mode=development"
+    "dev": "webpack-dev-server --mode=development",
+    "dev:examples": "webpack-dev-server --mode=development --config examples/webpack.config.js"
   },
   "devDependencies": {
     "@types/jest": "^24.0.18",