diff options
author | Johannes Zellner <johannes@cloudron.io> | 2020-01-05 17:53:16 +0100 |
---|---|---|
committer | Johannes Zellner <johannes@cloudron.io> | 2020-01-05 17:53:16 +0100 |
commit | 18b1ace178b9626b5dd411b5ee694669a87aef96 (patch) | |
tree | ca5af961ed952ce03a4b95a484740905be66d203 | |
parent | 6ce404d6ded9c09e33ff4a14c825c916a6e2d822 (diff) | |
download | Surfer-18b1ace178b9626b5dd411b5ee694669a87aef96.tar.gz Surfer-18b1ace178b9626b5dd411b5ee694669a87aef96.tar.zst Surfer-18b1ace178b9626b5dd411b5ee694669a87aef96.zip |
Bring tests up-to-date
-rw-r--r-- | test/test.js | 87 |
1 files changed, 34 insertions, 53 deletions
diff --git a/test/test.js b/test/test.js index 979ffde..dd2d06f 100644 --- a/test/test.js +++ b/test/test.js | |||
@@ -12,43 +12,34 @@ var execSync = require('child_process').execSync, | |||
12 | path = require('path'), | 12 | path = require('path'), |
13 | util = require('util'), | 13 | util = require('util'), |
14 | superagent = require('superagent'), | 14 | superagent = require('superagent'), |
15 | webdriver = require('selenium-webdriver'); | 15 | { Builder, By, until } = require('selenium-webdriver'), |
16 | 16 | { Options } = require('selenium-webdriver/chrome'); | |
17 | var by = webdriver.By, | ||
18 | until = webdriver.until; | ||
19 | 17 | ||
20 | if (!process.env.USERNAME || !process.env.PASSWORD) { | 18 | if (!process.env.USERNAME || !process.env.PASSWORD) { |
21 | console.log('USERNAME and PASSWORD env vars need to be set'); | 19 | console.log('USERNAME and PASSWORD env vars need to be set'); |
22 | process.exit(1); | 20 | process.exit(1); |
23 | } | 21 | } |
24 | 22 | ||
25 | const EXEC_OPTIONS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; | ||
26 | |||
27 | describe('Application life cycle test', function () { | 23 | describe('Application life cycle test', function () { |
28 | this.timeout(0); | 24 | this.timeout(0); |
29 | 25 | ||
30 | var browser; | 26 | const EXEC_OPTIONS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; |
27 | const LOCATION = 'test'; | ||
28 | const TEST_TIMEOUT = 10000; | ||
29 | const TEST_FILE_NAME_0 = 'index.html'; | ||
30 | const TEST_FILE_NAME_1 = 'test.txt'; | ||
31 | 31 | ||
32 | before(function (done) { | 32 | var app; |
33 | browser = new webdriver.Builder() | 33 | var browser; |
34 | .forBrowser('chrome') | ||
35 | // .setChromeOptions(new chrome.Options().addArguments(['no-sandbox', 'headless'])) | ||
36 | .build(); | ||
37 | 34 | ||
38 | done(); | 35 | before(function () { |
36 | browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build(); | ||
39 | }); | 37 | }); |
40 | 38 | ||
41 | after(function (done) { | 39 | after(function () { |
42 | browser.quit(); | 40 | browser.quit(); |
43 | done(); | ||
44 | }); | 41 | }); |
45 | 42 | ||
46 | var LOCATION = 'test'; | ||
47 | var TEST_TIMEOUT = 10000; | ||
48 | var TEST_FILE_NAME_0 = 'index.html'; | ||
49 | var TEST_FILE_NAME_1 = 'test.txt'; | ||
50 | var app; | ||
51 | |||
52 | function waitForElement(elem) { | 43 | function waitForElement(elem) { |
53 | return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () { | 44 | return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () { |
54 | return browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT); | 45 | return browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT); |
@@ -60,12 +51,12 @@ describe('Application life cycle test', function () { | |||
60 | browser.manage().deleteAllCookies(); | 51 | browser.manage().deleteAllCookies(); |
61 | browser.get('https://' + app.fqdn + '/_admin'); | 52 | browser.get('https://' + app.fqdn + '/_admin'); |
62 | 53 | ||
63 | waitForElement(by.id('loginUsernameInput')).then(function () { | 54 | waitForElement(By.id('loginUsernameInput')).then(function () { |
64 | browser.findElement(by.id('loginUsernameInput')).sendKeys(process.env.USERNAME); | 55 | browser.findElement(By.id('loginUsernameInput')).sendKeys(process.env.USERNAME); |
65 | browser.findElement(by.id('loginPasswordInput')).sendKeys(process.env.PASSWORD); | 56 | browser.findElement(By.id('loginPasswordInput')).sendKeys(process.env.PASSWORD); |
66 | browser.findElement(by.id('loginSubmitButton')).click(); | 57 | browser.findElement(By.id('loginSubmitButton')).click(); |
67 | 58 | ||
68 | waitForElement(by.id('burgerMenuButton')).then(function () { | 59 | waitForElement(By.id('burgerMenuButton')).then(function () { |
69 | done(); | 60 | done(); |
70 | }); | 61 | }); |
71 | }); | 62 | }); |
@@ -74,16 +65,16 @@ describe('Application life cycle test', function () { | |||
74 | function logout(done) { | 65 | function logout(done) { |
75 | browser.get('https://' + app.fqdn + '/_admin'); | 66 | browser.get('https://' + app.fqdn + '/_admin'); |
76 | 67 | ||
77 | waitForElement(by.id('burgerMenuButton')).then(function () { | 68 | waitForElement(By.id('burgerMenuButton')).then(function () { |
78 | browser.findElement(by.id('burgerMenuButton')).click(); | 69 | browser.findElement(By.id('burgerMenuButton')).click(); |
79 | 70 | ||
80 | // wait for open animation | 71 | // wait for open animation |
81 | browser.sleep(5000); | 72 | browser.sleep(5000); |
82 | 73 | ||
83 | waitForElement(by.id('logoutButton')).then(function () { | 74 | waitForElement(By.id('logoutButton')).then(function () { |
84 | browser.findElement(by.id('logoutButton')).click(); | 75 | browser.findElement(By.id('logoutButton')).click(); |
85 | 76 | ||
86 | waitForElement(by.id('loginUsernameInput')).then(function () { | 77 | waitForElement(By.id('loginUsernameInput')).then(function () { |
87 | done(); | 78 | done(); |
88 | }); | 79 | }); |
89 | }); | 80 | }); |
@@ -93,7 +84,7 @@ describe('Application life cycle test', function () { | |||
93 | function checkFileIsListed(name, done) { | 84 | function checkFileIsListed(name, done) { |
94 | browser.get('https://' + app.fqdn + '/_admin'); | 85 | browser.get('https://' + app.fqdn + '/_admin'); |
95 | 86 | ||
96 | waitForElement(by.xpath('//*[text()="' + name + '"]')).then(function () { | 87 | waitForElement(By.xpath('//*[text()="' + name + '"]')).then(function () { |
97 | done(); | 88 | done(); |
98 | }); | 89 | }); |
99 | } | 90 | } |
@@ -101,7 +92,7 @@ describe('Application life cycle test', function () { | |||
101 | function checkFileIsPresent(done) { | 92 | function checkFileIsPresent(done) { |
102 | browser.get('https://' + app.fqdn + '/' + TEST_FILE_NAME_0); | 93 | browser.get('https://' + app.fqdn + '/' + TEST_FILE_NAME_0); |
103 | 94 | ||
104 | waitForElement(by.xpath('//*[text()="test"]')).then(function () { | 95 | waitForElement(By.xpath('//*[text()="test"]')).then(function () { |
105 | done(); | 96 | done(); |
106 | }); | 97 | }); |
107 | } | 98 | } |
@@ -109,7 +100,7 @@ describe('Application life cycle test', function () { | |||
109 | function checkIndexFileIsServedUp(done) { | 100 | function checkIndexFileIsServedUp(done) { |
110 | browser.get('https://' + app.fqdn); | 101 | browser.get('https://' + app.fqdn); |
111 | 102 | ||
112 | waitForElement(by.xpath('//*[text()="test"]')).then(function () { | 103 | waitForElement(By.xpath('//*[text()="test"]')).then(function () { |
113 | done(); | 104 | done(); |
114 | }); | 105 | }); |
115 | } | 106 | } |
@@ -135,19 +126,13 @@ describe('Application life cycle test', function () { | |||
135 | done(); | 126 | done(); |
136 | } | 127 | } |
137 | 128 | ||
138 | xit('build app', function () { | 129 | xit('build app', function () { execSync('cloudron build', EXEC_OPTIONS); }); |
139 | execSync('cloudron build', EXEC_OPTIONS); | ||
140 | }); | ||
141 | 130 | ||
142 | it('install app', function () { | 131 | it('install app', function () { execSync(`cloudron install --location ${LOCATION}`, EXEC_OPTIONS); }); |
143 | execSync('cloudron install --new --wait --location ' + LOCATION, EXEC_OPTIONS); | ||
144 | }); | ||
145 | 132 | ||
146 | it('can get app information', function () { | 133 | it('can get app information', function () { |
147 | var inspect = JSON.parse(execSync('cloudron inspect')); | 134 | var inspect = JSON.parse(execSync('cloudron inspect')); |
148 | |||
149 | app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0]; | 135 | app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0]; |
150 | |||
151 | expect(app).to.be.an('object'); | 136 | expect(app).to.be.an('object'); |
152 | }); | 137 | }); |
153 | 138 | ||
@@ -159,20 +144,14 @@ describe('Application life cycle test', function () { | |||
159 | it('file is served up', checkIndexFileIsServedUp); | 144 | it('file is served up', checkIndexFileIsServedUp); |
160 | it('can upload second file', uploadFile.bind(null, TEST_FILE_NAME_1)); | 145 | it('can upload second file', uploadFile.bind(null, TEST_FILE_NAME_1)); |
161 | it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_1)); | 146 | it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_1)); |
162 | it('can delete second file with cli', function (done) { | 147 | it('can delete second file with cli', function () { |
163 | execSync(path.join(__dirname, '/../cli/surfer.js') + ' del ' + TEST_FILE_NAME_1, { stdio: 'inherit' } ); | 148 | execSync(path.join(__dirname, '/../cli/surfer.js') + ' del ' + TEST_FILE_NAME_1, { stdio: 'inherit' } ); |
164 | done(); | ||
165 | }); | 149 | }); |
166 | it('second file is gone', checkFileIsGone.bind(null, TEST_FILE_NAME_1)); | 150 | it('second file is gone', checkFileIsGone.bind(null, TEST_FILE_NAME_1)); |
167 | it('can logout', logout); | 151 | it('can logout', logout); |
168 | 152 | ||
169 | it('backup app', function () { | 153 | it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_OPTIONS); }); |
170 | execSync('cloudron backup create --app ' + app.id, EXEC_OPTIONS); | 154 | it('restore app', function () { execSync(`cloudron restore --app ${app.id}`, EXEC_OPTIONS); }); |
171 | }); | ||
172 | |||
173 | it('restore app', function () { | ||
174 | execSync('cloudron restore --app ' + app.id, EXEC_OPTIONS); | ||
175 | }); | ||
176 | 155 | ||
177 | it('can login', login); | 156 | it('can login', login); |
178 | it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_0)); | 157 | it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_0)); |
@@ -186,10 +165,12 @@ describe('Application life cycle test', function () { | |||
186 | 165 | ||
187 | // ensure we don't hit NXDOMAIN in the mean time | 166 | // ensure we don't hit NXDOMAIN in the mean time |
188 | browser.get('about:blank').then(function () { | 167 | browser.get('about:blank').then(function () { |
189 | execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_OPTIONS); | 168 | execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_OPTIONS); |
169 | |||
190 | var inspect = JSON.parse(execSync('cloudron inspect')); | 170 | var inspect = JSON.parse(execSync('cloudron inspect')); |
191 | app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0]; | 171 | app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0]; |
192 | expect(app).to.be.an('object'); | 172 | expect(app).to.be.an('object'); |
173 | |||
193 | done(); | 174 | done(); |
194 | }); | 175 | }); |
195 | }); | 176 | }); |
@@ -203,7 +184,7 @@ describe('Application life cycle test', function () { | |||
203 | it('uninstall app', function (done) { | 184 | it('uninstall app', function (done) { |
204 | // ensure we don't hit NXDOMAIN in the mean time | 185 | // ensure we don't hit NXDOMAIN in the mean time |
205 | browser.get('about:blank').then(function () { | 186 | browser.get('about:blank').then(function () { |
206 | execSync('cloudron uninstall --app ' + app.id, EXEC_OPTIONS); | 187 | execSync(`cloudron uninstall --app ${app.id}`, EXEC_OPTIONS); |
207 | done(); | 188 | done(); |
208 | }); | 189 | }); |
209 | }); | 190 | }); |