From affa9850a38279256da10227e537e0184fdeebda Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Tue, 29 Jun 2021 14:56:14 +0200 Subject: [PATCH] Rework test to follow new patterns --- test/test.js | 146 ++++++++++++++++++--------------------------------- 1 file changed, 52 insertions(+), 94 deletions(-) diff --git a/test/test.js b/test/test.js index e37d940..f728659 100644 --- a/test/test.js +++ b/test/test.js @@ -1,11 +1,11 @@ #!/usr/bin/env node -/* jslint node:true */ -/* global it:false */ -/* global xit:false */ -/* global describe:false */ -/* global before:false */ -/* global after:false */ +/* jshint esversion: 8 */ +/* global describe */ +/* global before */ +/* global after */ +/* global it */ +/* global xit */ 'use strict'; @@ -15,47 +15,42 @@ var execSync = require('child_process').execSync, expect = require('expect.js'), path = require('path'), superagent = require('superagent'), - webdriver = require('selenium-webdriver'); - -var by = require('selenium-webdriver').By, - until = require('selenium-webdriver').until, - Key = require('selenium-webdriver').Key; + { Builder, By, Key, until } = require('selenium-webdriver'), + { Options } = require('selenium-webdriver/chrome'); describe('Application life cycle test', function () { this.timeout(0); - var server, browser = new webdriver.Builder().forBrowser('chrome').build(); - var LOCATION = 'test'; - var app; - var username = process.env.USERNAME; - var password = process.env.PASSWORD; - var TIMEOUT = process.env.TIMEOUT | 30000; + const LOCATION = 'test'; + const TEST_TIMEOUT = 10000; + const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; + + const username = process.env.USERNAME; + const password = process.env.PASSWORD; + + var app, browser; var token, roomId; - before(function (done) { - if (!process.env.USERNAME) return done(new Error('USERNAME env var not set')); - if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set')); + before(function () { + if (!process.env.USERNAME) throw new Error('USERNAME env var not set'); + if (!process.env.PASSWORD) throw new Error('PASSWORD env var not set'); - var seleniumJar= require('selenium-server-standalone-jar'); - var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer; - server = new SeleniumServer(seleniumJar.path, { port: 4444 }); - server.start(); - - done(); + browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build(); }); - after(function (done) { + after(function () { browser.quit(); - server.stop(); - done(); }); - function checkLandingPage(done) { - browser.get('https://' + app.fqdn).then(function () { - return browser.wait(until.elementLocated(by.xpath('//h1[contains(text(),"Synapse is running")]')), TIMEOUT); - }).then(function () { - done(); - }); + function getAppInfo() { + var inspect = JSON.parse(execSync('cloudron inspect')); + app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0]; + expect(app).to.be.an('object'); + } + + async function checkLandingPage() { + await browser.get(`https://${app.fqdn}`); + await browser.wait(until.elementLocated(By.xpath('//h1[contains(text(),"Synapse is running")]')), TEST_TIMEOUT); } // https://matrix.org/docs/spec/client_server/latest#user-interactive-api-in-the-rest-api @@ -82,7 +77,7 @@ describe('Application life cycle test', function () { if (error) return done(error); if (result.statusCode !== 200) return done(new Error('Login failed with status ' + result.statusCode)); - console.log('registered user with id', result.user_id); + console.log('registered user with id', result.body.user_id); done(); }); @@ -141,22 +136,12 @@ describe('Application life cycle test', function () { }); } - xit('build app', function () { - execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - }); + xit('build app', function () { execSync('cloudron build', EXEC_ARGS); }); // No SSO - it('install app (no sso)', function () { - execSync('cloudron install --no-sso --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - }); + it('install app (no sso)', function () { execSync('cloudron install --no-sso --location ' + LOCATION, EXEC_ARGS); }); - it('can get app information', function () { - var inspect = JSON.parse(execSync('cloudron inspect')); - - app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0]; - - expect(app).to.be.an('object'); - }); + it('can get app information', getAppInfo); it('check landing page', checkLandingPage); it('can register new user', registerUser); @@ -165,22 +150,12 @@ describe('Application life cycle test', function () { it('create room', createRoom); it('check room', checkRoom); - it('uninstall app', function () { - execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - }); + it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); }); // SSO - it('install app', function () { - execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - }); + it('install app', function () { execSync('cloudron install --location ' + LOCATION, EXEC_ARGS); }); - it('can get app information', function () { - var inspect = JSON.parse(execSync('cloudron inspect')); - - app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0]; - - expect(app).to.be.an('object'); - }); + it('can get app information', getAppInfo); it('check landing page', checkLandingPage); it('can login', checkLogin); @@ -188,28 +163,22 @@ describe('Application life cycle test', function () { it('create room', createRoom); it('check room', checkRoom); - it('can restart app', function (done) { - execSync('cloudron restart'); - done(); - }); + it('can restart app', function () { execSync('cloudron restart'); }); it('check landing page', checkLandingPage); it('check room', checkRoom); - it('backup app', function () { - execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - }); + it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); }); it('check landing page', checkLandingPage); it('check room', checkRoom); it('restore app', function () { const backups = JSON.parse(execSync('cloudron backup list --raw')); - execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - var inspect = JSON.parse(execSync('cloudron inspect')); - app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0]; - execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); + execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); + execSync('cloudron install --location ' + LOCATION, EXEC_ARGS); + getAppInfo(); + execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS); }); it('check landing page', checkLandingPage); @@ -217,40 +186,29 @@ describe('Application life cycle test', function () { it('move to different location', function () { browser.manage().deleteAllCookies(); - execSync('cloudron configure --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - var inspect = JSON.parse(execSync('cloudron inspect')); - app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0]; - expect(app).to.be.an('object'); + execSync('cloudron configure --location ' + LOCATION + '2', EXEC_ARGS); + getAppInfo(); }); it('check landing page', checkLandingPage); it('check room', checkRoom); - it('uninstall app', function () { - execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - }); + it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); }); // test update - it('can install app', function () { - execSync('cloudron install --appstore-id org.matrix.synapse --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - var inspect = JSON.parse(execSync('cloudron inspect')); - app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0]; - expect(app).to.be.an('object'); - }); + it('can install app', function () { execSync('cloudron install --appstore-id org.matrix.synapse --location ' + LOCATION, EXEC_ARGS); }); + + it('can get app information', getAppInfo); it('check landing page', checkLandingPage); it('can login', checkLogin); it('create room', createRoom); it('check room', checkRoom); - it('can update', function () { - execSync('cloudron update --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - }); + it('can update', function () { execSync('cloudron update --app ' + LOCATION, EXEC_ARGS); }); it('check landing page', checkLandingPage); it('check room', checkRoom); - it('uninstall app', function () { - execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); - }); -}); + it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); }); +});