From 8d129e38c22e3eb47218c64884803eca40bada08 Mon Sep 17 00:00:00 2001 From: Martina Scholz Date: Thu, 20 Jun 2024 12:38:37 +0200 Subject: [PATCH 1/7] [4.4] Move the Cypress Tests to ESM --- .drone.yml | 2 +- ....config.dist.js => cypress.config.dist.mjs | 6 ++--- tests/System/plugins/{db.js => db.mjs} | 6 ++--- tests/System/plugins/{fs.js => fs.mjs} | 22 +++++++-------- tests/System/plugins/index.js | 25 ----------------- tests/System/plugins/index.mjs | 27 +++++++++++++++++++ tests/System/plugins/{mail.js => mail.mjs} | 4 +-- .../support/{commands.js => commands.mjs} | 8 +++--- .../support/commands/{api.js => api.mjs} | 0 .../commands/{config.js => config.mjs} | 0 .../System/support/commands/{db.js => db.mjs} | 0 tests/System/support/index.js | 4 +-- 12 files changed, 53 insertions(+), 51 deletions(-) rename cypress.config.dist.js => cypress.config.dist.mjs (89%) rename tests/System/plugins/{db.js => db.mjs} (97%) rename tests/System/plugins/{fs.js => fs.mjs} (72%) delete mode 100644 tests/System/plugins/index.js create mode 100644 tests/System/plugins/index.mjs rename tests/System/plugins/{mail.js => mail.mjs} (93%) rename tests/System/support/{commands.js => commands.mjs} (91%) rename tests/System/support/commands/{api.js => api.mjs} (100%) rename tests/System/support/commands/{config.js => config.mjs} (100%) rename tests/System/support/commands/{db.js => db.mjs} (100%) diff --git a/.drone.yml b/.drone.yml index e7050b7641f4..602a81dfffee 100644 --- a/.drone.yml +++ b/.drone.yml @@ -219,7 +219,7 @@ steps: environment: CYPRESS_VERIFY_TIMEOUT: 100000 commands: - - mv cypress.config.dist.js cypress.config.js + - mv cypress.config.dist.mjs cypress.config.mjs - npx cypress install - npx cypress verify diff --git a/cypress.config.dist.js b/cypress.config.dist.mjs similarity index 89% rename from cypress.config.dist.js rename to cypress.config.dist.mjs index c402c269e5db..e4d00070815a 100644 --- a/cypress.config.dist.js +++ b/cypress.config.dist.mjs @@ -1,7 +1,7 @@ -const { defineConfig } = require('cypress'); -const setupPlugins = require('./tests/System/plugins/index'); +import { defineConfig } from 'cypress'; +import setupPlugins from './tests/System/plugins/index.mjs'; -module.exports = defineConfig({ +export default defineConfig({ fixturesFolder: 'tests/System/fixtures', videosFolder: 'tests/System/output/videos', screenshotsFolder: 'tests/System/output/screenshots', diff --git a/tests/System/plugins/db.js b/tests/System/plugins/db.mjs similarity index 97% rename from tests/System/plugins/db.js rename to tests/System/plugins/db.mjs index 02ee7b83c89a..c829819eef1f 100644 --- a/tests/System/plugins/db.js +++ b/tests/System/plugins/db.mjs @@ -1,5 +1,5 @@ -const mysql = require('mysql'); -const postgres = require('postgres'); +import mysql from 'mysql'; +import postgres from 'postgres'; // Items cache which are added by an insert statement let insertedItems = []; @@ -144,4 +144,4 @@ function deleteInsertedItems(config) { return Promise.all(promises); } -module.exports = { queryTestDB, deleteInsertedItems }; +export { queryTestDB, deleteInsertedItems }; diff --git a/tests/System/plugins/fs.js b/tests/System/plugins/fs.mjs similarity index 72% rename from tests/System/plugins/fs.js rename to tests/System/plugins/fs.mjs index 0b3b37227c2e..2533e728ca31 100644 --- a/tests/System/plugins/fs.js +++ b/tests/System/plugins/fs.mjs @@ -1,6 +1,6 @@ -const fs = require('fs'); -const fspath = require('path'); -const { umask } = require('node:process'); +import { chmodSync, existsSync, writeFileSync, mkdirSync, rmSync } from "fs"; +import { dirname } from "path"; +import { umask } from 'node:process'; /** * Deletes a folder with the given path recursive. @@ -11,7 +11,7 @@ const { umask } = require('node:process'); * @returns null */ function deleteFolder(path, config) { - fs.rmSync(`${config.env.cmsPath}/${path}`, { recursive: true, force: true }); + rmSync(`${config.env.cmsPath}/${path}`, { recursive: true, force: true }); return null; } @@ -31,24 +31,24 @@ function deleteFolder(path, config) { * @returns null */ function writeFile(path, content, config, mode = 0o444) { - const fullPath = fspath.join(config.env.cmsPath, path); + const fullPath = dirname.join(config.env.cmsPath, path); // Prologue: Reset process file mode creation mask to ensure the umask value is not subtracted const oldmask = umask(0); // Create missing parent directories with 'rwxrwxrwx' - fs.mkdirSync(fspath.dirname(fullPath), { recursive: true, mode: 0o777 }); + mkdirSync(dirname(fullPath), { recursive: true, mode: 0o777 }); // Check if the file exists - if (fs.existsSync(fullPath)) { + if (existsSync(fullPath)) { // Set 'rw-rw-rw-' to be able to overwrite the file - fs.chmodSync(fullPath, 0o666); + chmodSync(fullPath, 0o666); } // Write or overwrite the file on relative path with given content - fs.writeFileSync(fullPath, content); + writeFileSync(fullPath, content); // Finally set given file mode or default 'r--r--r--' - fs.chmodSync(fullPath, mode); + chmodSync(fullPath, mode); // Epilogue: Restore process file mode creation mask umask(oldmask); return null; } -module.exports = { writeFile, deleteFolder }; +export { writeFile, deleteFolder }; diff --git a/tests/System/plugins/index.js b/tests/System/plugins/index.js deleted file mode 100644 index 771335eb69a1..000000000000 --- a/tests/System/plugins/index.js +++ /dev/null @@ -1,25 +0,0 @@ -const mail = require('./mail'); -const fs = require('./fs'); -const db = require('./db'); - -/** - * Does the setup of the plugins. - * - * @param {*} on - * @param {object} config The configuration - * - * @see https://docs.cypress.io/guides/references/configuration#setupNodeEvents - */ -function setupPlugins(on, config) { - on('task', { - queryDB: (query) => db.queryTestDB(query, config), - cleanupDB: () => db.deleteInsertedItems(config), - writeFile: ({ path, content, mode }) => fs.writeFile(path, content, config, mode), - deleteFolder: (path) => fs.deleteFolder(path, config), - getMails: () => mail.getMails(), - clearEmails: () => mail.clearEmails(), - startMailServer: () => mail.startMailServer(config), - }); -} - -module.exports = setupPlugins; diff --git a/tests/System/plugins/index.mjs b/tests/System/plugins/index.mjs new file mode 100644 index 000000000000..653577e36f6d --- /dev/null +++ b/tests/System/plugins/index.mjs @@ -0,0 +1,27 @@ +// const mail = require('./mail'); +// const fs = require('./fs'); +// const db = require('./db'); +import { getMails, clearEmails, startMailServer } from "./mail.mjs"; +import { writeFile, deleteFolder } from "./fs.mjs"; +import { queryTestDB, deleteInsertedItems } from "./db.mjs"; + +/** + * Does the setup of the plugins. + * + * @param {*} on + * @param {object} config The configuration + * + * @see https://docs.cypress.io/guides/references/configuration#setupNodeEvents + */ +export default function setupPlugins(on, config) { + on('task', { + queryDB: (query) => queryTestDB(query, config), + cleanupDB: () => deleteInsertedItems(config), + writeFile: ({ path, content, mode }) => writeFile(path, content, config, mode), + deleteFolder: (path) => deleteFolder(path, config), + getMails: () => getMails(), + clearEmails: () => clearEmails(), + startMailServer: () => startMailServer(config), + }); +} + diff --git a/tests/System/plugins/mail.js b/tests/System/plugins/mail.mjs similarity index 93% rename from tests/System/plugins/mail.js rename to tests/System/plugins/mail.mjs index 4deea22b85f3..c40ca24794d3 100644 --- a/tests/System/plugins/mail.js +++ b/tests/System/plugins/mail.mjs @@ -1,4 +1,4 @@ -const mailTester = require('smtp-tester'); +import mailTester from 'smtp-tester'; // The mail server instance let mailServer = null; @@ -64,4 +64,4 @@ function startMailServer(config) { return null; } -module.exports = { getMails, clearEmails, startMailServer }; +export { getMails, clearEmails, startMailServer }; diff --git a/tests/System/support/commands.js b/tests/System/support/commands.mjs similarity index 91% rename from tests/System/support/commands.js rename to tests/System/support/commands.mjs index c09c4a7783bc..3f1300fed4c3 100644 --- a/tests/System/support/commands.js +++ b/tests/System/support/commands.mjs @@ -5,11 +5,11 @@ * https://github.com/cypress-io/cypress/issues/6575 */ -import './commands/api'; -import './commands/config'; -import './commands/db'; +import { registerCommands } from 'joomla-cypress'; -const { registerCommands } = require('../../../node_modules/joomla-cypress/src/index.js'); +import './commands/api.mjs'; +import './commands/config.mjs'; +import './commands/db.mjs'; registerCommands(); diff --git a/tests/System/support/commands/api.js b/tests/System/support/commands/api.mjs similarity index 100% rename from tests/System/support/commands/api.js rename to tests/System/support/commands/api.mjs diff --git a/tests/System/support/commands/config.js b/tests/System/support/commands/config.mjs similarity index 100% rename from tests/System/support/commands/config.js rename to tests/System/support/commands/config.mjs diff --git a/tests/System/support/commands/db.js b/tests/System/support/commands/db.mjs similarity index 100% rename from tests/System/support/commands/db.js rename to tests/System/support/commands/db.mjs diff --git a/tests/System/support/index.js b/tests/System/support/index.js index 43e0237e29b6..68b3967f8d96 100644 --- a/tests/System/support/index.js +++ b/tests/System/support/index.js @@ -1,5 +1,5 @@ -import './commands'; -import 'joomla-cypress'; +import('./commands.mjs'); +import('joomla-cypress'); before(() => { cy.task('startMailServer'); From b617ae32cd8fff07b9f95363f5405f119e28e82d Mon Sep 17 00:00:00 2001 From: Martina Scholz Date: Thu, 20 Jun 2024 13:19:43 +0200 Subject: [PATCH 2/7] drone signature --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 602a81dfffee..41889d3c8472 100644 --- a/.drone.yml +++ b/.drone.yml @@ -504,6 +504,6 @@ trigger: --- kind: signature -hmac: 4883ca31950b6197886ad6e53fa6ec4bd19152852ea3e016a95a27b7ff27eece +hmac: ccc71c7a0c6643aef1000b49a0125d4a9bf2bacedc3875c9106b31449e7f50f8 ... From aa1be18e4767f4870539bcd4e0a5d4e10b3c3be9 Mon Sep 17 00:00:00 2001 From: Martina Scholz Date: Thu, 20 Jun 2024 14:00:43 +0200 Subject: [PATCH 3/7] resolve conflicts with #43663 - part 2 --- tests/System/plugins/fs.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/System/plugins/fs.mjs b/tests/System/plugins/fs.mjs index 2b674df3fdbb..3710e94bd246 100644 --- a/tests/System/plugins/fs.mjs +++ b/tests/System/plugins/fs.mjs @@ -54,4 +54,4 @@ function writeRelativeFile(relativePath, content, config, mode = 0o444) { return null; } -export { writeFile, deleteFolder }; +export { writeRelativeFile, deleteRelativePath }; From c3210c552d0aca943bd9606e399de6b3587661e4 Mon Sep 17 00:00:00 2001 From: Martina Scholz Date: Thu, 20 Jun 2024 14:26:33 +0200 Subject: [PATCH 4/7] Fix path.join --- tests/System/plugins/fs.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/System/plugins/fs.mjs b/tests/System/plugins/fs.mjs index 3710e94bd246..0ef550951ae4 100644 --- a/tests/System/plugins/fs.mjs +++ b/tests/System/plugins/fs.mjs @@ -14,7 +14,7 @@ import { umask } from 'node:process'; */ function deleteRelativePath(relativePath, config) { const fullPath = dirname.join(config.env.cmsPath, relativePath); - fs.rmSync(fullPath, { recursive: true, force: true }); + rmSync(fullPath, { recursive: true, force: true }); return null; } @@ -34,7 +34,7 @@ function deleteRelativePath(relativePath, config) { * @returns null */ function writeRelativeFile(relativePath, content, config, mode = 0o444) { - const fullPath = dirname.join(config.env.cmsPath, relativePath); + const fullPath = path.join(config.env.cmsPath, relativePath); // Prologue: Reset process file mode creation mask to ensure the umask value is not subtracted const oldmask = umask(0); // Create missing parent directories with 'rwxrwxrwx' From e1c23738cecd5c3a030b0d63a4e1739551d79a89 Mon Sep 17 00:00:00 2001 From: Martina Scholz Date: Thu, 20 Jun 2024 14:55:44 +0200 Subject: [PATCH 5/7] Fix path.join - 2 --- tests/System/plugins/fs.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/System/plugins/fs.mjs b/tests/System/plugins/fs.mjs index 0ef550951ae4..c87fa979e4f5 100644 --- a/tests/System/plugins/fs.mjs +++ b/tests/System/plugins/fs.mjs @@ -13,7 +13,7 @@ import { umask } from 'node:process'; * @returns null */ function deleteRelativePath(relativePath, config) { - const fullPath = dirname.join(config.env.cmsPath, relativePath); + const fullPath = path.join(config.env.cmsPath, relativePath); rmSync(fullPath, { recursive: true, force: true }); return null; From 3ea76a285e19deb96e76cce31c67a2c24bbbe23e Mon Sep 17 00:00:00 2001 From: Martina Scholz Date: Thu, 20 Jun 2024 15:33:36 +0200 Subject: [PATCH 6/7] Fix import join from path --- tests/System/plugins/fs.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/System/plugins/fs.mjs b/tests/System/plugins/fs.mjs index c87fa979e4f5..819d285eb33e 100644 --- a/tests/System/plugins/fs.mjs +++ b/tests/System/plugins/fs.mjs @@ -1,5 +1,5 @@ import { chmodSync, existsSync, writeFileSync, mkdirSync, rmSync } from "fs"; -import { dirname } from "path"; +import { dirname, join } from "path"; import { umask } from 'node:process'; /** @@ -13,7 +13,7 @@ import { umask } from 'node:process'; * @returns null */ function deleteRelativePath(relativePath, config) { - const fullPath = path.join(config.env.cmsPath, relativePath); + const fullPath = join(config.env.cmsPath, relativePath); rmSync(fullPath, { recursive: true, force: true }); return null; @@ -34,7 +34,7 @@ function deleteRelativePath(relativePath, config) { * @returns null */ function writeRelativeFile(relativePath, content, config, mode = 0o444) { - const fullPath = path.join(config.env.cmsPath, relativePath); + const fullPath = join(config.env.cmsPath, relativePath); // Prologue: Reset process file mode creation mask to ensure the umask value is not subtracted const oldmask = umask(0); // Create missing parent directories with 'rwxrwxrwx' From 29cf281dca8de74976b0915ffb0cb858c56398e1 Mon Sep 17 00:00:00 2001 From: Martina Scholz <64533137+LadySolveig@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:30:54 +0200 Subject: [PATCH 7/7] Remove the forgotten commented out orginial imports from plugin/index.js --- tests/System/plugins/index.mjs | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/System/plugins/index.mjs b/tests/System/plugins/index.mjs index dcee97c8c5f1..fff01fe477d0 100644 --- a/tests/System/plugins/index.mjs +++ b/tests/System/plugins/index.mjs @@ -1,6 +1,3 @@ -// const mail = require('./mail'); -// const fs = require('./fs'); -// const db = require('./db'); import { getMails, clearEmails, startMailServer } from "./mail.mjs"; import { writeRelativeFile, deleteRelativePath } from "./fs.mjs"; import { queryTestDB, deleteInsertedItems } from "./db.mjs";