#!/usr/bin/env node /* jslint node:true */ /* global it:false */ /* global xit:false */ /* global describe:false */ /* global before:false */ /* global after:false */ 'use strict'; require('chromedriver'); const execSync = require('child_process').execSync, expect = require('expect.js'), 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'); process.exit(1); } describe('Application life cycle test', function () { this.timeout(0); let browser, app; const LOCATION = 'test'; const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; before(function () { browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build(); }); after(function () { browser.quit(); }); 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); } 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', EXEC_ARGS); }); it('install app', function () { execSync('cloudron install --location ' + LOCATION, EXEC_ARGS); }); it('can get app information', getAppInfo); it('can search', search); it('backup app', function () { 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, 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 () { execSync('cloudron restart --app ' + app.id); }); it('can search', search); 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, EXEC_ARGS); }); // test update it('can install from appstore', function () { execSync(`cloudron install --appstore-id ${app.manifest.id} --location ${LOCATION}`, EXEC_ARGS); getAppInfo(); }); it('can update', function () { execSync('cloudron update --app ' + LOCATION, EXEC_ARGS); getAppInfo(); }); it('can search', search); it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); }); });