prepare tests for ci

This commit is contained in:
Johannes Zellner 2024-10-08 15:34:33 +02:00
parent 43328753d8
commit be9cb6b0f6

View file

@ -4,6 +4,7 @@
/* global describe */ /* global describe */
/* global before */ /* global before */
/* global after */ /* global after */
/* global afterEach */
/* global it */ /* global it */
/* global xit */ /* global xit */
@ -13,6 +14,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'),
{ Builder, By, until } = require('selenium-webdriver'), { Builder, By, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome'); { Options } = require('selenium-webdriver/chrome');
@ -25,7 +27,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 = parseInt(process.env.TIMEOUT) || 10000; const TEST_TIMEOUT = parseInt(process.env.TIMEOUT) || 10000;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
@ -36,13 +38,27 @@ describe('Application life cycle test', function () {
let manifest = require('../CloudronManifest.json'); let manifest = require('../CloudronManifest.json');
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 sleep(millis) { function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis)); return new Promise(resolve => setTimeout(resolve, millis));
} }