diff --git a/test/package.json b/test/package.json index 1b70d36..fb69881 100644 --- a/test/package.json +++ b/test/package.json @@ -13,5 +13,6 @@ "mocha": "^11.7.5", "selenium-webdriver": "^4.41.0", "superagent": "^10.3.0" - } + }, + "type": "module" } diff --git a/test/test.js b/test/test.js index 3a6ce38..fe66825 100755 --- a/test/test.js +++ b/test/test.js @@ -1,20 +1,16 @@ #!/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 */ -'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) { console.log('USERNAME, PASSWORD and EMAIL env vars need to be set'); process.exit(1); @@ -24,7 +20,7 @@ describe('Application life cycle test', function () { this.timeout(0); 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 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")]')); 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('//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.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() { - const publicKey = fs.readFileSync(__dirname + '/id_ed25519.pub', 'utf8'); - execSync(`chmod g-rw,o-rw ${__dirname}/id_ed25519`); // ssh will complain about perms later + const publicKey = fs.readFileSync(import.meta.dirname + '/id_ed25519.pub', 'utf8'); + 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'); @@ -173,13 +169,13 @@ describe('Application life cycle test', function () { function cloneRepo() { fs.rmSync(repodir, { recursive: true, force: true }); 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 }); } function pushFile() { 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`, { env: env, cwd: repodir }); fs.rmSync(repodir, { recursive: true, force: true });