From b1f79dfa1eab8cf7082a4a21a804707a6520ce72 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Wed, 15 Apr 2026 16:16:58 +0200 Subject: [PATCH] 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 --- test/package.json | 3 ++- test/test.js | 28 ++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/test/package.json b/test/package.json index 8b3297f..93ed1bf 100644 --- a/test/package.json +++ b/test/package.json @@ -14,5 +14,6 @@ "mocha": "^11.7.4", "selenium-webdriver": "^4.36.0", "superagent": "^10.2.3" - } + }, + "type": "module" } diff --git a/test/test.js b/test/test.js index bfcc632..eda4d68 100644 --- a/test/test.js +++ b/test/test.js @@ -1,21 +1,17 @@ #!/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 timers from 'node:timers/promises'; +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'), - timers = require('timers/promises'), - { 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); @@ -27,7 +23,7 @@ describe('Application life cycle test', function () { const LOCATION = process.env.LOCATION || 'test'; const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 30000; const BUCKET = 'cloudrontestbucket'; - const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }; + const EXEC_ARGS = { cwd: path.resolve(import.meta.dirname, '..'), stdio: 'inherit' }; let browser, app; let rootPassword; @@ -139,7 +135,7 @@ describe('Application life cycle test', function () { } async function changeAdminCredentials() { - let data = fs.readFileSync(path.join(__dirname, '../env.sh.template'), 'utf8'); + let data = fs.readFileSync(path.join(import.meta.dirname, '../env.sh.template'), 'utf8'); data += '\nexport MINIO_ROOT_USER=minioakey\nexport MINIO_ROOT_PASSWORD=minioskey\n'; fs.writeFileSync('/tmp/env.sh', data); execSync(`cloudron push --app ${app.id} /tmp/env.sh /app/data/env.sh`, EXEC_ARGS);