mirror of
https://git.cloudron.io/cloudron/mastodon-app.git
synced 2024-11-25 01:00:59 +00:00
prepare tests for ci
This commit is contained in:
parent
43328753d8
commit
be9cb6b0f6
1 changed files with 18 additions and 2 deletions
20
test/test.js
20
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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue