Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unnecessary await #942

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/modules/helpers/create-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ const backgroundProcess = (
});

/** Starts a file in a background process (useful for servers, APIs, etc.) */
export const startService = async (
export const startService = (
file: string,
options?: StartServiceOptions
): Promise<{ end: End }> => {
const runtimeOptions = runner(file);
const runtime = runtimeOptions.shift()!;
const runtimeArgs = [...runtimeOptions, file];

return await backgroundProcess(
return backgroundProcess(
runtime,
runtimeArgs,
normalize(sanitizePath(file)),
Expand All @@ -168,7 +168,7 @@ export const startService = async (
*
* By default it uses **npm**, but you can costumize it using the `runner` option.
*/
export const startScript = async (
export const startScript = (
script: string,
options?: StartScriptOptions
): Promise<{ end: End }> => {
Expand All @@ -177,7 +177,7 @@ export const startScript = async (
const runtime = runtimeOptions.shift()!;
const runtimeArgs = [...runtimeOptions, script];

return await backgroundProcess(runtime, runtimeArgs, script, {
return backgroundProcess(runtime, runtimeArgs, script, {
...options,
runner,
});
Expand Down
4 changes: 2 additions & 2 deletions src/modules/helpers/get-pids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ const getPIDsByPorts = async (port: number | number[]): Promise<number[]> => {
return PIDs;
};

const getPIDsByRange = async (
const getPIDsByRange = (
startsAt: number,
endsAt: number
): Promise<number[]> => {
const ports = populateRange(startsAt, endsAt);

return await getPIDs(ports);
return getPIDs(ports);
};

/** Returns an array containing the ID of all processes listening to the specified port */
Expand Down
2 changes: 1 addition & 1 deletion src/modules/helpers/list-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const getAllFiles = async (
return [sanitizePath(dirPath)];
}

return await readdir(sanitizePath(dirPath));
return readdir(sanitizePath(dirPath));
} catch (error) {
console.error(error);
process.exit(1);
Expand Down
21 changes: 8 additions & 13 deletions src/services/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class DockerContainer {
);
}

async start() {
start() {
const args: string[] = ['run'];

args.push(this.detach !== false ? '-d' : '--init');
Expand All @@ -97,16 +97,16 @@ export class DockerContainer {

if (this.envFile) args.push(...['--env-file', this.envFile]);

return await runDockerCommand(
return runDockerCommand(
'docker',
[...args, this.tagName],
{ cwd: this.cwd },
this.verbose
);
}

async stop() {
return await runDockerCommand(
stop() {
return runDockerCommand(
'docker',
['stop', this.containerName],
{ cwd: this.cwd },
Expand Down Expand Up @@ -162,7 +162,7 @@ export class DockerCompose {
this.verbose = verbose;
}

async up() {
up() {
const args: string[] = ['compose', '-f', this.file];

if (this.envFile) args.push(...['--env-file', this.envFile]);
Expand All @@ -174,21 +174,16 @@ export class DockerCompose {
if (this.build) args.push('--build');
if (this.serviceName) args.push(this.serviceName);

return await runDockerCommand(
'docker',
args,
{ cwd: this.cwd },
this.verbose
);
return runDockerCommand('docker', args, { cwd: this.cwd }, this.verbose);
}

async down() {
down() {
const args: string[] = ['-f', this.file];

if (this.envFile) args.push(...['--env-file', this.envFile]);
if (this.projectName) args.push(...['-p', this.projectName]);

return await runDockerCommand(
return runDockerCommand(
'docker',
['compose', ...args, 'down'],
{ cwd: this.cwd },
Expand Down
10 changes: 4 additions & 6 deletions src/services/each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ const eachCore = async (
}
};

export const beforeEach = async (fileRelative: string) => {
if (GLOBAL.configs.beforeEach)
return await eachCore('beforeEach', fileRelative);
export const beforeEach = (fileRelative: string) => {
if (GLOBAL.configs.beforeEach) return eachCore('beforeEach', fileRelative);

return true;
};

export const afterEach = async (fileRelative: string) => {
if (GLOBAL.configs.afterEach)
return await eachCore('afterEach', fileRelative);
export const afterEach = (fileRelative: string) => {
if (GLOBAL.configs.afterEach) return eachCore('afterEach', fileRelative);

return true;
};
2 changes: 1 addition & 1 deletion src/services/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ export const runTests = async (dir: string): Promise<boolean> => {
for (let i = 0; i < concurrency; i++)
isSequential ? await runNext() : runNext();

return await done;
return done;
};
Loading