From 9b773524ce15e4aaf9f1cb3ba66ee37e7a142e8d Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Wed, 9 Oct 2024 09:08:28 +0200 Subject: [PATCH] add ci files --- .gitlab-ci.yml | 5 +++++ test/test.js | 47 +++++++++++++++++++---------------------------- 2 files changed, 24 insertions(+), 28 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..dbcfb21 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,5 @@ +include: + - project: devops/pipeline-components + ref: main + file: cloudron-app.gitlab-ci.yml + diff --git a/test/test.js b/test/test.js index eeebb01..f57896b 100755 --- a/test/test.js +++ b/test/test.js @@ -1,11 +1,7 @@ #!/usr/bin/env node /* jshint esversion: 8 */ -/* global it:false */ -/* global xit:false */ -/* global describe:false */ -/* global before:false */ -/* global after:false */ +/* global it, xit, describe, before, after, afterEach */ 'use strict'; @@ -29,21 +25,23 @@ describe('Application life cycle test', function () { const TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 5000; const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; - const LOCATION = 'test'; + const LOCATION = process.env.LOCATION || 'test'; const SSH_PORT = 29420; let app, browser; - var athenticated_by_oidc = false; + let athenticated_by_oidc = false; const repodir = '/tmp/testrepo'; const reponame = 'testrepo'; const username = process.env.USERNAME; const password = process.env.PASSWORD; - const email = process.env.EMAIL; 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 () { @@ -51,8 +49,19 @@ describe('Application life cycle test', function () { fs.rmSync(repodir, { recursive: true, force: true }); }); + 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() { - var 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]; expect(app).to.be.an('object'); } @@ -147,25 +156,7 @@ describe('Application life cycle test', function () { await browser.wait(until.elementLocated(By.xpath('//p[contains(text(), "has been added.")]')), TIMEOUT); } - async function addPublicKeyOld() { - var publicKey = fs.readFileSync(__dirname + '/id_ed25519.pub', 'utf8'); - - await browser.get('https://' + app.fqdn + '/user/settings/keys'); - - await browser.wait(until.elementLocated(By.id('add-ssh-button')), TIMEOUT); - await browser.findElement(By.id('add-ssh-button')).click(); - await browser.findElement(By.id('ssh-key-title')).sendKeys('testkey'); - await browser.findElement(By.id('ssh-key-content')).sendKeys(publicKey.trim()); // #3480 - var button = browser.findElement(By.xpath('//button[contains(text(), "Add Key")]')); - await browser.executeScript('arguments[0].scrollIntoView(false)', button); - await browser.findElement(By.xpath('//button[contains(text(), "Add Key") and contains(@class, "green")]')).click(); - - await browser.wait(until.elementLocated(By.xpath('//p[contains(text(), "has been added.")]')), TIMEOUT); - } - async function createRepo() { - var getRepoPage = await browser.get('https://' + app.fqdn + '/repo/create'); - await browser.findElement(By.id('repo_name')).sendKeys(reponame); var button = browser.findElement(By.xpath('//button[contains(text(), "Create Repository")]')); await browser.executeScript('arguments[0].scrollIntoView(true)', button);