From ebf52afbe8aa8c10f127e9cd7af63d0ecb56cf40 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Fri, 12 May 2023 09:31:17 +0300 Subject: [PATCH 1/2] added the ability to automatically detect the extension of the currents.config file and to look for the right file --- packages/cypress-cloud/lib/config/config.ts | 24 ++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/cypress-cloud/lib/config/config.ts b/packages/cypress-cloud/lib/config/config.ts index d7aa368b..99966745 100644 --- a/packages/cypress-cloud/lib/config/config.ts +++ b/packages/cypress-cloud/lib/config/config.ts @@ -5,6 +5,7 @@ import { bootCypress } from "../bootstrap"; import { warn } from "../log"; import { require } from "../require"; import { getRandomPort } from "../utils"; +import fs from "fs"; const debug = Debug("currents:config"); @@ -62,10 +63,10 @@ export async function getMergedConfig(params: ValidatedCurrentsParameters) { debug("resolving cypress config"); const cypressResolvedConfig: | (Cypress.ResolvedConfigOptions & { - projectRoot: string; - rawJson: Record; - browsers: DetectedBrowser[]; - }) + projectRoot: string; + rawJson: Record; + browsers: DetectedBrowser[]; + }) | undefined = await bootCypress(getRandomPort(), params); debug("cypress resolvedConfig: %O", cypressResolvedConfig); @@ -95,5 +96,18 @@ export async function getMergedConfig(params: ValidatedCurrentsParameters) { } function getConfigFilePath(projectRoot: string | null = null) { - return [projectRoot ?? process.cwd(), "currents.config.js"]; + const filename = "currents.config"; + const extensions = ["js", "cjs", "ejs", "ts"]; + const filepaths: string[] = []; + + for (let i = 0; i < extensions.length; i++) { + const filepath = filename + "." + extensions[i]; + if (fs.existsSync(projectRoot ?? process.cwd() + filepath)) { + filepaths.push(projectRoot ?? process.cwd(), filepath); + } else { + console.log(filepath, "does not exist."); + } + } + + return filepaths; } From 15ff9c2c8ecdb92a34dff2f401d95aa5915ab0e2 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Thu, 18 May 2023 15:36:39 +0300 Subject: [PATCH 2/2] refactored the code so it's more clean --- packages/cypress-cloud/lib/config/config.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/cypress-cloud/lib/config/config.ts b/packages/cypress-cloud/lib/config/config.ts index 99966745..30974d09 100644 --- a/packages/cypress-cloud/lib/config/config.ts +++ b/packages/cypress-cloud/lib/config/config.ts @@ -100,12 +100,12 @@ function getConfigFilePath(projectRoot: string | null = null) { const extensions = ["js", "cjs", "ejs", "ts"]; const filepaths: string[] = []; - for (let i = 0; i < extensions.length; i++) { - const filepath = filename + "." + extensions[i]; - if (fs.existsSync(projectRoot ?? process.cwd() + filepath)) { - filepaths.push(projectRoot ?? process.cwd(), filepath); + for (const extension of extensions) { + const filepath = path.join(projectRoot ?? process.cwd(), `${filename}.${extension}`); + if (fs.existsSync(filepath)) { + filepaths.push(filepath); } else { - console.log(filepath, "does not exist."); + console.warn(`${filepath} does not exist.`); } }