From: Eduardo San Martin Morote Date: Wed, 16 Oct 2019 19:36:54 +0000 (+0200) Subject: test(e2e): refactor configs X-Git-Tag: v4.0.0-alpha.0~188 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e44e439bc5ea2908592111bb4f650f52f7a9b971;p=thirdparty%2Fvuejs%2Frouter.git test(e2e): refactor configs --- diff --git a/e2e/nightwatch.browserstack.js b/e2e/nightwatch.browserstack.js index 9a08014c..7b207692 100644 --- a/e2e/nightwatch.browserstack.js +++ b/e2e/nightwatch.browserstack.js @@ -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', }, diff --git a/e2e/runner.js b/e2e/runner.js index dda6e5c1..d17dee99 100644 --- a/e2e/runner.js +++ b/e2e/runner.js @@ -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) { diff --git a/examples/encoding/index.html b/examples/encoding/index.html index f8982d24..ca1ab4c8 100644 --- a/examples/encoding/index.html +++ b/examples/encoding/index.html @@ -46,10 +46,6 @@
  • /
  • -
  • - - --> -
  • /documents/%E2%82%AC /currency=€uro&é=e (object)/?currency=€uro&é=e (object)
  • - /n/%E2%82%AC (force reload) + /n/%E2%82%AC (force reload)
  • - /n/€ (force reload): not valid tho + /n/€ (force reload): not valid tho
  • diff --git a/examples/encoding/index.ts b/examples/encoding/index.ts index 8cc50cf9..9f4fc529 100644 --- a/examples/encoding/index.ts +++ b/examples/encoding/index.ts @@ -14,8 +14,6 @@ const Document: RouteComponent = { template: `
    Document: {{ $route.params.id }}
    `, } -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 index 00000000..8c60324b --- /dev/null +++ b/examples/hash/index.html @@ -0,0 +1,76 @@ + + + + + + + Vue Router Examples - Hash + + + + +
    +
    + Name: +
    {{ $route.name }}
    +
    + +
    + Params: +
    {{ $route.params }}
    +
    + +
    + Query: +
    {{ $route.query }}
    +
    + +
    + Hash: +
    {{ $route.hash }}
    +
    + +
    + FullPath: +
    {{ $route.fullPath }}
    +
    + +
    + path: +
    {{ $route.path }}
    +
    + +
    + + + + +
    + + diff --git a/examples/hash/index.ts b/examples/hash/index.ts new file mode 100644 index 00000000..04ddab58 --- /dev/null +++ b/examples/hash/index.ts @@ -0,0 +1,34 @@ +import { Router, plugin, createHashHistory } from '../../src' +import { RouteComponent } from '../../src/types' +import Vue from 'vue' + +const component: RouteComponent = { + template: `
    A component
    `, +} + +const Home: RouteComponent = { + template: `
    Home
    `, +} + +const Document: RouteComponent = { + template: `
    Document: {{ $route.params.id }}
    `, +} + +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, +}) diff --git a/examples/webpack.config.js b/examples/webpack.config.js index 9ac41218..a8820926 100644 --- a/examples/webpack.config.js +++ b/examples/webpack.config.js @@ -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), diff --git a/package.json b/package.json index 83b3c485..87967edb 100644 --- a/package.json +++ b/package.json @@ -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",