Skip to content

Commit 64d7389

Browse files
authored
refactor: simplify types and async methods (#1133)
* refactor: simplify types and async methods * docs: simplify inline docs * docs: simplify inline docs
1 parent 7e1ba35 commit 64d7389

32 files changed

Lines changed: 99 additions & 302 deletions

src/@types/background-process.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
import type { Runner } from './runner.js';
22

33
type BackgroundProcessOptions = {
4-
/**
5-
* - Default: resolves in the first console output
6-
* - String: waits for a specifc string on console output to resolve
7-
* - Number: waits for time in milliseconds to resolve
8-
*
9-
* @default undefined
10-
*/
114
startAfter?: string | number;
12-
/**
13-
* Stops the service for neither success nor failure after:
14-
*
15-
* @default 60000
16-
*/
175
timeout?: number;
18-
/** Shows the output from service */
196
verbose?: boolean;
20-
/**
21-
* Specify a target path to start the process
22-
*
23-
* @default "./"
24-
*/
257
cwd?: string | undefined;
268
};
279

2810
export type StartScriptOptions = {
29-
/** By default, Poku will use `npm`. Change it as you want */
3011
readonly runner?: Runner;
3112
} & BackgroundProcessOptions;
3213

src/@types/list-files.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
export type Configs = {
2-
/**
3-
* Filter by path to match only the files that should be performed.
4-
*
5-
* @default /\.(test|spec)\./i
6-
*/
2+
/** @default /\.(test|spec)\./i */
73
filter?: RegExp;
8-
/**
9-
* Exclude by path to match only the files that should be performed.
10-
*
11-
* @default undefined
12-
*/
134
exclude?: RegExp | RegExp[];
145
};

src/@types/plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export type PluginContext = {
2121
};
2222

2323
export type PokuPlugin = {
24-
/** Plugin name */
2524
name?: string;
2625
/** Modify the command array before spawning a test file process */
2726
runner?: (command: string[], file: string) => string[];

src/@types/poku.ts

Lines changed: 8 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -28,103 +28,27 @@ export type Reporter =
2828
| CustomString;
2929

3030
export type Configs = {
31-
/**
32-
* By setting `true`, **Poku** won't exit the process and will return the exit code (`0` or `1`)
33-
*
34-
* @default false
35-
*/
3631
noExit?: boolean;
37-
/**
38-
* This option overwrites all `log` settings
39-
*
40-
* @default false
41-
*/
4232
debug?: boolean;
43-
/**
44-
* This option overwrites the `debug` settings
45-
*
46-
* @default false
47-
*/
4833
quiet?: boolean;
49-
/**
50-
* Determines the mode of test execution
51-
*
52-
* @default false
53-
*/
5434
sequential?: boolean;
55-
/**
56-
* Controls process isolation for test files
57-
*
58-
* - `'process'` (default): each test file runs in a separate child process
59-
* - `'none'`: all test files run in the same process (useful for debugging with `--inspect`)
60-
*
61-
* @default 'process'
62-
*/
6335
isolation?: 'none' | 'process' | CustomString;
64-
/**
65-
* Stops the tests at the first failure.
66-
*
67-
* @default false
68-
*/
6936
failFast?: boolean;
70-
/**
71-
* Limits the number of tests running concurrently
72-
*
73-
* @default (availableParallelism() || cpus().lenght)
74-
*/
37+
/** @default (availableParallelism() || cpus().lenght) */
7538
concurrency?: number;
76-
/**
77-
* Sets the maximum time in milliseconds that each test file is allowed to run
78-
*
79-
* @default undefined
80-
*/
39+
/** Sets the maximum time in milliseconds that each test file is allowed to run */
8140
timeout?: number;
82-
/**
83-
* @default "poku"
84-
*/
41+
/** @default "poku" */
8542
reporter?: Reporter;
86-
/**
87-
* You can use this option to run a **callback** or a **file** before each test file on your suite
88-
*
89-
* ```ts
90-
* beforeEach(() => myFunc())
91-
* ```
92-
*
93-
* ```ts
94-
* beforeEach(async () => await myAsyncFunc())
95-
* ```
96-
*/
43+
/** Runs a callback or a file before each test file on your suite */
9744
beforeEach?: () => unknown | Promise<unknown>;
98-
/**
99-
* You can use this option to run a **callback** or a **file** after each test file on your suite
100-
*
101-
* ```ts
102-
* afterEach(() => myFunc())
103-
* ```
104-
*
105-
* ```ts
106-
* afterEach(async () => await myAsyncFunc())
107-
* ```
108-
*/
45+
/** Runs a callback or a file after each test file on your suite */
10946
afterEach?: () => unknown | Promise<unknown>;
11047
deno?: DenoOptions;
111-
/**
112-
* Plugins to extend Poku's behavior
113-
*
114-
* @default undefined
115-
*/
11648
plugins?: PokuPlugin[];
117-
/**
118-
* Only run tests whose title matches the given regex pattern
119-
*
120-
* @default undefined
121-
*/
49+
/** Only run tests whose title matches the given regex pattern */
12250
testNamePattern?: RegExp;
123-
/**
124-
* Skip tests whose title matches the given regex pattern
125-
*
126-
* @default undefined
127-
*/
51+
/** Skip tests whose title matches the given regex pattern */
12852
testSkipPattern?: RegExp;
12953
} & ListFilesConfigs;
13054

@@ -139,17 +63,12 @@ export type States = {
13963
};
14064

14165
type CliConfigs = {
142-
/** Default: searches for _`.test.`_ and `.spec.` files, but you can customize it */
14366
include?: string | string[];
144-
/** Reads an environment file and sets the environment variables */
14567
envFile?: string;
146-
/** Terminates the specified ports, port ranges and process IDs */
68+
/** Kills the specified ports, port ranges and process IDs */
14769
kill?: {
148-
/** Terminates the specified ports before running the test suite */
14970
port?: [number];
150-
/** Terminates the specified port range before running the test suite */
15171
range?: [number, number][];
152-
/** Terminates the specified processes before running the test suite */
15372
pid?: [number];
15473
};
15574
};

src/@types/wait-for.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,14 @@
11
export type WaitForExpectedResultOptions = {
2-
/**
3-
* Retry interval in milliseconds
4-
*
5-
* @default 100
6-
*/
2+
/** @default 100 */
73
interval?: number;
8-
/**
9-
* Timeout in milliseconds
10-
*
11-
* @default 60000
12-
*/
4+
/** @default 60000 */
135
timeout?: number;
14-
/**
15-
* Delays both the start and end by the defined milliseconds
16-
*
17-
* @default 0
18-
*/
196
delay?: number;
20-
/**
21-
* Ensure strict comparisons
22-
*
23-
* - For **Bun** users, this option isn't necessary
24-
*
25-
* @default false
26-
*/
7+
/** Ensure strict comparisons */
278
strict?: boolean;
289
};
2910

3011
export type WaitForPortOptions = {
31-
/**
32-
* Host to check the port on
33-
*
34-
* @default "localhost"
35-
*/
12+
/** @default "localhost" */
3613
host?: string;
3714
} & Omit<WaitForExpectedResultOptions, 'strict'>;

src/bin/help.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ${bullet} ${b('Poku')} is made with ${b('love')} and ${b('care')} in every detai
8888
${bullet} Give him a ${b('star')} to show your support 🌟
8989
`;
9090

91-
export const help = (): void => {
91+
export const help = () => {
9292
hr();
9393
log(header.trim());
9494
hr();

src/bin/watch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ export const startWatch = async (dirs: string[]) => {
1919
const executing = new Set<string>();
2020
const interval = Number(getArg('watchInterval')) || 1500;
2121

22-
const addWatcher = (pending: Promise<Watcher>): void => {
22+
const addWatcher = (pending: Promise<Watcher>) => {
2323
pending.then((watcher) => {
2424
watchers.add(watcher);
2525
});
2626
};
2727

28-
const resultsClear = (): void => {
28+
const resultsClear = () => {
2929
errors.length = 0;
3030
results.passed = 0;
3131
results.failed = 0;
3232
results.skipped = 0;
3333
results.todo = 0;
3434
};
3535

36-
const listenStdin = async (input: Buffer | string): Promise<void> => {
36+
const listenStdin = async (input: Buffer | string) => {
3737
if (isRunning || executing.size > 0) return;
3838

3939
if (String(input).trim() === 'rs') {

src/builders/assert.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const createAssert = (nodeAssert: typeof assert) => {
8383
block: () => unknown,
8484
errorOrMessage?: AssertPredicate | AssertionMessage,
8585
message?: AssertionMessage
86-
): void => {
86+
) => {
8787
processAssert(
8888
() => {
8989
if (isPredicate(errorOrMessage))
@@ -107,7 +107,7 @@ export const createAssert = (nodeAssert: typeof assert) => {
107107
block: () => unknown,
108108
errorOrMessage?: AssertPredicate | AssertionMessage,
109109
message?: AssertionMessage
110-
): void => {
110+
) => {
111111
if (isPredicate(errorOrMessage))
112112
processAssert(() => nodeAssert.throws(block, errorOrMessage), {
113113
message,
@@ -130,7 +130,7 @@ export const createAssert = (nodeAssert: typeof assert) => {
130130
block: AsyncBlock,
131131
errorOrMessage?: AssertPredicate | AssertionMessage,
132132
message?: AssertionMessage
133-
): Promise<void> => {
133+
) => {
134134
await processAsyncAssert(
135135
async () => {
136136
if (isPredicate(errorOrMessage))
@@ -154,7 +154,7 @@ export const createAssert = (nodeAssert: typeof assert) => {
154154
block: AsyncBlock,
155155
errorOrMessage?: AssertPredicate | AssertionMessage,
156156
message?: AssertionMessage
157-
): Promise<void> => {
157+
) => {
158158
await processAsyncAssert(
159159
async () => {
160160
if (isPredicate(errorOrMessage))

src/modules/essentials/poku.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { runTests } from '../../services/run-tests.js';
1010
import { exit } from '../helpers/exit.js';
1111
import { listFiles } from '../helpers/list-files.js';
1212

13-
export const onSigint = (): void => {
13+
export const onSigint = () => {
1414
stdout.write('\u001B[?25h');
1515
};
1616

src/modules/helpers/create-service.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const backgroundProcess = (
7474

7575
runningProcesses.set(PID, end);
7676

77-
const onData = (data: Buffer): void => {
77+
const onData = (data: Buffer) => {
7878
if (!isResolved && typeof options?.startAfter !== 'number') {
7979
if (
8080
typeof options?.startAfter === 'undefined' ||
@@ -122,7 +122,7 @@ const backgroundProcess = (
122122
} catch {}
123123
});
124124

125-
/** Starts a file in a background process (useful for servers, APIs, etc.) */
125+
/** Starts a file in a background process */
126126
export const startService = (
127127
file: string,
128128
options?: StartServiceOptions
@@ -139,14 +139,7 @@ export const startService = (
139139
);
140140
};
141141

142-
/**
143-
*
144-
* Starts a script (package.json) or task (deno.json) in a background process (useful for servers, APIs, etc.).
145-
*
146-
* ---
147-
*
148-
* By default it uses **npm**, but you can costumize it using the `runner` option.
149-
*/
142+
/** Starts a script in a background process */
150143
export const startScript = (
151144
script: string,
152145
options?: StartScriptOptions

0 commit comments

Comments
 (0)