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

e2e: add prettier and eslint #31049

Merged
merged 7 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/dotcms-e2e-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Now that we have these packages installed we need to start dotCMS (with its depe
At `e2e/e2e-dotcms-node/frontend/package.json` you can find the available scripts you can call to execute the tests:

```json lines
"scripts": {yarn playwright show-report;
"scripts": {
"show-report": "if [[ \"$CURRENT_ENV\" != \"ci\" ]]; then fi",
"start": "PLAYWRIGHT_JUNIT_SUITE_ID=nodee2etestsuite PLAYWRIGHT_JUNIT_SUITE_NAME='E2E Node Test Suite' PLAYWRIGHT_JUNIT_OUTPUT_FILE='../target/failsafe-reports/TEST-e2e-node-results.xml' yarn playwright test ${PLAYWRIGHT_SPECIFIC} ${PLAYWRIGHT_DEBUG}; yarn run show-report",
"start-local": "CURRENT_ENV=local yarn run start",
Expand All @@ -99,6 +99,7 @@ command before the tests on top of what is found on http://localhost:8080
- `start-ci`: runs E2E tests against http://localhost:8080 in `headless` mode which is how it's done in the pipeline

So, assuming that you are a frontend developer and you are still implementing a feature using the `start-dev` script will make much sense since it will run `nx` to start the app in the `4200` port.

```shell
yarn run start-dev
```
Expand Down
12 changes: 12 additions & 0 deletions e2e/dotcms-e2e-node/frontend/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintConfigPrettier from "eslint-config-prettier";
import playwright from "eslint-plugin-playwright";

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.strict,
tseslint.configs.stylistic,
eslintConfigPrettier,
playwright.configs["flat/recommended"],
);
114 changes: 59 additions & 55 deletions e2e/dotcms-e2e-node/frontend/index.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,88 @@
const fs = require('fs');
const path = require('path');
const xml2js = require('xml2js');
const fs = require("fs");
const path = require("path");
const xml2js = require("xml2js");

const summaryResults = {
completed: 0,
errors: 0,
failures: 0,
skipped: 0
completed: 0,
errors: 0,
failures: 0,
skipped: 0,
};

// Default configurations
const defaultE2eTestsResultsDir = '../target/failsafe-reports'; // Default results directory
const defaultE2eTestsResultsDir = "../target/failsafe-reports"; // Default results directory

// Function to generate failsafe-summary.xml
const generateFailsafeSummaryXml = (e2eTestsResultsDir) => {
const builder = new xml2js.Builder();
const result = summaryResults.failures > 0 ? 255 : 0;
const xmlObj = {
'failsafe-summary': {
$: { result: result },
completed: summaryResults.completed,
errors: summaryResults.errors,
failures: summaryResults.failures,
skipped: summaryResults.skipped
}
};
const builder = new xml2js.Builder();
const result = summaryResults.failures > 0 ? 255 : 0;
const xmlObj = {
"failsafe-summary": {
$: { result: result },
completed: summaryResults.completed,
errors: summaryResults.errors,
failures: summaryResults.failures,
skipped: summaryResults.skipped,
},
};

if (summaryResults.failures > 0) {
xmlObj['failsafe-summary']['failureMessage'] = 'There are test failures.';
}
if (summaryResults.failures > 0) {
xmlObj["failsafe-summary"]["failureMessage"] = "There are test failures.";
}

const xml = builder.buildObject(xmlObj);
const xml = builder.buildObject(xmlObj);

fs.writeFileSync(path.join(e2eTestsResultsDir, 'failsafe-summary.xml'), xml, 'utf8');
}
fs.writeFileSync(
path.join(e2eTestsResultsDir, "failsafe-summary.xml"),
xml,
"utf8",
);
};

const processTestsResults = async () => {
const parser = new xml2js.Parser();
const xml = fs.readFileSync(process.env.PLAYWRIGHT_JUNIT_OUTPUT_FILE, 'utf8');
const xmlDoc = await parser.parseStringPromise(xml);
const parser = new xml2js.Parser();
const xml = fs.readFileSync(process.env.PLAYWRIGHT_JUNIT_OUTPUT_FILE, "utf8");
const xmlDoc = await parser.parseStringPromise(xml);

xmlDoc.testsuites.testsuite.forEach((ts) => {
const tests = parseInt(ts.tests || '0');
const errors = parseInt(ts.errors || '0');
const failures = parseInt(ts.failures || '0');
const skipped = parseInt(ts.skipped || '0');
summaryResults.completed += tests;
summaryResults.errors += errors;
summaryResults.failures += failures;
summaryResults.skipped += skipped;
});
xmlDoc.testsuites.testsuite.forEach((ts) => {
const tests = parseInt(ts.tests || "0");
const errors = parseInt(ts.errors || "0");
const failures = parseInt(ts.failures || "0");
const skipped = parseInt(ts.skipped || "0");
summaryResults.completed += tests;
summaryResults.errors += errors;
summaryResults.failures += failures;
summaryResults.skipped += skipped;
});
};

/**
* Main function to process command line arguments and run the script.
* Parses command line arguments for named parameters.
*/
async function main() {
const e2eTestsResultsDir = path.resolve(__dirname, defaultE2eTestsResultsDir);
// Ensure results directory exists
if (!fs.existsSync(e2eTestsResultsDir)) {
fs.mkdirSync(e2eTestsResultsDir, { recursive: true });
}
const e2eTestsResultsDir = path.resolve(__dirname, defaultE2eTestsResultsDir);
// Ensure results directory exists
if (!fs.existsSync(e2eTestsResultsDir)) {
fs.mkdirSync(e2eTestsResultsDir, { recursive: true });
}

try {
await processTestsResults();
generateFailsafeSummaryXml(e2eTestsResultsDir);
try {
await processTestsResults();
generateFailsafeSummaryXml(e2eTestsResultsDir);

if (summaryResults.failures > 0) {
console.error('Some E2E tests failed.');
process.exit(0);
}
} catch (error) {
console.error('An error occurred:', error);
process.exit(1);
if (summaryResults.failures > 0) {
console.error("Some E2E tests failed.");
process.exit(0);
}
} catch (error) {
console.error("An error occurred:", error);
process.exit(1);
}
}

// Run the main function and handle any errors
main().catch((err) => {
console.error('Unhandled error:', err);
process.exit(1);
console.error("Unhandled error:", err);
process.exit(1);
});
49 changes: 24 additions & 25 deletions e2e/dotcms-e2e-node/frontend/locators/globalLocators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,47 @@
* Locators for the iframes in the main page.
*/
export const iFramesLocators = {
main_iframe: 'iframe[name="detailFrame"]',
dot_iframe: 'dot-iframe-dialog iframe[name="detailFrame"]',
wysiwygFrame: 'iframe[title="Rich Text Area\\. Press ALT-F9 for menu\\. Press ALT-F10 for toolbar\\. Press ALT-0 for help"]',
dataTestId: '[data-testid="iframe"]'
}
main_iframe: 'iframe[name="detailFrame"]',
dot_iframe: 'dot-iframe-dialog iframe[name="detailFrame"]',
wysiwygFrame:
'iframe[title="Rich Text Area\\. Press ALT-F9 for menu\\. Press ALT-F10 for toolbar\\. Press ALT-0 for help"]',
dataTestId: '[data-testid="iframe"]',
};

/**
* Locators for the login functionality.
*/
export const loginLocators = {
userNameInput: 'input[id="inputtext"]',
passwordInput: 'input[id="password"]',
loginBtn: 'submitButton'
}
userNameInput: 'input[id="inputtext"]',
passwordInput: 'input[id="password"]',
loginBtn: "submitButton",
};

/**
* Locators for the Add Content functionality.
*/
export const addContent = {
addBtn: '#dijit_form_DropDownButton_0',
addNewContentSubMenu: 'Add New Content',
addNewMenuLabel: '▼'
}
addBtn: "#dijit_form_DropDownButton_0",
addNewContentSubMenu: "Add New Content",
addNewMenuLabel: "▼",
};

/**
* Locators for the Rich Text functionality.
*/
export const contentGeneric = {
locator: "articleContent (Generic)",
label: "Content (Generic)"
}
locator: "articleContent (Generic)",
label: "Content (Generic)",
};

export const fileAsset = {
locator: "attach_fileFile Asset",
label: "File Asset"
}
locator: "attach_fileFile Asset",
label: "File Asset",
};

export const pageAsset = {
locator: "descriptionPage",
label: "Page"
}

export {
} from './navigation/menuLocators';
locator: "descriptionPage",
label: "Page",
};

export {} from "./navigation/menuLocators";
61 changes: 31 additions & 30 deletions e2e/dotcms-e2e-node/frontend/locators/navigation/menuLocators.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
import {Page, Locator} from '@playwright/test';
import { Page, Locator } from "@playwright/test";

export class GroupEntriesLocators {
readonly SITE: Locator;
readonly CONTENT: Locator;
readonly SCHEMA: Locator;

constructor(page: Page) {
this.SITE = page.getByText('Site', {exact: true});
this.CONTENT = page.getByRole('complementary').getByText('Content', {exact: true});
this.SCHEMA = page.getByText('Schema');

}
readonly SITE: Locator;
readonly CONTENT: Locator;
readonly SCHEMA: Locator;

constructor(page: Page) {
this.SITE = page.getByText("Site", { exact: true });
this.CONTENT = page
.getByRole("complementary")
.getByText("Content", { exact: true });
this.SCHEMA = page.getByText("Schema");
}
}

/**
* Locators for the tools in the menu
*/
export class ToolEntriesLocators {
readonly SEARCH_ALL: Locator;
readonly CONTENT_TYPES: Locator;
readonly CATEGORIES: Locator;


constructor(page: Page) {
this.SEARCH_ALL = page.getByRole('link', {name: 'Search All'});
this.CONTENT_TYPES = page.getByRole('link', {name: 'Content Types'});
this.CATEGORIES = page.getByRole('link', { name: 'Categories' });
}
readonly SEARCH_ALL: Locator;
readonly CONTENT_TYPES: Locator;
readonly CATEGORIES: Locator;

constructor(page: Page) {
this.SEARCH_ALL = page.getByRole("link", { name: "Search All" });
this.CONTENT_TYPES = page.getByRole("link", { name: "Content Types" });
this.CATEGORIES = page.getByRole("link", { name: "Categories" });
}
}

/**
* Locators for the menu entries
*/
export class MenuEntriesLocators {
readonly EXPAND: Locator;
readonly COLLAPSE: Locator;
readonly EXPAND: Locator;
readonly COLLAPSE: Locator;

constructor(page: Page) {
/*this.EXPAND = page.locator('button[ng-reflect-ng-class="[object Object]"]').first();
constructor(page: Page) {
/*this.EXPAND = page.locator('button[ng-reflect-ng-class="[object Object]"]').first();
this.COLLAPSE = page.locator('button[ng-reflect-ng-class="[object Object]"]').first();
this.EXPAND = page.locator('button[ng-reflect-ng-class="[object Object]"]');
this.COLLAPSE = page.locator('button[ng-reflect-ng-class="[object Object]"]');*/
this.EXPAND = page.getByRole('button', { name: '' });
this.COLLAPSE = page.locator('button[ng-reflect-ng-class="[object Object]"]').first();

}
}
this.EXPAND = page.getByRole("button", { name: "" });
this.COLLAPSE = page
.locator('button[ng-reflect-ng-class="[object Object]"]')
.first();
}
}
15 changes: 13 additions & 2 deletions e2e/dotcms-e2e-node/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@eslint/js": "^9.17.0",
"@playwright/test": "^1.48.2",
"@types/node": "^22.5.4",
"dotenv": "^16.4.5"
"@typescript-eslint/eslint-plugin": "^8.19.0",
"dotenv": "^16.4.5",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-playwright": "^2.1.0",
"prettier": "3.4.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.19.0"
},
"dependencies": {
"jsdom": "^25.0.1",
Expand All @@ -18,6 +26,9 @@
"start-local": "CURRENT_ENV=local yarn run start",
"start-dev": "CURRENT_ENV=dev yarn run start",
"start-ci": "CURRENT_ENV=ci yarn run start",
"post-testing": "PLAYWRIGHT_JUNIT_OUTPUT_FILE='../target/failsafe-reports/TEST-e2e-node-results.xml' node index.js"
"post-testing": "PLAYWRIGHT_JUNIT_OUTPUT_FILE='../target/failsafe-reports/TEST-e2e-node-results.xml' node index.js",
"format": "prettier --write .",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
}
}
Loading
Loading