Skip to content

Commit

Permalink
append prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ykaiboussiSO committed Dec 30, 2024
1 parent 2ede094 commit b18e1e0
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 117 deletions.
Binary file not shown.
10 changes: 10 additions & 0 deletions cmd/e2e/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tabWidth": 4,
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"jsxSingleQuote": true,
"bracketSameLine": true,
"printWidth": 120,
"bracketSpacing": true
}
2 changes: 2 additions & 0 deletions cmd/e2e/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintConfigPrettier from "eslint-config-prettier";


/** @type {import('eslint').Linter.Config[]} */
Expand All @@ -26,6 +27,7 @@ export default [
"prisma/client.ts",
"prisma/seed.ts"
]},
eslintConfigPrettier,
{languageOptions: { globals: globals.node }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
Expand Down
5 changes: 4 additions & 1 deletion cmd/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"pretest": "tsc src/helpers/init.ts",
"test:e2e": "env-cmd -e dev cucumber-js --config=src/cucumber.json --tags '@e2e'",
"test:failed": "env-cmd -e dev cucumber-js -p rerun --config=src/cucumber.json @rerun.txt",
"lint": "eslint src prisma"
"lint": "eslint src prisma",
"format": "prettier --write \"src/**/*.@(js|jsx|ts|tsx|md|json)\" \"prisma/**/*.@(js|jsx|ts|tsx|md|json)\""
},
"type": "module",
"description": "E2E BDD Tests",
Expand All @@ -26,8 +27,10 @@
"dotenv": "^16.4.5",
"env-cmd": "^10.1.0",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"globals": "^15.14.0",
"playwright": "1.49.0",
"prettier": "3.4.2",
"prisma": "5.22.0",
"ts-node": "^10.9.2",
"typescript": "5.6.3",
Expand Down
19 changes: 12 additions & 7 deletions cmd/e2e/prisma/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@
//
// SPDX-License-Identifier: Apache-2.0

import prisma from "./client.js"
import prisma from './client.js';

export class dbOPS {
// delete test data in dev environment only
async deleteUsers() {
const baseURL = `${process.env.BASEURL}`.toLowerCase()
if (((`${process.env.ENV}` != "production" || `${process.env.ENV}` != "staging")) && (baseURL.toLowerCase().includes('localhost') || baseURL.toLowerCase().includes("127.0.0.1"))) {
const deleteUsers = prisma.users.deleteMany()
const deleteUserRoles = prisma.users_roles.deleteMany()
await prisma.$transaction([deleteUserRoles, deleteUsers])
const baseURL = `${process.env.BASEURL}`.toLowerCase();
if (
(`${process.env.ENV}` != 'production' || `${process.env.ENV}` != 'staging') &&
(baseURL.toLowerCase().includes('localhost') || baseURL.toLowerCase().includes('127.0.0.1'))
) {
const deleteUsers = prisma.users.deleteMany();
const deleteUserRoles = prisma.users_roles.deleteMany();
await prisma.$transaction([deleteUserRoles, deleteUsers]);
} else {
console.log(`Skipping deletion test data, baseURL: ${process.env.BASEURL} does not target local environment`)
console.log(
`Skipping deletion test data, baseURL: ${process.env.BASEURL} does not target local environment`
);
}
}
}
6 changes: 3 additions & 3 deletions cmd/e2e/prisma/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
//
// SPDX-License-Identifier: Apache-2.0

import { PrismaClient } from "@prisma/client"
import { PrismaClient } from '@prisma/client';
// Database connection will increase once we create more BDD scenarios.
// Per Prisma best practice: create a single prisma instance for each worker to perform database operations
// context: https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/databases-connections#re-using-a-single-prismaclient-instance
let prisma = new PrismaClient()
export default prisma
let prisma = new PrismaClient();
export default prisma;
40 changes: 20 additions & 20 deletions cmd/e2e/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import { users } from '@prisma/client';

let uniquePassword: string;

export interface IUserResult extends users {
export interface IUserResult extends users {
email_address: string;
uniquePassword: string;
principal_name: string;
}

// create a unique user for each scenario
// create a unique user for each scenario
export class User {
firstName: string;
lastName: string;
Expand All @@ -42,15 +42,15 @@ export class User {
isExpired: boolean;
totpSecret: string;
totpActivated: boolean;

// initialize user properties as optional parameters
constructor(
firstName = faker.person.firstName(),
lastName = faker.person.lastName(),
principalName = `${firstName}-${lastName}`,
email = `${firstName}@test.com`,
role = "Administrator",
password = "",
role = 'Administrator',
password = '',
eulaAccepted = true,
isDisabled = false,
isExpired = false,
Expand All @@ -59,29 +59,29 @@ export class User {
) {
this.firstName = firstName;
this.lastName = lastName;
this.principalName = principalName
this.principalName = principalName;
this.email = email;
this.password = password;
this.role = role,
this.eulaAccepted = eulaAccepted,
this.isDisabled = isDisabled,
this.isExpired = isExpired,
this.totpSecret = totpSecret,
this.totpActivated = totpActivated
(this.role = role),
(this.eulaAccepted = eulaAccepted),
(this.isDisabled = isDisabled),
(this.isExpired = isExpired),
(this.totpSecret = totpSecret),
(this.totpActivated = totpActivated);
}
async create() {
// sanity check when running against production environment
// production tagged tests should not include any seeding data.
if (process.env.ENV === "production") {
console.error("exiting tests: no seeding data in production environment")
exit(1)
// production tagged tests should not include any seeding data.
if (process.env.ENV === 'production') {
console.error('exiting tests: no seeding data in production environment');
exit(1);
}

// option to set the password in table driven tests
if (this.password == '') {
uniquePassword = faker.lorem.word({ length: { min: 5, max: 10 }})
uniquePassword = faker.lorem.word({ length: { min: 5, max: 10 } });
} else {
uniquePassword = this.password as string
uniquePassword = this.password as string;
}

const now = new Date();
Expand Down Expand Up @@ -130,7 +130,7 @@ export class User {

return {
...newUser,
uniquePassword
} as IUserResult
uniquePassword,
} as IUserResult;
}
}
24 changes: 6 additions & 18 deletions cmd/e2e/src/cucumber.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
{
"default": {
"paths": [
"src/tests/features/"
],
"paths": ["src/tests/features/"],
"dryRun": false,
"import": [
"src/tests/steps/*.ts",
"src/support/hooks.ts"
],
"loader": [
"ts-node/esm"
],
"import": ["src/tests/steps/*.ts", "src/support/hooks.ts"],
"loader": ["ts-node/esm"],
"format": [
"progress-bar",
"html:test-results/reports/html/cucumber-report.html",
Expand All @@ -20,18 +13,13 @@
},
"rerun": {
"dryRun": false,
"import": [
"src/tests/steps/*.ts",
"src/support/hooks.ts"
],
"loader": [
"ts-node/esm"
],
"import": ["src/tests/steps/*.ts", "src/support/hooks.ts"],
"loader": ["ts-node/esm"],
"format": [
"progress-bar",
"html:test-results/reports/html/cucumber-report.html",
"json:test-results/reports/json/cucumber-report.json",
"rerun:@rerun.txt"
]
}
}
}
4 changes: 2 additions & 2 deletions cmd/e2e/src/helpers/env/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//
// SPDX-License-Identifier: Apache-2.0

import * as dotenv from "dotenv";
import * as dotenv from 'dotenv';

export const loadEnvs = () => {
dotenv.config();
}
};
2 changes: 1 addition & 1 deletion cmd/e2e/src/helpers/hashpassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const hashPassword = async (password: string) => {
timeCost: 3,
memoryCost: 1048576,
parallelism: 32,
hashLength: 16
hashLength: 16,
});
const hashWithPadding = hashedPassword
.split('$')
Expand Down
14 changes: 7 additions & 7 deletions cmd/e2e/src/helpers/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ import * as fs from 'node:fs';
function createsupportfolders(path: string): void {
if (!fs.existsSync(path)) {
fs.mkdirSync(path, { recursive: true });
console.log(`${path} folder is created`)
console.log(`${path} folder is created`);
} else {
console.log(`${path} folder exists`)
console.log(`${path} folder exists`);
}
}

function createRerunFile(fileName: string): void {
if (!fs.existsSync(fileName)) {
fs.writeFileSync(fileName, '');
console.log(`${fileName} is created`)
console.log(`${fileName} is created`);
} else {
console.log(`${fileName} file exists`)
console.log(`${fileName} file exists`);
}
}

const reRunFile = "@rerun.txt";
const reRunFile = '@rerun.txt';
createRerunFile(reRunFile);

const reportPath = "./test-results/reports"
const reportPath = './test-results/reports';
createsupportfolders(reportPath);

const screenshotsPath = "./test-results/screenshots"
const screenshotsPath = './test-results/screenshots';
createsupportfolders(screenshotsPath);
8 changes: 4 additions & 4 deletions cmd/e2e/src/helpers/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
//
// SPDX-License-Identifier: Apache-2.0

export { };
export {};

declare global {
namespace NodeJS {
interface ProcessEnv {
DEFAULT_BROWSER: "chrome" | "firefox" | "webkit",
ENV: "staging" | "production" | "dev",
BASEURL: string
DEFAULT_BROWSER: 'chrome' | 'firefox' | 'webkit';
ENV: 'staging' | 'production' | 'dev';
BASEURL: string;
}
}
}
8 changes: 4 additions & 4 deletions cmd/e2e/src/support/FixtureManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
//
// SPDX-License-Identifier: Apache-2.0

import { Browser, BrowserContext, Page } from "@playwright/test";
import PageManager from "./pageManager.js";
import { invokeBrowser } from "./browserManager.js";
import { Browser, BrowserContext, Page } from '@playwright/test';
import PageManager from './pageManager.js';
import { invokeBrowser } from './browserManager.js';

export interface IFixture {
browser: Browser;
Expand All @@ -41,7 +41,7 @@ export default class FixtureManager implements IFixture {
context: this.context,
pageManager: this.pageManager,
page: this.pageManager.Page,
}
};
}

async openBrowser() {
Expand Down
14 changes: 7 additions & 7 deletions cmd/e2e/src/support/browserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
//
// SPDX-License-Identifier: Apache-2.0

import { LaunchOptions, chromium, firefox, webkit } from "@playwright/test";
import { LaunchOptions, chromium, firefox, webkit } from '@playwright/test';

const options: LaunchOptions = {
headless: true,
}
};

export const invokeBrowser = () => {
// TODO Add option to load browser type configuration at runtime
const browserType = process.env.DEFAULT_BROWSER;
switch (browserType) {
case "chrome":
case 'chrome':
return chromium.launch(options);
case "firefox":
case 'firefox':
return firefox.launch(options);
case "webkit":
case 'webkit':
return webkit.launch(options);
default:
throw new Error("Please set the proper browser :)")
throw new Error('Please set the proper browser :)');
}
}
};
Loading

0 comments on commit b18e1e0

Please sign in to comment.