Skip to content

Commit 74e625d

Browse files
laoneobrianteeman
andauthored
[5.3] Does check the server error logs in system tests (#45409)
* Does check the server error logs in system tests * order * Update tests/System/README.md Co-authored-by: Brian Teeman <[email protected]> --------- Co-authored-by: Brian Teeman <[email protected]>
1 parent 78d2b75 commit 74e625d

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

cypress.config.dist.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ export default defineConfig({
4242
smtp_host: 'localhost',
4343
smtp_port: '1025',
4444
cmsPath: '.',
45+
logFile: '',
4546
},
4647
});

tests/System/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ The Joomla System Tests come with some convenient [Cypress Tasks](https://docs.c
178178
- **writeRelativeFile** – Writes a file relative to the CMS root folder
179179
- **deleteRelativePath** – Deletes a file or folder relative to the CMS root folder
180180
- **copyRelativeFile** – Copies a file relative to the CMS root folder
181+
- **checkForLogs** – Checks the log file (path defined in configuration) for errors
182+
- **clearLogs** – Clears the logs in the log file from the configuration
181183
- **startMailServer** – Starts the smtp-tester SMTP server
182184
- **getMails** – Get received mails from smtp-tester
183185
- **clearEmails** – Clear all smtp-tester received mails

tests/System/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ if [ -z "$( ls -A '/root/.cache/Cypress' )" ]; then
3939
npx cypress verify
4040
fi
4141

42-
npx cypress run --browser=firefox --e2e --env cmsPath=/tests/www/$TEST_GROUP,db_type=$DB_ENGINE,db_host=$DB_HOST,db_password=joomla_ut,db_prefix="${TEST_GROUP}_" --config baseUrl=https://localhost/$TEST_GROUP,screenshotsFolder=$JOOMLA_BASE/tests/System/output/screenshots
42+
npx cypress run --browser=firefox --e2e --env cmsPath=/tests/www/$TEST_GROUP,db_type=$DB_ENGINE,db_host=$DB_HOST,db_password=joomla_ut,db_prefix="${TEST_GROUP}_",logFile=/var/log/apache2/error.log --config baseUrl=https://localhost/$TEST_GROUP,screenshotsFolder=$JOOMLA_BASE/tests/System/output/screenshots

tests/System/plugins/index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getMails, clearEmails, startMailServer } from './mail.mjs';
22
import { writeRelativeFile, deleteRelativePath, copyRelativeFile } from './fs.mjs';
33
import { queryTestDB, deleteInsertedItems } from './db.mjs';
4+
import { checkForLogs, clearLogs } from './logs.mjs';
45

56
/**
67
* Does the setup of the plugins.
@@ -17,6 +18,8 @@ export default function setupPlugins(on, config) {
1718
writeRelativeFile: ({ path, content, mode }) => writeRelativeFile(path, content, config, mode),
1819
deleteRelativePath: (path) => deleteRelativePath(path, config),
1920
copyRelativeFile: ({ source, destination }) => copyRelativeFile(source, destination, config),
21+
checkForLogs: () => checkForLogs(config),
22+
clearLogs: () => clearLogs(config),
2023
getMails: () => getMails(),
2124
clearEmails: () => clearEmails(),
2225
startMailServer: () => startMailServer(config),

tests/System/plugins/logs.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2+
3+
/**
4+
* Checks if there are entries written to the logs file.
5+
*
6+
* @param {object} config - The Cypress configuration object
7+
*
8+
* @returns null
9+
*/
10+
function checkForLogs(config) {
11+
const { logFile } = config.env;
12+
if (!existsSync(logFile)) {
13+
return null;
14+
}
15+
16+
const log = readFileSync(logFile, 'utf8');
17+
if (!log) {
18+
return null;
19+
}
20+
21+
throw new Error(log);
22+
}
23+
24+
/**
25+
* Clears the log file.
26+
*
27+
* @param {object} config - The Cypress configuration object
28+
*
29+
* @returns null
30+
*/
31+
function clearLogs(config) {
32+
const { logFile } = config.env;
33+
if (!existsSync(logFile)) {
34+
return null;
35+
}
36+
37+
writeFileSync(logFile, '');
38+
39+
return null;
40+
}
41+
42+
export { checkForLogs, clearLogs };

tests/System/support/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import('joomla-cypress');
33

44
before(() => {
55
cy.task('startMailServer');
6+
cy.task('clearLogs');
67
});
78

89
afterEach(() => {
910
cy.checkForPhpNoticesOrWarnings();
11+
cy.task('checkForLogs');
1012
cy.task('cleanupDB');
1113
});

0 commit comments

Comments
 (0)