diff --git a/lib/src/runner/kill-concurrently-result.ts b/lib/src/runner/kill-concurrently-result.ts index ce11c0d..ef45efc 100644 --- a/lib/src/runner/kill-concurrently-result.ts +++ b/lib/src/runner/kill-concurrently-result.ts @@ -10,6 +10,6 @@ export const killConcurrentlyResult = async ( command.kill(); console.info(`✅ ${command.name ?? command.command} has been successfully shut down`); }); - - await concurrentlyResult.result; + + await concurrentlyResult.result; }; diff --git a/lib/src/runner/load-configuration.ts b/lib/src/runner/load-configuration.ts index 4ce7654..af61884 100644 --- a/lib/src/runner/load-configuration.ts +++ b/lib/src/runner/load-configuration.ts @@ -1,6 +1,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { register } from 'ts-node'; + import { CypressRunnerConfig } from './cypress-runner-config'; export const loadConfiguration = (): CypressRunnerConfig => { @@ -9,25 +10,31 @@ export const loadConfiguration = (): CypressRunnerConfig => { for (const ext of extensions) { const filePath = path.resolve(process.cwd(), configFileName + ext); - - if (fs.existsSync(filePath)) { - if (ext === '.json' || ext === '') { - return JSON.parse(fs.readFileSync(filePath, 'utf-8')); - } else if (ext === '.js') { - return require(filePath); - } else if (ext === '.ts') { - register({ - transpileOnly: true, - compilerOptions: { - module: 'commonjs' - } - }); - return require(filePath).default; + try { + if (fs.existsSync(filePath)) { + if (ext === '.json' || ext === '') { + return JSON.parse(fs.readFileSync(filePath, 'utf-8')); + } else if (ext === '.js') { + return require(filePath); + } else if (ext === '.ts') { + register({ + transpileOnly: true, + compilerOptions: { + module: 'commonjs', + }, + }); + // eslint-disable-next-line @typescript-eslint/no-var-requires + return require(filePath).default; + } } + } catch (e) { + throw new Error(`failed to load ${filePath}.\n${e}`); } } - throw new Error(`No configuration file found. Please create a ${configFileName} file with the appropriate format (json, js, ts).`); -}; - + const supportedFormats = extensions.map((ext) => configFileName + ext).join(', '); + throw new Error( + `No configuration file found. Please create a ${configFileName} file with the appropriate format (${supportedFormats}).`, + ); +}; diff --git a/lib/src/runner/runner.ts b/lib/src/runner/runner.ts index ea5a5df..afce832 100644 --- a/lib/src/runner/runner.ts +++ b/lib/src/runner/runner.ts @@ -33,8 +33,8 @@ export const cypressRunner = async () => { stdio: 'inherit', env: process.env, }); - } catch { - throw new Error('Ooops! Something went wrong :('); + } catch (e) { + throw new Error(`something went wrong during execution.\n${e}`); } finally { await webServersKiller().catch(() => null); } diff --git a/lib/src/runner/start-web-server-commands.ts b/lib/src/runner/start-web-server-commands.ts index e5efd81..f0edc3d 100644 --- a/lib/src/runner/start-web-server-commands.ts +++ b/lib/src/runner/start-web-server-commands.ts @@ -4,7 +4,9 @@ import { castArray, isEmpty, isNil, negate } from 'lodash'; import { CypressRunnerConfig } from './cypress-runner-config'; import { killConcurrentlyResult } from './kill-concurrently-result'; -export const startWebServerCommands = (configuration: CypressRunnerConfig): () => Promise => { +export const startWebServerCommands = ( + configuration: CypressRunnerConfig, +): (() => Promise) => { const commands = castArray(configuration.startWebServerCommands).filter(negate(isNil)); if (isEmpty(commands)) { diff --git a/lib/src/runner/wait-web-services.ts b/lib/src/runner/wait-web-services.ts index 3b259ce..5049f40 100644 --- a/lib/src/runner/wait-web-services.ts +++ b/lib/src/runner/wait-web-services.ts @@ -5,13 +5,15 @@ import { CypressRunnerConfig } from './cypress-runner-config'; export const waitWebServices = async (configuration: CypressRunnerConfig): Promise => { const waitOnConfigs = configuration.waitOn; - if (!isNil(waitOnConfigs) && !isEmpty(waitOnConfigs?.resources)) { - try { - await waitOn(waitOnConfigs); - } catch { - throw new Error( - 'Timeout: the commands have not yet pulled up all the services expected to start cypress', - ); - } + if (isNil(waitOnConfigs) || isEmpty(waitOnConfigs?.resources)) { + return; + } + + try { + await waitOn(waitOnConfigs); + } catch (e) { + throw new Error( + `The commands have not yet pulled up all the services expected to start cypress.\n${e}`, + ); } };