From 6c9de5793774681dea9264188ca06dbeb62a525f Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Tue, 22 Oct 2024 21:02:19 +0200 Subject: [PATCH] Prepare for ci --- Dockerfile | 5 +++-- test/test.js | 28 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 72fddbb..7dbcb37 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,10 @@ FROM cloudron/base:4.2.0@sha256:46da2fffb36353ef714f97ae8e962bd2c212ca091108d768 RUN mkdir -p /app/code /app/pkg WORKDIR /app/code -ARG VERSION=2.54.1 +# renovate: datasource=github-releases depName=prometheus/prometheus versioning=semver extractVersion=^v(?.+)$ +ARG PROMETHEUS_VERSION=2.54.1 -RUN curl -L https://github.com/prometheus/prometheus/releases/download/v${VERSION}/prometheus-${VERSION}.linux-amd64.tar.gz | tar zxvf - --strip-components 1 +RUN curl -L https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz | tar zxvf - --strip-components 1 COPY env.sh.template start.sh /app/pkg/ diff --git a/test/test.js b/test/test.js index f2af293..83baf95 100755 --- a/test/test.js +++ b/test/test.js @@ -1,10 +1,6 @@ #!/usr/bin/env node -/* jshint esversion: 8 */ -/* global describe */ -/* global before */ -/* global after */ -/* global it */ +/* global it, xit, describe, before, after, afterEach */ 'use strict'; @@ -12,6 +8,7 @@ require('chromedriver'); var execSync = require('child_process').execSync, expect = require('expect.js'), + fs = require('fs'), path = require('path'), { Builder, By, Key, until } = require('selenium-webdriver'), { Options } = require('selenium-webdriver/chrome'); @@ -24,7 +21,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 EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 50000; @@ -35,16 +32,27 @@ describe('Application life cycle test', function () { var app; before(function () { - const options = new Options().windowSize({ width: 1280, height: 1024 }); - if (process.env.HEADLESS) options.addArguments('headless'); - - browser = new Builder().forBrowser('chrome').setChromeOptions(options).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'); + }); + async function waitForElement(elem) { await browser.wait(until.elementLocated(elem), TEST_TIMEOUT); await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);