aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorJohannes Zellner <johannes@cloudron.io>2018-10-15 17:38:10 +0200
committerJohannes Zellner <johannes@cloudron.io>2018-10-15 17:38:10 +0200
commita7317b4ba7e4f37ab1e562669c03e4867c070d39 (patch)
tree9920a2dcc66d30a3b03fa5a6a7699f3ca9a6b421 /test
parent4d8f08f9c825c35ed3e05ce92457c2fc2e2194c6 (diff)
downloadSurfer-a7317b4ba7e4f37ab1e562669c03e4867c070d39.tar.gz
Surfer-a7317b4ba7e4f37ab1e562669c03e4867c070d39.tar.zst
Surfer-a7317b4ba7e4f37ab1e562669c03e4867c070d39.zip
Fixup tests
Diffstat (limited to 'test')
-rw-r--r--test/test.js94
1 files changed, 57 insertions, 37 deletions
diff --git a/test/test.js b/test/test.js
index 3386596..dace05d 100644
--- a/test/test.js
+++ b/test/test.js
@@ -2,43 +2,44 @@
2 2
3'use strict'; 3'use strict';
4 4
5/* global describe */
6/* global before */
7/* global after */
8/* global it */
9
5var execSync = require('child_process').execSync, 10var execSync = require('child_process').execSync,
6 expect = require('expect.js'), 11 expect = require('expect.js'),
7 path = require('path'), 12 path = require('path'),
8 util = require('util'), 13 util = require('util'),
9 fs = require('fs'),
10 superagent = require('superagent'), 14 superagent = require('superagent'),
11 webdriver = require('selenium-webdriver'); 15 webdriver = require('selenium-webdriver');
12 16
13var by = webdriver.By, 17var by = webdriver.By,
14 Keys = webdriver.Key,
15 until = webdriver.until; 18 until = webdriver.until;
16 19
17process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
18
19if (!process.env.USERNAME || !process.env.PASSWORD) { 20if (!process.env.USERNAME || !process.env.PASSWORD) {
20 console.log('USERNAME and PASSWORD env vars need to be set'); 21 console.log('USERNAME and PASSWORD env vars need to be set');
21 process.exit(1); 22 process.exit(1);
22} 23}
23 24
25const EXEC_OPTIONS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
26
24describe('Application life cycle test', function () { 27describe('Application life cycle test', function () {
25 this.timeout(0); 28 this.timeout(0);
26 29
27 var chrome = require('selenium-webdriver/chrome'); 30 var browser;
28 var server, browser = new chrome.Driver();
29 31
30 before(function (done) { 32 before(function (done) {
31 var seleniumJar= require('selenium-server-standalone-jar'); 33 browser = new webdriver.Builder()
32 var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer; 34 .forBrowser('chrome')
33 server = new SeleniumServer(seleniumJar.path, { port: 4444 }); 35 // .setChromeOptions(new chrome.Options().addArguments(['no-sandbox', 'headless']))
34 server.start(); 36 .build();
35 37
36 done(); 38 done();
37 }); 39 });
38 40
39 after(function (done) { 41 after(function (done) {
40 browser.quit(); 42 browser.quit();
41 server.stop();
42 done(); 43 done();
43 }); 44 });
44 45
@@ -48,20 +49,24 @@ describe('Application life cycle test', function () {
48 var TEST_FILE_NAME_1 = 'test.txt'; 49 var TEST_FILE_NAME_1 = 'test.txt';
49 var app; 50 var app;
50 51
52 function waitForElement(elem) {
53 return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
54 return browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
55 });
56 }
57
51 // tests which are used more than once 58 // tests which are used more than once
52 function login(done) { 59 function login(done) {
53 browser.manage().deleteAllCookies(); 60 browser.manage().deleteAllCookies();
54 browser.get('https://' + app.fqdn + '/_admin'); 61 browser.get('https://' + app.fqdn + '/_admin');
55 62
56 browser.wait(until.elementLocated(by.id('inputUsername')), TEST_TIMEOUT).then(function () { 63 waitForElement(by.id('loginUsernameInput')).then(function () {
57 browser.wait(until.elementIsVisible(browser.findElement(by.id('inputUsername'))), TEST_TIMEOUT).then(function () { 64 browser.findElement(by.id('loginUsernameInput')).sendKeys(process.env.USERNAME);
58 browser.findElement(by.id('inputUsername')).sendKeys(process.env.USERNAME); 65 browser.findElement(by.id('loginPasswordInput')).sendKeys(process.env.PASSWORD);
59 browser.findElement(by.id('inputPassword')).sendKeys(process.env.PASSWORD); 66 browser.findElement(by.id('loginSubmitButton')).click();
60 browser.findElement(by.id('loginForm')).submit();
61 67
62 browser.wait(until.elementIsVisible(browser.findElement(by.id('logoutButton'))), TEST_TIMEOUT).then(function () { 68 waitForElement(by.id('burgerMenuButton')).then(function () {
63 done(); 69 done();
64 });
65 }); 70 });
66 }); 71 });
67 } 72 }
@@ -69,11 +74,16 @@ describe('Application life cycle test', function () {
69 function logout(done) { 74 function logout(done) {
70 browser.get('https://' + app.fqdn + '/_admin'); 75 browser.get('https://' + app.fqdn + '/_admin');
71 76
72 browser.wait(until.elementLocated(by.id('logoutButton')), TEST_TIMEOUT).then(function () { 77 waitForElement(by.id('burgerMenuButton')).then(function () {
73 browser.wait(until.elementIsVisible(browser.findElement(by.id('logoutButton'))), TEST_TIMEOUT).then(function () { 78 browser.findElement(by.id('burgerMenuButton')).click();
79
80 // wait for open animation
81 browser.sleep(5000);
82
83 waitForElement(by.id('logoutButton')).then(function () {
74 browser.findElement(by.id('logoutButton')).click(); 84 browser.findElement(by.id('logoutButton')).click();
75 85
76 browser.wait(until.elementIsVisible(browser.findElement(by.id('inputPassword'))), TEST_TIMEOUT).then(function () { 86 waitForElement(by.id('loginUsernameInput')).then(function () {
77 done(); 87 done();
78 }); 88 });
79 }); 89 });
@@ -83,7 +93,7 @@ describe('Application life cycle test', function () {
83 function checkFileIsListed(name, done) { 93 function checkFileIsListed(name, done) {
84 browser.get('https://' + app.fqdn + '/_admin'); 94 browser.get('https://' + app.fqdn + '/_admin');
85 95
86 browser.wait(until.elementLocated(by.xpath('//*[text()="' + name + '"]')), TEST_TIMEOUT).then(function () { 96 waitForElement(by.xpath('//*[text()="' + name + '"]')).then(function () {
87 done(); 97 done();
88 }); 98 });
89 } 99 }
@@ -91,7 +101,7 @@ describe('Application life cycle test', function () {
91 function checkFileIsPresent(done) { 101 function checkFileIsPresent(done) {
92 browser.get('https://' + app.fqdn + '/' + TEST_FILE_NAME_0); 102 browser.get('https://' + app.fqdn + '/' + TEST_FILE_NAME_0);
93 103
94 browser.wait(until.elementLocated(by.xpath('//*[text()="test"]')), TEST_TIMEOUT).then(function () { 104 waitForElement(by.xpath('//*[text()="test"]')).then(function () {
95 done(); 105 done();
96 }); 106 });
97 } 107 }
@@ -99,7 +109,7 @@ describe('Application life cycle test', function () {
99 function checkIndexFileIsServedUp(done) { 109 function checkIndexFileIsServedUp(done) {
100 browser.get('https://' + app.fqdn); 110 browser.get('https://' + app.fqdn);
101 111
102 browser.wait(until.elementLocated(by.xpath('//*[text()="test"]')), TEST_TIMEOUT).then(function () { 112 waitForElement(by.xpath('//*[text()="test"]')).then(function () {
103 done(); 113 done();
104 }); 114 });
105 } 115 }
@@ -107,7 +117,8 @@ describe('Application life cycle test', function () {
107 function checkFileIsGone(name, done) { 117 function checkFileIsGone(name, done) {
108 superagent.get('https://' + app.fqdn + '/' + name).end(function (error, result) { 118 superagent.get('https://' + app.fqdn + '/' + name).end(function (error, result) {
109 expect(error).to.be.an('object'); 119 expect(error).to.be.an('object');
110 expect(result.statusCode).to.equal(404); 120 expect(error.response.status).to.equal(404);
121 expect(result).to.be.an('object');
111 done(); 122 done();
112 }); 123 });
113 } 124 }
@@ -125,11 +136,11 @@ describe('Application life cycle test', function () {
125 } 136 }
126 137
127 xit('build app', function () { 138 xit('build app', function () {
128 execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 139 execSync('cloudron build', EXEC_OPTIONS);
129 }); 140 });
130 141
131 it('install app', function () { 142 it('install app', function () {
132 execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 143 execSync('cloudron install --new --wait --location ' + LOCATION, EXEC_OPTIONS);
133 }); 144 });
134 145
135 it('can get app information', function () { 146 it('can get app information', function () {
@@ -156,11 +167,11 @@ describe('Application life cycle test', function () {
156 it('can logout', logout); 167 it('can logout', logout);
157 168
158 it('backup app', function () { 169 it('backup app', function () {
159 execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 170 execSync('cloudron backup create --app ' + app.id, EXEC_OPTIONS);
160 }); 171 });
161 172
162 it('restore app', function () { 173 it('restore app', function () {
163 execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 174 execSync('cloudron restore --app ' + app.id, EXEC_OPTIONS);
164 }); 175 });
165 176
166 it('can login', login); 177 it('can login', login);
@@ -170,12 +181,17 @@ describe('Application life cycle test', function () {
170 it('second file is still gone', checkFileIsGone.bind(null, TEST_FILE_NAME_1)); 181 it('second file is still gone', checkFileIsGone.bind(null, TEST_FILE_NAME_1));
171 it('can logout', logout); 182 it('can logout', logout);
172 183
173 it('move to different location', function () { 184 it('move to different location', function (done) {
174 browser.manage().deleteAllCookies(); 185 browser.manage().deleteAllCookies();
175 execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 186
176 var inspect = JSON.parse(execSync('cloudron inspect')); 187 // ensure we don't hit NXDOMAIN in the mean time
177 app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0]; 188 browser.get('about:blank').then(function () {
178 expect(app).to.be.an('object'); 189 execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_OPTIONS);
190 var inspect = JSON.parse(execSync('cloudron inspect'));
191 app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
192 expect(app).to.be.an('object');
193 done();
194 });
179 }); 195 });
180 196
181 it('can login', login); 197 it('can login', login);
@@ -184,7 +200,11 @@ describe('Application life cycle test', function () {
184 it('file is served up', checkIndexFileIsServedUp); 200 it('file is served up', checkIndexFileIsServedUp);
185 it('can logout', logout); 201 it('can logout', logout);
186 202
187 it('uninstall app', function () { 203 it('uninstall app', function (done) {
188 execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 204 // ensure we don't hit NXDOMAIN in the mean time
205 browser.get('about:blank').then(function () {
206 execSync('cloudron uninstall --app ' + app.id, EXEC_OPTIONS);
207 done();
208 });
189 }); 209 });
190}); 210});