Make tests async

This commit is contained in:
Girish Ramakrishnan 2022-01-23 10:50:53 -08:00
parent be87dfccc4
commit 73e3ad3341
3 changed files with 1710 additions and 218 deletions

1818
test/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -10,9 +10,9 @@
"license": "ISC",
"dependencies": {
"expect.js": "^0.3.1",
"mocha": "^8.3.2",
"mocha": "^9.1.4",
"selenium-server-standalone-jar": "^3.141.59",
"selenium-webdriver": "^3.6.0",
"chromedriver": "^89.0.0"
"selenium-webdriver": "^4.1.1",
"chromedriver": "^97.0.0"
}
}

View file

@ -11,14 +11,11 @@
require('chromedriver');
var execSync = require('child_process').execSync,
const execSync = require('child_process').execSync,
expect = require('expect.js'),
path = require('path');
var by = require('selenium-webdriver').By,
until = require('selenium-webdriver').until,
Key = require('selenium-webdriver').Key,
Builder = require('selenium-webdriver').Builder;
path = require('path'),
{ Builder, By, Key, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
if (!process.env.USERNAME || !process.env.PASSWORD || !process.env.EMAIL) {
console.log('USERNAME, PASSWORD and EMAIL env vars need to be set');
@ -28,112 +25,89 @@ if (!process.env.USERNAME || !process.env.PASSWORD || !process.env.EMAIL) {
describe('Application life cycle test', function () {
this.timeout(0);
var server, browser = new Builder().forBrowser('chrome').build();
let browser, app;
const LOCATION = 'test';
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
before(function (done) {
var seleniumJar= require('selenium-server-standalone-jar');
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
server = new SeleniumServer(seleniumJar.path, { port: 4444 });
server.start();
done();
before(function () {
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 search(done) {
browser.get(`https://${app.fqdn}`).then(function () {
return browser.wait(until.elementLocated(by.id('q')), 5000);
}).then(function () {
return browser.findElement(by.id('q')).sendKeys('cloudron');
}).then(function () {
return browser.findElement(by.id('q')).sendKeys(Key.RETURN);
}).then(function () {
return browser.wait(until.elementLocated(by.xpath('//span[text()="Cloudron"]')), 5000);
}).then(function () {
return done();
});
async function search() {
await browser.get(`https://${app.fqdn}`);
await browser.wait(until.elementLocated(By.id('q')), 5000);
await browser.findElement(By.id('q')).sendKeys('cloudron');
await browser.findElement(By.id('q')).sendKeys(Key.RETURN);
await browser.wait(until.elementLocated(By.xpath('//span[text()="Cloudron"]')), 5000);
}
var LOCATION = 'test';
var app;
function getAppInfo() {
const inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location.startsWith(LOCATION); })[0];
expect(app).to.be.an('object');
}
xit('build app', function () {
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
execSync('cloudron build', EXEC_ARGS);
});
it('install app', function () {
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
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('can search', search);
it('backup app', function () {
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
execSync('cloudron backup create --app ' + app.id, EXEC_ARGS);
});
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('can search', search);
it('can restart app', function (done) {
it('can restart app', function () {
execSync('cloudron restart --app ' + app.id);
done();
});
it('can search', search);
it('move to different location', function (done) {
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, { 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');
done();
it('move to different location', function () {
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS);
getAppInfo();
});
it('can search', search);
it('uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
});
// test update
it('can install from appstore', function () {
execSync(`cloudron install --appstore-id ${app.manifest.id} --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');
execSync(`cloudron install --appstore-id ${app.manifest.id} --location ${LOCATION}`, EXEC_ARGS);
getAppInfo();
});
it('can update', function () {
execSync('cloudron update --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
let inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
execSync('cloudron update --app ' + LOCATION, EXEC_ARGS);
getAppInfo();
});
it('can search', search);
it('uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
});
});