From be9cb6b0f60a3aef91512d08bb51fa4be3cbcbfa Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Tue, 8 Oct 2024 15:34:33 +0200 Subject: [PATCH] prepare tests for ci --- test/test.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/test.js b/test/test.js index 2e92d02..45b7f49 100755 --- a/test/test.js +++ b/test/test.js @@ -4,6 +4,7 @@ /* global describe */ /* global before */ /* global after */ +/* global afterEach */ /* global it */ /* global xit */ @@ -13,6 +14,7 @@ require('chromedriver'); const execSync = require('child_process').execSync, expect = require('expect.js'), + fs = require('fs'), path = require('path'), { Builder, By, until } = require('selenium-webdriver'), { Options } = require('selenium-webdriver/chrome'); @@ -25,7 +27,7 @@ if (!process.env.USERNAME || !process.env.PASSWORD) { describe('Application life cycle test', function () { this.timeout(0); - const LOCATION = 'test'; + const LOCATION = process.env.LOCATION || 'test'; const TEST_TIMEOUT = parseInt(process.env.TIMEOUT) || 10000; const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; @@ -36,13 +38,27 @@ describe('Application life cycle test', function () { let manifest = require('../CloudronManifest.json'); 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 () { 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) { return new Promise(resolve => setTimeout(resolve, millis)); }