searxng-app/test/test.js

114 lines
3.3 KiB
JavaScript
Raw Permalink Normal View History

2020-03-04 20:15:23 +00:00
#!/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');
2022-01-23 18:50:53 +00:00
const execSync = require('child_process').execSync,
2020-03-04 20:15:23 +00:00
expect = require('expect.js'),
2022-01-23 18:50:53 +00:00
path = require('path'),
{ Builder, By, Key, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
2020-03-04 20:15:23 +00:00
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);
2022-01-23 18:50:53 +00:00
let browser, app;
const LOCATION = 'test';
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
2020-03-04 20:15:23 +00:00
2022-01-23 18:50:53 +00:00
before(function () {
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
2020-03-04 20:15:23 +00:00
});
2022-01-23 18:50:53 +00:00
after(function () {
2020-03-04 20:15:23 +00:00
browser.quit();
});
2022-01-23 18:50:53 +00:00
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);
2020-03-04 20:40:48 +00:00
}
2022-01-23 18:50:53 +00:00
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');
}
2020-03-04 20:15:23 +00:00
xit('build app', function () {
2022-01-23 18:50:53 +00:00
execSync('cloudron build', EXEC_ARGS);
2020-03-04 20:15:23 +00:00
});
it('install app', function () {
2022-01-23 18:50:53 +00:00
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
2020-03-04 20:15:23 +00:00
});
2022-01-23 18:50:53 +00:00
it('can get app information', getAppInfo);
2020-03-04 20:15:23 +00:00
2020-03-04 20:40:48 +00:00
it('can search', search);
2020-03-04 20:15:23 +00:00
it('backup app', function () {
2022-01-23 18:50:53 +00:00
execSync('cloudron backup create --app ' + app.id, EXEC_ARGS);
2020-03-04 20:15:23 +00:00
});
it('restore app', function () {
2021-02-23 02:37:56 +00:00
const backups = JSON.parse(execSync('cloudron backup list --raw'));
2022-01-23 18:50:53 +00:00
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);
2020-03-04 20:15:23 +00:00
});
2020-03-04 20:40:48 +00:00
it('can search', search);
2022-01-23 18:50:53 +00:00
it('can restart app', function () {
2020-03-04 20:15:23 +00:00
execSync('cloudron restart --app ' + app.id);
});
2020-03-04 20:40:48 +00:00
it('can search', search);
2022-01-23 18:50:53 +00:00
it('move to different location', function () {
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS);
getAppInfo();
2020-03-04 20:15:23 +00:00
});
2020-03-04 20:40:48 +00:00
it('can search', search);
2020-03-04 20:15:23 +00:00
it('uninstall app', function () {
2022-01-23 18:50:53 +00:00
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
2020-03-04 20:15:23 +00:00
});
// test update
it('can install from appstore', function () {
2022-01-23 18:50:53 +00:00
execSync(`cloudron install --appstore-id ${app.manifest.id} --location ${LOCATION}`, EXEC_ARGS);
getAppInfo();
2020-03-04 20:15:23 +00:00
});
it('can update', function () {
2022-01-23 18:50:53 +00:00
execSync('cloudron update --app ' + LOCATION, EXEC_ARGS);
getAppInfo();
2020-03-04 20:15:23 +00:00
});
2020-03-04 20:40:48 +00:00
it('can search', search);
2020-03-04 20:15:23 +00:00
it('uninstall app', function () {
2022-01-23 18:50:53 +00:00
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
2020-03-04 20:15:23 +00:00
});
});