+++ /dev/null
-const axios = require('axios')
-
-const { BS_USER, BS_KEY } = process.env
-
-function getKey(client) {
- // const { capabilities, currentTest } = client
- // originally i wanted to use this but it turns out the information changes
- // on the afterEach, making the key non valid. But because every environment
- // runs on a different thread, the sessionMap object is only shared for a given
- // environment, so only using the name of the test (currentTest.module) seems to be
- // enough
- // return `${capabilities.platform}::${capabilities.browserName}@${
- // capabilities.version
- // } ${currentTest.module}: ${currentTest.name}`
-
- return `${client.currentTest.module}: ${client.currentTest.name}`
-}
-
-function shouldSkipBrowserstackReporting(client) {
- return !BS_USER || !BS_KEY || client.options.selenium_port !== 80
-}
-
-/**
- * Generates an object with beforeEach and afterEach functions to be added to
- * every test suite. It cannot be added globally because these must be executed
- * before each test (instead of each test suite as it does in globalModules)
- */
-module.exports = function sendStatus() {
- const sessionMap = Object.create(null)
-
- return {
- beforeEach(browser, cb) {
- // avoid running if missing credentials
- if (shouldSkipBrowserstackReporting(this.client)) return cb()
- // retrieve the session and save it to the map
- const key = getKey(this.client)
- browser.session(({ sessionId }) => {
- sessionMap[key] = sessionId
- cb()
- })
- },
-
- afterEach(browser, cb) {
- // avoid running if missing credentials
- if (shouldSkipBrowserstackReporting(this.client)) return cb()
- const key = getKey(this.client)
- const { results } = this.client.currentTest
- const sessionId = sessionMap[key]
-
- if (!sessionId) {
- console.warn('❌ Cannot find sessionId for ' + key)
- return cb()
- }
-
- if (results.errors > 0 || results.failed > 0) {
- const reason = results.lastError.message
- console.log('Found failed test', reason)
- axios
- .put(
- `https://api.browserstack.com/automate/sessions/${sessionId}.json`,
- {
- // change the name so it's easier to find
- name: key,
- status: 'failed',
- reason,
- },
- {
- auth: {
- username: BS_USER,
- password: BS_KEY,
- },
- }
- )
- .catch(err => {
- console.log('❌ Failed changing status for sessions', err)
- })
- .then(() => {
- console.log('✅ Sent for', sessionId)
- cb()
- })
- } else {
- cb()
- }
- },
- }
-}
+++ /dev/null
-/**
- * Running tests on remote browsers
- */
-
-const { BS_USER, BS_KEY } = process.env
-
-const nwConf = {
- src_folders: ['e2e/specs'],
- output_folder: 'e2e/reports',
- custom_commands_path: ['node_modules/nightwatch-helpers/commands'],
- custom_assertions_path: ['node_modules/nightwatch-helpers/assertions'],
- // set to true when testing on multiple browsers (-e chrome,firefox) to display tests as they pass instead of waiting for everything to be finished
- live_output: true,
-
- // this couldn't work at the end, so we used ./browserstack-send-status.js
- // globals_path: resolve(__dirname, './globalModules.js'),
-
- selenium: {
- start_process: false,
- host: 'hub-cloud.browserstack.com',
- port: 80,
- },
-
- common_capabilities: {
- 'browserstack.user': BS_USER,
- 'browserstack.key': BS_KEY,
- name: 'Bstack-[Nightwatch] Vue Router Parallel Test',
- 'browserstack.local': true,
- // useful to get visual logs
- // 'browserstack.debug': true,
- // 'browserstack.console': 'verbose',
- // 'browserstack.video': false,
- acceptSslCerts: true,
- resolution: '1024x768',
- },
-
- test_settings: {
- // default: {},
-
- chrome: {
- desiredCapabilities: {
- browser: 'chrome',
- },
- },
-
- chromeQt: {
- desiredCapabilities: {
- browser: 'chrome',
- browser_version: '49.0',
- },
- },
-
- firefox: {
- desiredCapabilities: {
- browser: 'firefox',
- },
- },
-
- safari: {
- desiredCapabilities: {
- os: 'OS X',
- os_version: 'Mojave',
- browser: 'Safari',
- browser_version: '12.0',
- },
- },
-
- safari6: {
- desiredCapabilities: {
- os: 'OS X',
- os_version: 'Lion',
- browser: 'Safari',
- browser_version: '6.0',
- },
- },
-
- ie: {
- desiredCapabilities: {
- browser: 'internet explorer',
- browser_version: '11',
- // name: 'Bstack-[Nightwatch] Vue Router',
- // 'browserstack.video': true,
- },
- },
-
- edge_pre_chrome: {
- desiredCapabilities: {
- browser: 'Edge',
- browser_version: '18',
- },
- },
-
- android44: {
- desiredCapabilities: {
- device: 'Google Nexus 5',
- realMobile: 'true',
- os_version: '4.4',
- },
- },
-
- ios7: {
- desiredCapabilities: {
- device: 'iPhone 7',
- realMobile: 'true',
- os_version: '10',
- },
- },
- },
-}
-
-// Code to copy selenium host/port into test settings
-for (const setting in nwConf.test_settings) {
- const config = nwConf.test_settings[setting]
- config['selenium_host'] = nwConf.selenium.host
- config['selenium_port'] = nwConf.selenium.port
-
- // merge common_capabilities
- for (const key in nwConf.common_capabilities) {
- // fallback to common_capabilities
- config['desiredCapabilities'][key] =
- config['desiredCapabilities'][key] || nwConf.common_capabilities[key]
- }
-}
-
-module.exports = nwConf
+++ /dev/null
-// yarn nightwatch -e chrome,safari,firefox
-
-/** @type {import('nightwatch').NightwatchTestSettingScreenshots} */
-const browserDefaults = {
- selenium_port: 4444,
- selenium_host: 'localhost',
- silent: true,
- screenshots: {
- enabled: true,
- on_failure: true,
- on_error: false,
- path: 'e2e/screenshots',
- },
-}
-
-const geckodriverPath = require('geckodriver').path
-const chromedriverPath = require('chromedriver').path
-
-/** @type {import('nightwatch').NightwatchOptions} */
-module.exports = {
- src_folders: ['e2e/specs'],
- output_folder: 'e2e/reports',
- custom_commands_path: ['node_modules/nightwatch-helpers/commands'],
- custom_assertions_path: ['node_modules/nightwatch-helpers/assertions'],
- // set to true when testing on multiple browsers (-e chrome,firefox) to display tests as they pass instead of waiting for everything to be finished
- live_output: false,
-
- selenium: {
- start_process: true,
- start_session: true,
- host: '127.0.0.1',
- port: 4444,
- server_path: require('selenium-server').path,
- cli_args: {
- 'webdriver.chrome.driver': chromedriverPath,
- 'webdriver.gecko.driver': geckodriverPath,
- },
- },
-
- webdriver: {
- start_process: false,
- },
-
- test_settings: {
- default: {
- launch_url: 'https://nightwatchjs.org',
- },
-
- chrome: {
- ...browserDefaults,
- desiredCapabilities: {
- browserName: 'chrome',
- acceptSslCerts: true,
- chromeOptions: {
- // https://github.com/nightwatchjs/nightwatch/releases/tag/v1.1.12
- w3c: false,
- args: ['window-size=1280,800'],
- },
- },
- },
-
- 'chrome-headless': {
- ...browserDefaults,
- desiredCapabilities: {
- browserName: 'chrome',
- acceptSslCerts: true,
- chromeOptions: {
- w3c: false,
- args: ['window-size=1280,800', 'headless'],
- },
- },
- },
-
- safari: {
- ...browserDefaults,
- desiredCapabilities: {
- browserName: 'safari',
- acceptSslCerts: true,
- },
- },
-
- // TODO: not working
- firefox: {
- ...browserDefaults,
- desiredCapabilities: {
- browserName: 'firefox',
- acceptSslCerts: true,
- 'moz:firefoxOptions': {
- binary: geckodriverPath,
- args: [],
- },
- },
- },
- },
-}
+++ /dev/null
-/**
- * Running tests
- *
- * By default tests are run locally on chrome headless
- * $ node e2e/runner.js
- *
- * You can run a specific test by passing it, or pass various tests
- * $ node e2e/runner.js e2e/specs/basic.js e2e/specs/redirect.js
- *
- * You can specify a list of browsers to run from nightwatch.config.js with -e separated by a comma
- * $ node e2e/runner.js -e safari,firefox
- *
- * If you are already running the dev server with `yarn run serve`, you can pass the --dev option to avoid launching the server
- * $ node e2e/runner.js --dev
- * **Make sure to pass the option at the end:**
- * $ node e2e/runner.js e2e/specs/basic.js --dev
- *
- * __For maintainers only__
- * You can trigger tests on Browserstack on other browsers by passing the --local option
- * It's also required to pass the list of browsers to test on to avoid launching too many tests. Available options are located inside nightwatch.browserstack.js
- * $ node e2e/runner.js --local -e ie,chrome50
- */
-
-require('dotenv').config()
-const { resolve } = require('path')
-const Nightwatch = require('nightwatch')
-const args = process.argv.slice(2)
-
-// allow running browserstack local
-const isLocal = args.indexOf('--local') > -1
-
-if (isLocal && (!process.env.BS_USER || !process.env.BS_KEY)) {
- console.log(
- 'Hey!\n',
- 'You are missing credentials for Browserstack.\n',
- 'If you are a contributor, this is normal, credentials are private. These tests must be run by a maintainer of vue-router',
- 'If you are a maintainer, make sure to create your `.env` file with both `BS_USER` and `BS_KEY` variables!'
- )
- // fail if testing locally
- process.exit(process.env.CI ? 0 : 1)
-}
-
-// if we are running yarn dev locally, we can pass --dev to avoid launching another server instance
-const server =
- args.indexOf('--dev') > -1
- ? null
- : // : process.env.CI || args.indexOf('--ci') > -1
- // ? require('./staticServer')
- require('./devServer')
-
-const DEFAULT_CONFIG = './nightwatch.json'
-const NW_CONFIG = isLocal
- ? resolve(__dirname, './nightwatch.browserstack.js')
- : resolve(__dirname, './nightwatch.config.js')
-
-// check -c option is passed when using multiple environments
-if (args.indexOf('-c') < 0) {
- // check if multiple envs are provided. The way Nightwatch works
- // requires to explicitly provide the conf
- const envs = args[args.indexOf('-e') + 1]
- if (envs && envs.indexOf(',') > -1) {
- console.warn(
- `Specify the conf when providing multiple browsers:\n$ yarn run test:e2e ${args.join(
- ' '
- )} -c ${NW_CONFIG}`
- )
- process.exit(1)
- }
-} else if (isLocal) {
- const conf = args[args.indexOf('-c') + 1]
- if (resolve('.', conf) !== NW_CONFIG) {
- console.warn('The passed config should be', NW_CONFIG)
- process.exit(1)
- }
-}
-
-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.test = argv['_'].slice(0)
-
- if (argv.c === DEFAULT_CONFIG && argv.config === DEFAULT_CONFIG) {
- argv.config = argv.c = NW_CONFIG
- }
- // Nightwatch does not accept an array with one element
- if (argv.test.length === 1) argv.test = argv.test[0]
-
- // debugging easily
- // console.log(argv)
- // process.exit(0)
-}
-
-process.mainModule.filename = resolve(
- __dirname,
- '../node_modules/.bin/nightwatch'
-)
-
-if (isLocal) {
- let bsLocal
- const browserstack = require('browserstack-local')
- Nightwatch.bs_local = bsLocal = new browserstack.Local()
- bsLocal.start({ key: process.env.BS_KEY }, error => {
- if (error) throw error
-
- console.log('Connected. Now testing...')
- try {
- Nightwatch.cli(argv => {
- adaptArgv(argv)
- Nightwatch.CliRunner(argv)
- .setup(null, () => {
- // NOTE: I don't know when this is running or if it does
- // Code to stop browserstack local after end of parallel test
- bsLocal.stop(() => {
- server && server.close()
- process.exit(0)
- })
- })
- .runTests()
- .then(() => {
- // Code to stop browserstack local after end of single test
- bsLocal.stop(() => {
- server && server.close()
- process.exit(0)
- })
- })
- .catch(() => {
- server && server.close()
- // fail execution
- process.exit(1)
- })
- })
- } catch (err) {
- console.error(err)
- bsLocal.stop(() => {
- process.exit(1)
- })
- }
- })
-} else {
- // create the Nightwatch CLI runner
- Nightwatch.cli(argv => {
- adaptArgv(argv)
- const runner = Nightwatch.CliRunner(argv)
-
- // setup and run tests
- runner
- .setup()
- .startWebDriver()
- .then(() => runner.runTests())
- .then(() => {
- runner.stopWebDriver()
- server && server.close()
- process.exit(0)
- })
- .catch(err => {
- server && server.close()
- console.error(err)
- process.exit(1)
- })
- })
-}
+++ /dev/null
-const handler = require('serve-handler')
-const http = require('http')
-const fs = require('fs')
-const path = require('path')
-
-/** @type {string[]} */
-let examples = []
-const buildDir = path.join(__dirname, '__build__')
-fs.readdirSync(buildDir).forEach(file => {
- if (file.endsWith('.html') && !/index\.html$/.test(file)) {
- const fullPath = path.join(buildDir, file)
- if (fs.statSync(fullPath).isFile() && fs.existsSync(fullPath)) {
- examples.push(file.replace(/\.html$/, ''))
- }
- }
-})
-
-const server = http.createServer((request, response) => {
- return handler(request, response, {
- public: path.join(__dirname, '__build__'),
- cleanUrls: true,
- rewrites: examples.map(name => ({
- source: `${name}/**`,
- destination: `${name}.html`,
- })),
- })
-})
-
-const port = process.env.PORT || 3000
-module.exports = server.listen(port, () => {
- console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`)
-})