From ab28d5a219dd364952393a366a4734ff9de88385 Mon Sep 17 00:00:00 2001 From: Thomas Winkler Date: Tue, 29 Oct 2024 23:02:34 +0100 Subject: [PATCH] Fix baseUrl from config file --- src/screenshot/helper.ts | 4 ++-- src/screenshot/startup.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/screenshot/helper.ts b/src/screenshot/helper.ts index d21f9ab..889e859 100644 --- a/src/screenshot/helper.ts +++ b/src/screenshot/helper.ts @@ -99,6 +99,6 @@ export function resolveFileExtension(): string { return fileExtension; } -export function resolveBaseUrl(args: Partial): string { - return args.baseUrl ?? process.env.C8Y_BASEURL ?? "http://localhost:8080"; +export function resolveBaseUrl(args: Partial): string | undefined{ + return args.baseUrl ?? process.env.C8Y_BASEURL; } diff --git a/src/screenshot/startup.ts b/src/screenshot/startup.ts index 63625d7..f084b99 100644 --- a/src/screenshot/startup.ts +++ b/src/screenshot/startup.ts @@ -13,6 +13,7 @@ import schema from "./../screenshot/schema.json"; import { createInitConfig, readYamlFile, + resolveBaseUrl, resolveConfigOptions, resolveFileExtension, } from "./helper"; @@ -33,12 +34,16 @@ const log = debug("c8y:scrn:startup"); ); } const resolvedCypressConfig = resolveConfigOptions(args); - const baseUrl = resolvedCypressConfig.config.e2e.baseUrl; + let baseUrl = resolveBaseUrl(args); const yamlFile = path.resolve(process.cwd(), args.config); if (args.init === true) { if (!fs.existsSync(yamlFile)) { - fs.writeFileSync(yamlFile, createInitConfig(baseUrl), "utf8"); + fs.writeFileSync( + yamlFile, + createInitConfig(baseUrl ?? "http://localhost:8080"), + "utf8" + ); log(`Config file ${yamlFile} created.`); } else { throw new Error(`Config file ${yamlFile} already exists.`); @@ -73,6 +78,8 @@ const log = debug("c8y:scrn:startup"); throw new Error(`Invalid config file. ${error.message}`); } + baseUrl = baseUrl ?? configData.baseUrl ?? "http://localhost:8080"; + resolvedCypressConfig.config.e2e.baseUrl = baseUrl; log(`Using baseUrl ${baseUrl}`); const screenshotsFolder =