Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.4] Move the Cypress Tests to ESM #43676

Merged
merged 12 commits into from
Jun 24, 2024
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -504,6 +504,6 @@ trigger:

---
kind: signature
hmac: 4883ca31950b6197886ad6e53fa6ec4bd19152852ea3e016a95a27b7ff27eece
hmac: ccc71c7a0c6643aef1000b49a0125d4a9bf2bacedc3875c9106b31449e7f50f8

...
6 changes: 3 additions & 3 deletions cypress.config.dist.js → cypress.config.dist.mjs
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
6 changes: 3 additions & 3 deletions tests/System/plugins/db.js → tests/System/plugins/db.mjs
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down Expand Up @@ -144,4 +144,4 @@ function deleteInsertedItems(config) {
return Promise.all(promises);
}

module.exports = { queryTestDB, deleteInsertedItems };
export { queryTestDB, deleteInsertedItems };
24 changes: 12 additions & 12 deletions tests/System/plugins/fs.js → tests/System/plugins/fs.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
const { umask } = require('node:process');
import { chmodSync, existsSync, writeFileSync, mkdirSync, rmSync } from "fs";
import { dirname, join } from "path";
import { umask } from 'node:process';

/**
* Synchronously deletes a file or folder, relative to cmsPath.
Expand All @@ -13,8 +13,8 @@ const { umask } = require('node:process');
* @returns null
*/
function deleteRelativePath(relativePath, config) {
const fullPath = path.join(config.env.cmsPath, relativePath);
fs.rmSync(fullPath, { recursive: true, force: true });
const fullPath = join(config.env.cmsPath, relativePath);
rmSync(fullPath, { recursive: true, force: true });

return null;
}
Expand All @@ -34,24 +34,24 @@ 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'
fs.mkdirSync(path.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 = { writeRelativeFile, deleteRelativePath };
export { writeRelativeFile, deleteRelativePath };
25 changes: 0 additions & 25 deletions tests/System/plugins/index.js

This file was deleted.

27 changes: 27 additions & 0 deletions tests/System/plugins/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// const mail = require('./mail');
// const fs = require('./fs');
// const db = require('./db');
import { getMails, clearEmails, startMailServer } from "./mail.mjs";
LadySolveig marked this conversation as resolved.
Show resolved Hide resolved
import { writeRelativeFile, deleteRelativePath } 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),
writeRelativeFile: ({ path, content, mode }) => writeRelativeFile(path, content, config, mode),
deleteRelativePath: (path) => deleteRelativePath(path, config),
getMails: () => getMails(),
clearEmails: () => clearEmails(),
startMailServer: () => startMailServer(config),
});
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mailTester = require('smtp-tester');
import mailTester from 'smtp-tester';

// The mail server instance
let mailServer = null;
Expand Down Expand Up @@ -64,4 +64,4 @@ function startMailServer(config) {
return null;
}

module.exports = { getMails, clearEmails, startMailServer };
export { getMails, clearEmails, startMailServer };
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions tests/System/support/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './commands';
import 'joomla-cypress';
import('./commands.mjs');
import('joomla-cypress');

before(() => {
cy.task('startMailServer');
Expand Down