From 56884224873ff9308b83ef0874bdbe7a5b38e1b3 Mon Sep 17 00:00:00 2001 From: Mark <mark@openappstack.net> Date: Tue, 5 Nov 2019 13:52:47 +0100 Subject: [PATCH] Add e2e testing boilerplate --- frontend/package.json | 5 ++++ frontend/test/e2e/index.test.js | 10 ++++++++ frontend/test/nightwatch.json | 16 +++++++++++++ frontend/test/nightwatch_globals.js | 37 +++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 frontend/test/e2e/index.test.js create mode 100644 frontend/test/nightwatch.json create mode 100644 frontend/test/nightwatch_globals.js diff --git a/frontend/package.json b/frontend/package.json index 136e86e..f36a316 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -9,6 +9,7 @@ "build": "nuxt build", "start": "nuxt start", "post-update": "yarn upgrade --latest", + "test": "nightwatch --config ./test/nightwatch.json", "build-start": "nuxt build; nuxt start" }, "author": "", @@ -20,5 +21,9 @@ "cookie-parser": "^1.4.4", "nuxt": "latest", "openid-client": "^3.7.3" + }, + "devDependencies": { + "chromedriver": "^77.0.0", + "nightwatch": "^1.2.4" } } diff --git a/frontend/test/e2e/index.test.js b/frontend/test/e2e/index.test.js new file mode 100644 index 0000000..d6cb9c7 --- /dev/null +++ b/frontend/test/e2e/index.test.js @@ -0,0 +1,10 @@ +module.exports = { + 'Demo test Index' : function (browser) { + console.log(this) + browser + .url(browser.globals.url) + .waitForElementVisible('body') + .assert.containsText('.jumbotron', 'Welcome to OpenAppStack') + .end(); + } +}; diff --git a/frontend/test/nightwatch.json b/frontend/test/nightwatch.json new file mode 100644 index 0000000..cdcb831 --- /dev/null +++ b/frontend/test/nightwatch.json @@ -0,0 +1,16 @@ +{ + "src_folders" : ["e2e"], + "webdriver" : { + "start_process": true, + "server_path": "node_modules/.bin/chromedriver", + "port": 9515 + }, + "test_settings" : { + "default" : { + "desiredCapabilities": { + "browserName": "chrome" + }, + "globals_path": "nightwatch_globals.js" + } + } +} diff --git a/frontend/test/nightwatch_globals.js b/frontend/test/nightwatch_globals.js new file mode 100644 index 0000000..cf516b2 --- /dev/null +++ b/frontend/test/nightwatch_globals.js @@ -0,0 +1,37 @@ +var resolve = require('path').resolve +var Nuxt = require('nuxt').Nuxt +var Builder = require('nuxt').Builder + +const rootDir = resolve(__dirname, '..') +const port = 4000 +const host = "localhost" +const url = "http://"+host+":"+port.toString() +let config = {} +try { config = require(resolve(rootDir, 'nuxt.config.js')) } catch (e) {} +const nuxt = new Nuxt(config) +var nuxtIsBuild = false + +module.exports = { + 'default' : { + asyncHookTimeout: 20000, + url: url, + nuxt: nuxt, + serverHost: host, + serverPort: port, + }, + before : async function(cb){ + if (!nuxtIsBuild){ + console.log("Building nuxt components"); + await new Builder(nuxt).build(); + nuxtIsBuild = true + } + console.log("Starting nuxt server"); + nuxt.listen(port, host) + cb(); + }, + after : async function(cb){ + console.log("Shutting down nuxt"); + await nuxt.close() + cb(); + } +}; -- GitLab