From 24eac72d5765b18675819df5d80e09263fd8e933 Mon Sep 17 00:00:00 2001 From: Aref Shafaei Date: Thu, 1 Aug 2024 14:23:21 -0700 Subject: [PATCH] inject defaultCatalog property to chaise-config and remove catalog alias creation step while the alias method worked properly for one user, we found several issues when multiple people want to run the test cases: 1. when some one adds alias to a catalog, they will become the owner of that alias. so the next person won't be able to use the same alias on a different catalog. We might be able to solve this by passing the owner property and use the isrd-testers or isrd-gorups. but then we have to hardcode this in our chaise test step. 2. we are not able to run multiple instances of our test suite at the same time on the same server. so for example if user1 and user2 start running the test cases together, since we're using the same alias name in these two instances, the alias is going to be attached to only one of the catalogs which can cause issues. --- .eslintrc.js | 1 + Makefile | 4 +++ test/e2e/setup/playwright.model.ts | 8 +++++ test/e2e/setup/playwright.setup.ts | 30 ++++++++++++++----- .../specs/delete-prohibited/chaise-config.js | 1 - .../navbar/playwright.config.ts | 1 + .../delete-prohibited/playwright.config.ts | 1 + 7 files changed, 38 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 87d95d767..dbed66270 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -56,6 +56,7 @@ module.exports = { '@typescript-eslint/no-unsafe-function-type': 'warn', '@typescript-eslint/ban-ts-comment': 'warn', '@typescript-eslint/no-inferrable-types': 'warn', + '@typescript-eslint/no-require-imports': 'warn', // ------------------ testing ------------------ '@typescript-eslint/no-floating-promises': 'warn' diff --git a/Makefile b/Makefile index 2d0e6f8a5..0287903e3 100644 --- a/Makefile +++ b/Makefile @@ -502,6 +502,10 @@ lint: $(SOURCE) lint-w-warn: $(SOURCE) @npx eslint src --ext .ts,.tsx +.PHONY: lint-tests +lint-tests: + npx eslint test/e2e --ext .ts,.tsx --quiet + # Rule to create the package. .PHONY: dist-wo-deps dist-wo-deps: print-variables run-webpack $(SASS) $(MIN) $(HTML) gitversion diff --git a/test/e2e/setup/playwright.model.ts b/test/e2e/setup/playwright.model.ts index 30cfbe583..d61154b5d 100644 --- a/test/e2e/setup/playwright.model.ts +++ b/test/e2e/setup/playwright.model.ts @@ -23,6 +23,14 @@ export type TestOptions = { */ chaiseConfigFilePath?: string, + /** + * if set to to true, we will inject the "defaultCatalog" property + * into the chaise-config.js file. + * + * the id of the catalog created for the chrome project will be used for this. + */ + addDefaultCatalogToChaiseConfig?: boolean, + manualTestConfig?: boolean, /** diff --git a/test/e2e/setup/playwright.setup.ts b/test/e2e/setup/playwright.setup.ts index 176042c83..3051f8d6e 100644 --- a/test/e2e/setup/playwright.setup.ts +++ b/test/e2e/setup/playwright.setup.ts @@ -2,10 +2,11 @@ import { FullConfig } from '@playwright/test'; import axios from 'axios'; import { execSync } from 'child_process'; import fs from 'fs'; +import path from 'path'; import { TestOptions } from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.model'; -import { removeAllCatalogs, setupCatalog } from '@isrd-isi-edu/chaise/test/e2e/utils/catalog-utils'; -import { ENTITIES_PATH, PW_PROJECT_NAMES } from '@isrd-isi-edu/chaise/test/e2e/utils/constants'; +import { getCatalogID, removeAllCatalogs, setupCatalog } from '@isrd-isi-edu/chaise/test/e2e/utils/catalog-utils'; +import { ENTITIES_PATH, PW_PROJECT_NAMES, UPLOAD_FOLDER } from '@isrd-isi-edu/chaise/test/e2e/utils/constants'; import { setCatalogID } from '@isrd-isi-edu/chaise/test/e2e/utils/catalog-utils'; /** @@ -80,7 +81,7 @@ export default async function globalSetup(config: FullConfig) { chaiseConfigFilePath = `test/e2e/specs/${options.mainSpecName}/chaise-config.js`; } - copyChaiseConfig(chaiseConfigFilePath); + copyChaiseConfig(chaiseConfigFilePath, options.addDefaultCatalogToChaiseConfig); registerCallbacks(testConfiguration); } @@ -180,9 +181,7 @@ async function createCatalog(testConfiguration: any, projectNames: string[], mai for (const p of projectNames) { try { - // add alias to the catalog based on the config and project name - const alias = `${mainSpecName}-${p}`; - const res = await setupCatalog({ catalog: { ...catalog, alias }, schemas }); + const res = await setupCatalog({ catalog: { ...catalog }, schemas }); console.log(`catalog with id ${res.catalogId} created for project ${p}`); setCatalogID(p, res.catalogId); @@ -292,7 +291,7 @@ async function getSessionByUserPass(username: string, password: string, authCook /** * copy the chaise config into desired location */ -function copyChaiseConfig(chaiseConfigFilePath?: string) { +function copyChaiseConfig(chaiseConfigFilePath?: string, addDefaultCatalogToChaiseConfig?: boolean) { let chaiseFilePath = 'chaise-config-sample.js'; if (typeof chaiseConfigFilePath === 'string') { try { @@ -303,6 +302,23 @@ function copyChaiseConfig(chaiseConfigFilePath?: string) { } } + if (addDefaultCatalogToChaiseConfig) { + // grab the catalog id + const catId = getCatalogID(PW_PROJECT_NAMES.CHROME); + if (catId === null) { + throw new Error('unable to find catalog id for chrome project while adding defaultCatalog'); + } + + // grab the content of chaise-config file and add the defaultCatalog to it + let content = fs.readFileSync(chaiseFilePath, 'utf8'); + content += `\nchaiseConfig.defaultCatalog = '${catId}'`; + + // write the new content into the temporary location + execSync(`mkdir -p ${UPLOAD_FOLDER}`); + chaiseFilePath = path.resolve(UPLOAD_FOLDER, 'chaise-config.js'); + fs.writeFileSync(chaiseFilePath, content); + } + const remoteChaiseDirPath = process.env.REMOTE_CHAISE_DIR_PATH; // The tests will take this path when it is not running on CI and remoteChaseDirPath is not null diff --git a/test/e2e/specs/delete-prohibited/chaise-config.js b/test/e2e/specs/delete-prohibited/chaise-config.js index 0c57d8a3b..ccd1d69ed 100644 --- a/test/e2e/specs/delete-prohibited/chaise-config.js +++ b/test/e2e/specs/delete-prohibited/chaise-config.js @@ -2,7 +2,6 @@ var chaiseConfig = { name: "Delete Prohibited", - defaultCatalog: 'delete-prohibited-chrome', editRecord: true, deleteRecord: false, showFaceting: true, diff --git a/test/e2e/specs/delete-prohibited/navbar/playwright.config.ts b/test/e2e/specs/delete-prohibited/navbar/playwright.config.ts index 7dbe17c96..741342c1d 100644 --- a/test/e2e/specs/delete-prohibited/navbar/playwright.config.ts +++ b/test/e2e/specs/delete-prohibited/navbar/playwright.config.ts @@ -4,4 +4,5 @@ export default getConfig({ testName: 'delete-prohibited/navbar', configFileName: 'navbar/catalog-chaise-config.dev.json', mainSpecName: 'delete-prohibited', + addDefaultCatalogToChaiseConfig: true }); diff --git a/test/e2e/specs/delete-prohibited/playwright.config.ts b/test/e2e/specs/delete-prohibited/playwright.config.ts index 8e883aa33..cabfe2e7e 100644 --- a/test/e2e/specs/delete-prohibited/playwright.config.ts +++ b/test/e2e/specs/delete-prohibited/playwright.config.ts @@ -4,4 +4,5 @@ export default getConfig({ testName: 'delete-prohibited', configFileName: 'parallel-configs/delete-prohibited.dev.json', mainSpecName: 'delete-prohibited', + addDefaultCatalogToChaiseConfig: true });