From: Eduardo San Martin Morote Date: Thu, 9 Jun 2022 12:11:24 +0000 (+0200) Subject: test: run on ci try X-Git-Tag: v4.1.0~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe837746240714d94724a46ce8325e1954a2a665;p=thirdparty%2Fvuejs%2Frouter.git test: run on ci try --- diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1a2d631d..fd54e3c6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,6 @@ jobs: - run: pnpm run -r build - run: pnpm run -r build:dts - run: pnpm run -r test:dts - # TODO: add when doable - # - run: pnpm run -r test:e2e:ci + - run: pnpm run -r test:e2e:ci - uses: codecov/codecov-action@v2 diff --git a/packages/router/e2e/local.runner.js b/packages/router/e2e/local.runner.js deleted file mode 100644 index d9a0d405..00000000 --- a/packages/router/e2e/local.runner.js +++ /dev/null @@ -1,52 +0,0 @@ -require('dotenv').config() -const Nightwatch = require('nightwatch') -const browserstack = require('browserstack-local') -const path = require('path') - -const { BROWSERSTACK_ACCESS_KEY } = process.env -if (!BROWSERSTACK_ACCESS_KEY) { - throw new Error( - ` -(ONLY FOR MAINTAINERS) -BROWSERSTACK_ACCESS_KEY is not set. Did you create the .env file? -` - ) -} - -try { - require.main.filename = path.resolve( - __dirname, - '../../../node_modules/.bin/nightwatch' - ) - - // Code to start browserstack local before start of test - console.log('Connecting local') - - const bs_local = new browserstack.Local() - Nightwatch.bs_local = bs_local - - bs_local.start( - { key: process.env.BROWSERSTACK_ACCESS_KEY }, - function (error) { - if (error) throw error - - console.log('Connected. Now testing...') - Nightwatch.cli(function (argv) { - Nightwatch.CliRunner(argv) - .setup() - .runTests() - .catch(err => { - throw err - }) - .finally(() => { - // Code to stop browserstack local after end of single test - bs_local.stop(function () {}) - }) - }) - } - ) -} catch (ex) { - console.log('There was an error while starting the test runner:\n\n') - process.stderr.write(ex.stack + '\n') - process.exit(2) -} diff --git a/packages/router/e2e/runner.js b/packages/router/e2e/runner.js new file mode 100644 index 00000000..0f290363 --- /dev/null +++ b/packages/router/e2e/runner.js @@ -0,0 +1,64 @@ +require('dotenv').config() +const Nightwatch = require('nightwatch') +const browserstack = require('browserstack-local') +const path = require('path') + +const { BROWSERSTACK_ACCESS_KEY } = process.env +if (!BROWSERSTACK_ACCESS_KEY) { + throw new Error( + ` +(ONLY FOR MAINTAINERS) +BROWSERSTACK_ACCESS_KEY is not set. Did you create the .env file? +` + ) +} + +const args = process.argv.slice(2) + +// allow running browserstack local +// note this works because nighwatch doesn't use this option +const isLocal = args.indexOf('--local') > -1 + +try { + require.main.filename = path.resolve( + __dirname, + '../../../node_modules/.bin/nightwatch' + ) + + // Code to start browserstack local before start of test + console.log('Connecting local') + + /** @type {import('browserstack-local').Local} */ + let bs_local + if (isLocal) { + bs_local = new browserstack.Local() + Nightwatch.bs_local = bs_local + + bs_local.start( + { key: process.env.BROWSERSTACK_ACCESS_KEY }, + async error => { + if (error) throw error + + console.log('Connected. Now testing...') + await runNighwatchCli().finally(() => { + // Code to stop browserstack local after end of single test + bs_local.stop(() => {}) + }) + } + ) + } else { + runNighwatchCli() + } +} catch (ex) { + console.log('There was an error while starting the test runner:\n\n') + process.stderr.write(ex.stack + '\n') + process.exit(2) +} + +function runNighwatchCli() { + return new Promise((resolve, reject) => { + Nightwatch.cli(argv => { + Nightwatch.CliRunner(argv).setup().runTests().then(resolve).catch(reject) + }) + }) +} diff --git a/packages/router/e2e/specs/encoding.js b/packages/router/e2e/specs/encoding.js index 17bcb535..c55fdc3d 100644 --- a/packages/router/e2e/specs/encoding.js +++ b/packages/router/e2e/specs/encoding.js @@ -20,9 +20,9 @@ module.exports = { .click('li:nth-child(3) a') .assert.urlEquals(baseURL + '/documents/%E2%82%ACuro') - .assert.containsText('#fullPath', '/documents/%E2%82%ACuro') - .assert.containsText('#path', '/documents/%E2%82%ACuro') - .assert.containsText('#p-id', '"€uro"') + .assert.textContains('#fullPath', '/documents/%E2%82%ACuro') + .assert.textContains('#path', '/documents/%E2%82%ACuro') + .assert.textContains('#p-id', '"€uro"') // full encoding test .click('li:nth-child(8) a') @@ -48,16 +48,16 @@ module.exports = { browser .url(baseURL + '/documents/%E2%82%ACuro') .waitForElementPresent('#app > *', TIMEOUT) - // .assert.containsText('#fullPath', '/documents/%E2%82%ACuro') - // .assert.containsText('#path', '/documents/%E2%82%ACuro') - .assert.containsText('#p-id', '"€uro"') + // .assert.textContains('#fullPath', '/documents/%E2%82%ACuro') + // .assert.textContains('#path', '/documents/%E2%82%ACuro') + .assert.textContains('#p-id', '"€uro"') // TODO: invalid in safari, tests on those where this is valid // .url(baseURL + '/unicode/€uro') // .waitForElementPresent('#app > *', TIMEOUT) // navigation to unencoded value // depending on the browser the value will be encoded or not - // .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2)) + // .assert.textContains('#params', JSON.stringify({ id: '€uro' }, null, 2)) .end() }, diff --git a/packages/router/nightwatch.conf.js b/packages/router/nightwatch.conf.js index 28a977b8..ba1ccf19 100644 --- a/packages/router/nightwatch.conf.js +++ b/packages/router/nightwatch.conf.js @@ -50,16 +50,12 @@ module.exports = { browserName: 'chrome', 'goog:chromeOptions': { w3c: true, - args: ['window-size=1280,800', 'headless'], }, }, webdriver: { start_process: true, server_path: '', - cli_args: [ - // --verbose - ], }, }, @@ -124,6 +120,13 @@ module.exports = { 'chrome-headless': { extends: 'default', + desiredCapabilities: { + browserName: 'chrome', + 'goog:chromeOptions': { + w3c: true, + args: ['window-size=1280,800', 'headless'], + }, + }, }, edge: { @@ -189,30 +192,6 @@ module.exports = { }, }, - 'browserstack.chrome': { - extends: 'browserstack', - desiredCapabilities: { - browserName: 'chrome', - chromeOptions: { - w3c: true, - }, - }, - }, - - 'browserstack.firefox': { - extends: 'browserstack', - desiredCapabilities: { - browserName: 'firefox', - }, - }, - - 'browserstack.safari': { - extends: 'browserstack', - desiredCapabilities: { - browserName: 'safari', - }, - }, - 'browserstack.local_chrome': { extends: 'browserstack.local', desiredCapabilities: { diff --git a/packages/router/package.json b/packages/router/package.json index 63eb30eb..cb47bf0e 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -67,10 +67,10 @@ "test:unit": "jest --coverage", "test": "pnpm run test:types && pnpm run test:unit && pnpm run build && pnpm run build:dts && pnpm run test:e2e", "test:e2e": "pnpm run test:e2e:headless && pnpm run test:e2e:native", - "test:e2e:headless": "node e2e/runner.js -e chrome-headless --skiptags no-headless", - "test:e2e:native": "node e2e/runner.js -e chrome --tag no-headless", - "test:e2e:ci": "node e2e/runner.js -e firefox --retries 2", - "test:e2e:bs": "node e2e/local.runner.js -e edge_pre_chrome,android44 --tag browserstack" + "test:e2e:headless": "nightwatch --skiptags no-headless", + "test:e2e:native": "nightwatch --env chrome", + "test:e2e:ci": "nightwatch --env chrome --retries 2", + "test:e2e:bs": "node e2e/runner.js -e edge_pre_chrome,android44 --tag browserstack" }, "gitHooks": { "pre-commit": "lint-staged",