-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow usage of the Waldo staging environment
- Loading branch information
Showing
12 changed files
with
167 additions
and
108 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { | ||
type ProcessEnvironmentConfiguration, | ||
getProcessEnvironmentConfiguration, | ||
} from './processEnvironment.js'; | ||
import { loadWaldoProfile } from './waldoProfile.js'; | ||
|
||
export type Configuration = ProcessEnvironmentConfiguration; | ||
|
||
export async function loadConfiguration(): Promise<Configuration> { | ||
const envConfig = getProcessEnvironmentConfiguration(); | ||
const profileConfig = await loadWaldoProfile(); | ||
|
||
return { | ||
...envConfig, | ||
token: envConfig.token ?? profileConfig.user_token, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as process from 'process'; | ||
|
||
import type { WaldoEnvironment } from '../types.js'; | ||
import { parseEnvironment } from './waldoEnvironment.js'; | ||
|
||
export type ProcessEnvironmentConfiguration = { | ||
readonly environment: WaldoEnvironment | undefined; | ||
readonly token: string | undefined; | ||
readonly sessionId: string | undefined; | ||
readonly versionId: string | undefined; | ||
readonly showSession: boolean | undefined; | ||
}; | ||
|
||
function parseBoolean(value: string | undefined): boolean | undefined { | ||
if (value === undefined) { | ||
return undefined; | ||
} | ||
|
||
return value === '1' || value.toLowerCase() === 'true'; | ||
} | ||
|
||
export function getProcessEnvironmentConfiguration(): ProcessEnvironmentConfiguration { | ||
const { env } = process; | ||
|
||
return { | ||
environment: parseEnvironment(env.WALDO_ENVIRONMENT), | ||
token: env.WALDO_API_TOKEN ?? env.WALDO_TOKEN ?? process.env.TOKEN, | ||
sessionId: env.WALDO_SESSION_ID ?? env.SESSION_ID, | ||
versionId: env.WALDO_APP_VERSION_ID ?? env.VERSION_ID, | ||
showSession: parseBoolean(env.WALDO_SHOW_SESSION) ?? parseBoolean(env.SHOW_SESSION), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { Options } from '@wdio/types'; | ||
import type { WaldoEnvironment } from '../types.js'; | ||
|
||
export type EnvironmentConnection = { | ||
readonly hostname: NonNullable<Options.Connection['hostname']>; | ||
readonly port: NonNullable<Options.Connection['port']>; | ||
readonly protocol: NonNullable<Options.Connection['protocol']>; | ||
readonly path: NonNullable<Options.Connection['path']>; | ||
}; | ||
|
||
export const DEFAULT_REMOTE_CONFIG: EnvironmentConnection = { | ||
hostname: 'core.waldo.com', | ||
port: 443, | ||
protocol: 'https', | ||
path: '/wd/hub', | ||
}; | ||
|
||
export const STAGING_REMOTE_CONFIG: EnvironmentConnection = { | ||
...DEFAULT_REMOTE_CONFIG, | ||
hostname: 'core-staging.waldo.io', | ||
}; | ||
|
||
export const LOCAL_REMOTE_CONFIG: EnvironmentConnection = { | ||
...DEFAULT_REMOTE_CONFIG, | ||
hostname: 'localhost', | ||
port: 3035, | ||
}; | ||
|
||
export function parseEnvironment(value: string | undefined): WaldoEnvironment | undefined { | ||
switch (value) { | ||
case 'production': | ||
case 'staging': | ||
case 'development': | ||
return value; | ||
default: | ||
return undefined; | ||
} | ||
} | ||
|
||
export function getEnvironmentConnectionOptions( | ||
environment: WaldoEnvironment | undefined, | ||
): EnvironmentConnection { | ||
switch (environment) { | ||
case 'staging': | ||
return STAGING_REMOTE_CONFIG; | ||
case 'development': | ||
return LOCAL_REMOTE_CONFIG; | ||
default: | ||
return DEFAULT_REMOTE_CONFIG; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as fs from 'fs'; | ||
import { homedir } from 'os'; | ||
import { parse as parseYaml } from 'yaml'; | ||
|
||
export type WaldoProfileYaml = { | ||
user_token?: string; | ||
}; | ||
|
||
export async function loadWaldoProfile(): Promise<WaldoProfileYaml> { | ||
const waldoProfileFile = `${homedir()}/.waldo/profile.yml`; | ||
try { | ||
const ymlContent = await fs.promises.readFile(waldoProfileFile, 'utf-8'); | ||
return parseYaml(ymlContent); | ||
} catch (error: any) { | ||
// File not existing is expected - any other error is not | ||
if (error.code !== 'ENOENT') { | ||
throw error; | ||
} | ||
|
||
return {}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { getLocalDevFromEnvironment } from './config.js'; | ||
import { DEFAULT_REMOTE_CONFIG, LOCAL_REMOTE_CONFIG } from './constants.js'; | ||
import { DEFAULT_REMOTE_CONFIG } from './configuration/waldoEnvironment.js'; | ||
|
||
const remoteConfig = getLocalDevFromEnvironment() ? LOCAL_REMOTE_CONFIG : DEFAULT_REMOTE_CONFIG; | ||
|
||
export function getRemoteBaseUrl() { | ||
return `${remoteConfig.protocol}://${remoteConfig.hostname}:${remoteConfig.port}`; | ||
export function getRemoteBaseUrl(browser: WebdriverIO.Browser) { | ||
const protocol = browser.options.protocol ?? 'http'; | ||
const hostname = browser.options.hostname ?? DEFAULT_REMOTE_CONFIG.hostname; | ||
const port = browser.options.port ?? DEFAULT_REMOTE_CONFIG.port; | ||
return `${protocol}://${hostname}:${port}`; | ||
} | ||
|
||
export function getWdUrl(path: string) { | ||
return `${getRemoteBaseUrl()}${remoteConfig.path ?? '/'}${path}`; | ||
export function getWdUrl(browser: WebdriverIO.Browser, path: string) { | ||
return `${getRemoteBaseUrl(browser)}${browser.options.path ?? '/'}${path}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters