MCPcopy Index your code
hub / github.com/code-pushup/cli / group

Method group

packages/utils/src/lib/logger.ts:274–341  ·  view source on GitHub ↗
(
    title: string,
    worker: () => Promise<string | { message: string; result: T }>,
  )

Source from the content-addressed store, hash-verified

272 */
273 // eslint-disable-next-line max-lines-per-function
274 async group<T = undefined>(
275 title: string,
276 worker: () => Promise<string | { message: string; result: T }>,
277 ): Promise<T> {
278 if (this.#groupColor) {
279 throw new Error(
280 'Internal Logger error - nested groups are not supported',
281 );
282 }
283 if (this.#activeSpinner) {
284 throw new Error(
285 'Internal Logger error - creating group in active spinner is not supported',
286 );
287 }
288
289 if (!this.#endsWithBlankLine) {
290 this.newline();
291 }
292
293 this.#groupColor = this.#groupsCount % 2 === 0 ? 'cyan' : 'magenta';
294 this.#groupsCount++;
295
296 const groupMarkers = this.#createGroupMarkers();
297
298 console.log(groupMarkers.start(title));
299
300 const start = performance.now();
301 const result = await settlePromise(worker());
302 const end = performance.now();
303
304 if (result.status === 'fulfilled') {
305 const message =
306 typeof result.value === 'string' ? result.value : result.value.message;
307 console.log(
308 [
309 this.#colorize(this.#groupSymbols.end, this.#groupColor),
310 this.#colorize(message, 'green'),
311 this.#formatDurationSuffix({ start, end }),
312 ].join(' '),
313 );
314 } else {
315 console.log(
316 [
317 this.#colorize(this.#groupSymbols.end, this.#groupColor),
318 this.#colorize(
319 `${stringifyError(result.reason, { oneline: true })}`,
320 'red',
321 ),
322 ].join(' '),
323 );
324 }
325
326 const endMarker = groupMarkers.end();
327 if (endMarker) {
328 console.log(endMarker);
329 }
330 this.#groupColor = undefined;
331 this.newline();

Callers 6

logger-demo.tsFile · 0.80
logger.int.test.tsFile · 0.80
executePluginsFunction · 0.80
yargsCliFunction · 0.80
coreConfigMiddlewareFunction · 0.80

Calls 7

newlineMethod · 0.95
#createGroupMarkersMethod · 0.95
#colorizeMethod · 0.95
#formatDurationSuffixMethod · 0.95
settlePromiseFunction · 0.85
workerFunction · 0.85
stringifyErrorFunction · 0.70

Tested by

no test coverage detected