Skip to content

Commit

Permalink
feat: improved error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelPanic92 committed Jun 5, 2024
1 parent 03eb16b commit 3f8f775
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 30 deletions.
4 changes: 2 additions & 2 deletions lib/src/runner/kill-concurrently-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
41 changes: 24 additions & 17 deletions lib/src/runner/load-configuration.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -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}).`,
);
};
4 changes: 2 additions & 2 deletions lib/src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/runner/start-web-server-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
export const startWebServerCommands = (
configuration: CypressRunnerConfig,
): (() => Promise<void>) => {
const commands = castArray(configuration.startWebServerCommands).filter(negate(isNil));

if (isEmpty(commands)) {
Expand Down
18 changes: 10 additions & 8 deletions lib/src/runner/wait-web-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { CypressRunnerConfig } from './cypress-runner-config';

export const waitWebServices = async (configuration: CypressRunnerConfig): Promise<void> => {
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}`,
);
}
};

0 comments on commit 3f8f775

Please sign in to comment.