Skip to content

Commit 82b3f78

Browse files
committed
Introduce describe()
1 parent 4157807 commit 82b3f78

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

packages/cli/src/benchmark/benchmark.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ All workflows with default settings unless otherwise specified.
1818

1919
1.1. using "Respond immediately" mode
2020
1.2. using "When last node finishes" mode
21-
1.3. using "Using 'Respond to Webhook' node" mode
21+
1.3. using 'Respond to Webhook' node mode

packages/cli/src/benchmark/lib/suites.ts

+17-12
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,27 @@ function suiteFilePath() {
5757
return filePath;
5858
}
5959

60-
/**
61-
* Run a benchmarking task, i.e. a single operation whose performance to measure.
62-
*/
63-
export function task(description: string, operation: Task['operation']) {
60+
export function describe(suiteName: string, suiteFn: () => void) {
6461
const filePath = suiteFilePath();
6562

66-
suites[filePath] ||= { hooks: {}, tasks: [] };
67-
suites[filePath].tasks.push({ description, operation });
63+
suites[filePath] = { name: suiteName, hooks: {}, tasks: [] };
64+
65+
suiteFn();
6866
}
6967

68+
export function task(taskName: string, operation: Task['operation']) {
69+
const filePath = suiteFilePath();
70+
71+
suites[filePath].tasks.push({
72+
description: suites[filePath].name + ' ' + taskName,
73+
operation,
74+
});
75+
}
76+
77+
// @TODO: Rename next two utils to dismbiguate?
78+
7079
/**
71-
* Setup step to run once before each benchmarking task in a suite.
72-
* Only one `beforeEach` is allowed per suite.
80+
* Setup step to run once before all iterations of each benchmarking task in a suite.
7381
*/
7482
export function beforeEach(fn: Callback) {
7583
const filePath = suiteFilePath();
@@ -78,13 +86,11 @@ export function beforeEach(fn: Callback) {
7886
throw new DuplicateHookError('beforeEach', filePath);
7987
}
8088

81-
suites[filePath] ||= { hooks: {}, tasks: [] };
8289
suites[filePath].hooks.beforeEach = fn;
8390
}
8491

8592
/**
86-
* Teardown step to run once after each benchmarking task in a suite.
87-
* Only one `afterEach` is allowed per suite.
93+
* Teardown step to run once after all iterations of each benchmarking task in a suite.
8894
*/
8995
export function afterEach(fn: Callback) {
9096
const filePath = suiteFilePath();
@@ -93,6 +99,5 @@ export function afterEach(fn: Callback) {
9399
throw new DuplicateHookError('afterEach', filePath);
94100
}
95101

96-
suites[filePath] ||= { hooks: {}, tasks: [] };
97102
suites[filePath].hooks.afterEach = fn;
98103
}

packages/cli/src/benchmark/lib/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
export type Suites = {
55
[suiteFilepath: string]: {
6+
name: string;
67
hooks: {
78
beforeEach?: Callback;
89
afterEach?: Callback;

packages/cli/src/benchmark/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Bench from 'tinybench';
1111
import { withCodSpeed } from '@codspeed/tinybench-plugin';
1212
/* eslint-enable import/no-extraneous-dependencies */
1313

14-
export { beforeEach, afterEach, task } from './lib/suites';
14+
export { describe, task, beforeEach, afterEach } from './lib/suites';
1515

1616
async function main() {
1717
const dbType = config.getEnv('database.type');
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import axios from 'axios';
2-
import { task } from '../main.js';
2+
import { task, describe } from '../main';
33

4-
const client = axios.create({ baseURL: 'http://localhost:5678/' });
4+
// @TODO: Rename file?
55

6-
task(
7-
'1.1. Production workflow with authless webhook node using "Respond immediately" mode',
8-
async () => {
6+
describe('1. Production workflow with authless webhook node', () => {
7+
const client = axios.create({ baseURL: 'http://localhost:5678/' });
8+
9+
task('(1.1) using "Respond immediately" mode', async () => {
910
await client.get('/webhook/1.1');
10-
},
11-
);
11+
});
1212

13-
task(
14-
'1.2. Production workflow with authless webhook node using "When last node finishes" mode',
15-
async () => {
13+
task('(1.2) using "When last node finishes" mode', async () => {
1614
await client.get('/webhook/1.2');
17-
},
18-
);
15+
});
1916

20-
task(
21-
'1.3. Production workflow with authless webhook node using "Using \'Respond to Webhook\' node" mode',
22-
async () => {
17+
task('(1.3) using "Respond to Webhook" node mode', async () => {
2318
await client.get('/webhook/1.3');
24-
},
25-
);
19+
});
20+
});

0 commit comments

Comments
 (0)