Skip to content

Commit

Permalink
Fix baseUrl from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswinkler committed Oct 29, 2024
1 parent ba82a1f commit ab28d5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/screenshot/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ export function resolveFileExtension(): string {
return fileExtension;
}

export function resolveBaseUrl(args: Partial<C8yScreenshotOptions>): string {
return args.baseUrl ?? process.env.C8Y_BASEURL ?? "http://localhost:8080";
export function resolveBaseUrl(args: Partial<C8yScreenshotOptions>): string | undefined{
return args.baseUrl ?? process.env.C8Y_BASEURL;
}
11 changes: 9 additions & 2 deletions src/screenshot/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import schema from "./../screenshot/schema.json";
import {
createInitConfig,
readYamlFile,
resolveBaseUrl,
resolveConfigOptions,
resolveFileExtension,
} from "./helper";
Expand All @@ -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.`);
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit ab28d5a

Please sign in to comment.