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:
Girish Ramakrishnan
2026-04-15 16:16:57 +02:00
parent 43b6dbc74a
commit cd4d6efee4
2 changed files with 12 additions and 15 deletions

View File

@@ -14,5 +14,6 @@
},
"dependencies": {
"chromedriver": "^146.0.5"
}
},
"type": "module"
}

View File

@@ -1,6 +1,13 @@
#!/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 { Builder, By, until } from 'selenium-webdriver';
import { Options } from 'selenium-webdriver/chrome';
/* global describe */
/* global before */
/* global after */
@@ -8,17 +15,6 @@
/* global it */
/* global xit */
'use strict';
require('chromedriver');
const execSync = require('child_process').execSync,
assert = require('node:assert/strict'),
fs = require('fs'),
path = require('path'),
{ Builder, By, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
if (!process.env.USERNAME || !process.env.PASSWORD) {
console.log('USERNAME and PASSWORD env vars need to be set');
process.exit(1);
@@ -29,7 +25,7 @@ describe('Application life cycle test', function () {
const LOCATION = process.env.LOCATION || 'test';
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT) || 10000;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
const EXEC_ARGS = { cwd: path.resolve(import.meta.dirname, '..'), stdio: 'inherit' };
let browser, app;
const username = process.env.USERNAME;
@@ -137,7 +133,7 @@ describe('Application life cycle test', function () {
it('has registration open', checkRegistration.bind(null, 'none'));
let testPassword;
it('create a user with CLI', function () {
const output = execSync('cloudron exec --app ' + LOCATION + ' -- bin/tootctl accounts create test --email=test@cloudron.io', { cwd: path.resolve(__dirname, '..'), encoding: 'utf8' });
const output = execSync('cloudron exec --app ' + LOCATION + ' -- bin/tootctl accounts create test --email=test@cloudron.io', { cwd: path.resolve(import.meta.dirname, '..'), encoding: 'utf8' });
console.log(output);
testPassword = output.slice(output.indexOf('New password: ') + 'New password: '.length).trim();
console.log(testPassword);