Update tests for CI
This commit is contained in:
parent
7bab576c1b
commit
f3abbdd291
29
test/test.js
29
test/test.js
|
@ -1,11 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/* jshint esversion: 8 */
|
/* jshint esversion: 8 */
|
||||||
/* global describe */
|
/* global it, xit, describe, before, after, afterEach */
|
||||||
/* global before */
|
|
||||||
/* global after */
|
|
||||||
/* global it */
|
|
||||||
/* global xit */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -13,6 +9,7 @@ require('chromedriver');
|
||||||
|
|
||||||
const execSync = require('child_process').execSync,
|
const execSync = require('child_process').execSync,
|
||||||
expect = require('expect.js'),
|
expect = require('expect.js'),
|
||||||
|
fs = require('fs'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
timers = require('timers/promises'),
|
timers = require('timers/promises'),
|
||||||
{ Builder, By, until } = require('selenium-webdriver'),
|
{ Builder, By, until } = require('selenium-webdriver'),
|
||||||
|
@ -26,7 +23,7 @@ if (!process.env.USERNAME || !process.env.PASSWORD) {
|
||||||
describe('Application life cycle test', function () {
|
describe('Application life cycle test', function () {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|
||||||
const LOCATION = 'test';
|
const LOCATION = process.env.LOCATION || 'test';
|
||||||
const TEST_TIMEOUT = 30000;
|
const TEST_TIMEOUT = 30000;
|
||||||
const FOLDER = 'xmf'; // keep this small. long folder names fail in automation, not sure why
|
const FOLDER = 'xmf'; // keep this small. long folder names fail in automation, not sure why
|
||||||
const SYNC_PORT = 22001;
|
const SYNC_PORT = 22001;
|
||||||
|
@ -34,17 +31,31 @@ describe('Application life cycle test', function () {
|
||||||
|
|
||||||
let browser, app;
|
let browser, app;
|
||||||
const adminUsername = 'admin', adminPassword = 'changeme';
|
const adminUsername = 'admin', adminPassword = 'changeme';
|
||||||
let username = process.env.USERNAME;
|
const username = process.env.USERNAME;
|
||||||
let password = process.env.PASSWORD;
|
const password = process.env.PASSWORD;
|
||||||
|
|
||||||
before(function () {
|
before(function () {
|
||||||
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
|
const chromeOptions = new Options().windowSize({ width: 1280, height: 1024 });
|
||||||
|
if (process.env.CI) chromeOptions.addArguments('no-sandbox', 'disable-dev-shm-usage', 'headless');
|
||||||
|
browser = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
|
||||||
|
if (!fs.existsSync('./screenshots')) fs.mkdirSync('./screenshots');
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
browser.quit();
|
browser.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(async function () {
|
||||||
|
if (!process.env.CI || !app) return;
|
||||||
|
|
||||||
|
const currentUrl = await browser.getCurrentUrl();
|
||||||
|
if (!currentUrl.includes(app.domain)) return;
|
||||||
|
expect(this.currentTest.title).to.be.a('string');
|
||||||
|
|
||||||
|
const screenshotData = await browser.takeScreenshot();
|
||||||
|
fs.writeFileSync(`./screenshots/${new Date().getTime()}-${this.currentTest.title.replaceAll(' ', '_')}.png`, screenshotData, 'base64');
|
||||||
|
});
|
||||||
|
|
||||||
function getAppInfo() {
|
function getAppInfo() {
|
||||||
const inspect = JSON.parse(execSync('cloudron inspect'));
|
const inspect = JSON.parse(execSync('cloudron inspect'));
|
||||||
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
|
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
|
||||||
|
|
Loading…
Reference in New Issue