Skip to content

Commit

Permalink
chore(deps): bump eslint version
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelPanic92 committed Jan 16, 2025
1 parent 3d15a47 commit bedd61d
Show file tree
Hide file tree
Showing 12 changed files with 8,712 additions and 12,439 deletions.
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

50 changes: 0 additions & 50 deletions .eslintrc.json

This file was deleted.

14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const tseslint = require("typescript-eslint");
const devmy = require("@devmy/eslint-plugin");

module.exports = tseslint.config(
{
files: ["**/*.ts"],
plugins: { "devmy": devmy },
extends: [devmy.configs["recommended"]],
rules: {
'no-console': 'off',
'@typescript-eslint/no-require-imports': 'off',
}
},
);
7 changes: 5 additions & 2 deletions lib/src/runner/banner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import figlet from 'figlet';
import { isNil } from 'lodash';

const figletAsync = (txt: string, options: figlet.Options | undefined) =>
const figletAsync = (
txt: string,
options: figlet.Options | undefined,
): Promise<string | undefined> =>
new Promise((resolve, reject) =>
figlet(txt, options, (error, data) => {
if (isNil(error)) {
Expand All @@ -12,7 +15,7 @@ const figletAsync = (txt: string, options: figlet.Options | undefined) =>
}),
);

export const printBanner = async () => {
export const printBanner = async (): Promise<void> => {
const banner = await figletAsync('Cypress Runner', { font: 'Standard' });

console.log(banner + '\n\n');
Expand Down
2 changes: 1 addition & 1 deletion lib/src/runner/cypress-runner-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { WaitOnOptions } from 'wait-on';

export interface CypressRunnerConfig {
debug?: boolean;
startWebServerCommands: Array<ConcurrentlyCommandInput> | ConcurrentlyCommandInput;
startWebServerCommands: ConcurrentlyCommandInput[] | ConcurrentlyCommandInput;
waitOn?: WaitOnOptions;
}
38 changes: 25 additions & 13 deletions lib/src/runner/load-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,49 @@ import { register } from 'ts-node';

import { CypressRunnerConfig } from './cypress-runner-config';

export const loadConfiguration = (): CypressRunnerConfig => {
const configFileName = '.cypressrunnerrc';
const extensions = ['', '.json', '.js', '.ts'];
const JSON_FILE_EXTENSION = '.json';
const EMPTY_FILE_EXTENSION = '';
const JAVASCRIPT_FILE_EXTENSION = '.js';
const TYSESCRIPT_FILE_EXTENSION = '.ts';
const CYPRESS_RUNNER_CONFIG_FILENAME = '.cypressrunnerrc';

const CYPRESS_RUNNER_SUPPORTED_FILE_EXTENSIONS = [
EMPTY_FILE_EXTENSION,
JSON_FILE_EXTENSION,
JAVASCRIPT_FILE_EXTENSION,
TYSESCRIPT_FILE_EXTENSION,
];

for (const ext of extensions) {
const filePath = path.resolve(process.cwd(), configFileName + ext);
export const loadConfiguration = (): CypressRunnerConfig => {
for (const ext of CYPRESS_RUNNER_SUPPORTED_FILE_EXTENSIONS) {
const filePath = path.resolve(process.cwd(), CYPRESS_RUNNER_CONFIG_FILENAME + ext);
try {
if (fs.existsSync(filePath)) {
if (ext === '.json' || ext === '') {
if (ext === JSON_FILE_EXTENSION || ext === EMPTY_FILE_EXTENSION) {
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
} else if (ext === '.js') {
} else if (ext === JAVASCRIPT_FILE_EXTENSION) {
return require(filePath);
} else if (ext === '.ts') {
} else if (ext === TYSESCRIPT_FILE_EXTENSION) {
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}`);
} catch (error) {
throw new Error(`failed to load ${filePath}.\n${error}`);
}
}

const supportedFormats = extensions.map((ext) => configFileName + ext).join(', ');
const supportedFormats = CYPRESS_RUNNER_SUPPORTED_FILE_EXTENSIONS.map(
(ext) => CYPRESS_RUNNER_CONFIG_FILENAME + ext,
).join(', ');

throw new Error(
`No configuration file found. Please create a ${configFileName} file with the appropriate format (${supportedFormats}).`,
`No configuration file found. Please create a ${CYPRESS_RUNNER_CONFIG_FILENAME} file with the appropriate format (${supportedFormats}).`,
);
};
28 changes: 19 additions & 9 deletions lib/src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,45 @@ import { loadConfiguration } from './load-configuration';
import { startWebServerCommands } from './start-web-server-commands';
import { waitWebServices } from './wait-web-services';

export const cypressRunner = async () => {
const SCRIPT_ARG_START_INDEX = 2;
const JSON_PRETTY_PRINT_INDENT = 2;

export const cypressRunner = async (): Promise<void> => {
await printBanner();

const processArguments = [...process.argv];
processArguments.splice(0, 2);
processArguments.splice(0, SCRIPT_ARG_START_INDEX);

const configuration: CypressRunnerConfig = loadConfiguration();
const isDebug = configuration.debug;

isDebug && console.log('Configuration: ', JSON.stringify(configuration, undefined, 2));

isDebug && console.debug('starting web server commands');
if (isDebug) {
console.log('Configuration: ', JSON.stringify(configuration, void 0, JSON_PRETTY_PRINT_INDENT));
console.debug('starting web server commands');
}

const webServersKiller = startWebServerCommands(configuration);

try {
isDebug && console.debug('waiting on endpoints');
if (isDebug) {
console.debug('waiting on endpoints');
}

await waitWebServices(configuration);

isDebug && console.debug('web server commands ready to tests, running cypress');
if (isDebug) {
console.debug('web server commands ready to tests, running cypress');
}

// this command executes the cypress command using the OS api
// eslint-disable-next-line sonarjs/os-command
execSync(`cypress ${processArguments.join(' ')}`, {
cwd: process.cwd(),
stdio: 'inherit',
env: process.env,
});
} catch (e) {
throw new Error(`something went wrong during execution.\n${e}`);
} catch (error) {
throw new Error(`something went wrong during execution.\n${error}`);
} finally {
await webServersKiller().catch(() => null);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/runner/start-web-server-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const startWebServerCommands = (
cwd: process.cwd(),
});

const killer = () => killConcurrentlyResult(server);
const killer = (): Promise<void> => killConcurrentlyResult(server);

[
`exit`,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/runner/wait-web-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export const waitWebServices = async (configuration: CypressRunnerConfig): Promi

try {
await waitOn(waitOnConfigs);
} catch (e) {
} catch (error) {
throw new Error(
`The commands have not yet pulled up all the services expected to start cypress.\n${e}`,
`The commands have not yet pulled up all the services expected to start cypress.\n${error}`,
);
}
};
Loading

0 comments on commit bedd61d

Please sign in to comment.