mirror of
https://git.cloudron.io/cloudron/gitea-app
synced 2026-04-22 02:43:30 +00:00
test: convert test to ESM
Replace CommonJS require() with ESM imports, add "type": "module" to test/package.json, remove 'use strict' and jshint directives, replace __dirname with import.meta.dirname. Made-with: Cursor
This commit is contained in:
@@ -13,5 +13,6 @@
|
|||||||
"mocha": "^11.7.5",
|
"mocha": "^11.7.5",
|
||||||
"selenium-webdriver": "^4.41.0",
|
"selenium-webdriver": "^4.41.0",
|
||||||
"superagent": "^10.3.0"
|
"superagent": "^10.3.0"
|
||||||
}
|
},
|
||||||
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
|||||||
34
test/test.js
34
test/test.js
@@ -1,20 +1,16 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/* jshint esversion: 8 */
|
import 'chromedriver';
|
||||||
|
import { execSync } from 'node:child_process';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import superagent from 'superagent';
|
||||||
|
import { Builder, By, until } from 'selenium-webdriver';
|
||||||
|
import { Options } from 'selenium-webdriver/chrome';
|
||||||
|
|
||||||
/* global it, xit, describe, before, after, afterEach */
|
/* global it, xit, describe, before, after, afterEach */
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
require('chromedriver');
|
|
||||||
|
|
||||||
const execSync = require('child_process').execSync,
|
|
||||||
assert = require('node:assert/strict'),
|
|
||||||
fs = require('fs'),
|
|
||||||
path = require('path'),
|
|
||||||
superagent = require('superagent'),
|
|
||||||
{ Builder, By, until } = require('selenium-webdriver'),
|
|
||||||
{ Options } = require('selenium-webdriver/chrome');
|
|
||||||
|
|
||||||
if (!process.env.USERNAME || !process.env.PASSWORD || !process.env.EMAIL) {
|
if (!process.env.USERNAME || !process.env.PASSWORD || !process.env.EMAIL) {
|
||||||
console.log('USERNAME, PASSWORD and EMAIL env vars need to be set');
|
console.log('USERNAME, PASSWORD and EMAIL env vars need to be set');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@@ -24,7 +20,7 @@ describe('Application life cycle test', function () {
|
|||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|
||||||
const TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 5000;
|
const TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 5000;
|
||||||
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
const EXEC_ARGS = { cwd: path.resolve(import.meta.dirname, '..'), stdio: 'inherit' };
|
||||||
const LOCATION = process.env.LOCATION || 'test';
|
const LOCATION = process.env.LOCATION || 'test';
|
||||||
const SSH_PORT = 29420;
|
const SSH_PORT = 29420;
|
||||||
|
|
||||||
@@ -80,7 +76,7 @@ describe('Application life cycle test', function () {
|
|||||||
var button = await browser.findElement(By.xpath('//label[contains(text(), "Use Custom Avatar")]'));
|
var button = await browser.findElement(By.xpath('//label[contains(text(), "Use Custom Avatar")]'));
|
||||||
await browser.executeScript('arguments[0].scrollIntoView(false)', button);
|
await browser.executeScript('arguments[0].scrollIntoView(false)', button);
|
||||||
await browser.findElement(By.xpath('//label[contains(text(), "Use Custom Avatar")]')).click();
|
await browser.findElement(By.xpath('//label[contains(text(), "Use Custom Avatar")]')).click();
|
||||||
await browser.findElement(By.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(__dirname, '../logo.png'));
|
await browser.findElement(By.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(import.meta.dirname, '../logo.png'));
|
||||||
await browser.findElement(By.xpath('//button[contains(text(), "Update Avatar")]')).click();
|
await browser.findElement(By.xpath('//button[contains(text(), "Update Avatar")]')).click();
|
||||||
await browser.wait(until.elementLocated(By.xpath('//p[contains(text(),"Your avatar has been updated.")]')), TIMEOUT);
|
await browser.wait(until.elementLocated(By.xpath('//p[contains(text(),"Your avatar has been updated.")]')), TIMEOUT);
|
||||||
}
|
}
|
||||||
@@ -138,8 +134,8 @@ describe('Application life cycle test', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addPublicKey() {
|
async function addPublicKey() {
|
||||||
const publicKey = fs.readFileSync(__dirname + '/id_ed25519.pub', 'utf8');
|
const publicKey = fs.readFileSync(import.meta.dirname + '/id_ed25519.pub', 'utf8');
|
||||||
execSync(`chmod g-rw,o-rw ${__dirname}/id_ed25519`); // ssh will complain about perms later
|
execSync(`chmod g-rw,o-rw ${import.meta.dirname}/id_ed25519`); // ssh will complain about perms later
|
||||||
|
|
||||||
await browser.get('https://' + app.fqdn + '/user/settings/keys');
|
await browser.get('https://' + app.fqdn + '/user/settings/keys');
|
||||||
|
|
||||||
@@ -173,13 +169,13 @@ describe('Application life cycle test', function () {
|
|||||||
function cloneRepo() {
|
function cloneRepo() {
|
||||||
fs.rmSync(repodir, { recursive: true, force: true });
|
fs.rmSync(repodir, { recursive: true, force: true });
|
||||||
var env = Object.create(process.env);
|
var env = Object.create(process.env);
|
||||||
env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
|
env.GIT_SSH = import.meta.dirname + '/git_ssh_wrapper.sh';
|
||||||
execSync(`git clone ssh://git@${app.fqdn}:${SSH_PORT}/${username}/${reponame}.git ${repodir}`, { env: env });
|
execSync(`git clone ssh://git@${app.fqdn}:${SSH_PORT}/${username}/${reponame}.git ${repodir}`, { env: env });
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushFile() {
|
function pushFile() {
|
||||||
const env = Object.create(process.env);
|
const env = Object.create(process.env);
|
||||||
env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
|
env.GIT_SSH = import.meta.dirname + '/git_ssh_wrapper.sh';
|
||||||
execSync(`touch newfile && git add newfile && git commit -a -mx && git push ssh://git@${app.fqdn}:${SSH_PORT}/${username}/${reponame} main`,
|
execSync(`touch newfile && git add newfile && git commit -a -mx && git push ssh://git@${app.fqdn}:${SSH_PORT}/${username}/${reponame} main`,
|
||||||
{ env: env, cwd: repodir });
|
{ env: env, cwd: repodir });
|
||||||
fs.rmSync(repodir, { recursive: true, force: true });
|
fs.rmSync(repodir, { recursive: true, force: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user