From 97da1607a74fd7b7e10f4ef359a1648e21d6be59 Mon Sep 17 00:00:00 2001 From: Chemi Atlow Date: Wed, 26 Jul 2023 16:15:24 +0300 Subject: [PATCH] doc: add new reporter events to custom reporter examples Fixes: https://github.com/nodejs/node/issues/48894 PR-URL: https://github.com/nodejs/node/pull/48903 Reviewed-By: Moshe Atlow Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca --- doc/api/test.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/doc/api/test.md b/doc/api/test.md index 8f7f7f4cd4d7dd..00cea0530b9e3b 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -666,6 +666,15 @@ const customReporter = new Transform({ writableObjectMode: true, transform(event, encoding, callback) { switch (event.type) { + case 'test:dequeue': + callback(null, `test ${event.data.name} dequeued`); + break; + case 'test:enqueue': + callback(null, `test ${event.data.name} enqueued`); + break; + case 'test:watch:drained': + callback(null, 'test watch queue drained'); + break; case 'test:start': callback(null, `test ${event.data.name} started`); break; @@ -679,6 +688,8 @@ const customReporter = new Transform({ callback(null, 'test plan'); break; case 'test:diagnostic': + case 'test:stderr': + case 'test:stdout': callback(null, event.data.message); break; case 'test:coverage': { @@ -700,6 +711,15 @@ const customReporter = new Transform({ writableObjectMode: true, transform(event, encoding, callback) { switch (event.type) { + case 'test:dequeue': + callback(null, `test ${event.data.name} dequeued`); + break; + case 'test:enqueue': + callback(null, `test ${event.data.name} enqueued`); + break; + case 'test:watch:drained': + callback(null, 'test watch queue drained'); + break; case 'test:start': callback(null, `test ${event.data.name} started`); break; @@ -713,6 +733,8 @@ const customReporter = new Transform({ callback(null, 'test plan'); break; case 'test:diagnostic': + case 'test:stderr': + case 'test:stdout': callback(null, event.data.message); break; case 'test:coverage': { @@ -733,6 +755,15 @@ Example of a custom reporter using a generator function: export default async function * customReporter(source) { for await (const event of source) { switch (event.type) { + case 'test:dequeue': + yield `test ${event.data.name} dequeued`; + break; + case 'test:enqueue': + yield `test ${event.data.name} enqueued`; + break; + case 'test:watch:drained': + yield 'test watch queue drained'; + break; case 'test:start': yield `test ${event.data.name} started\n`; break; @@ -746,6 +777,8 @@ export default async function * customReporter(source) { yield 'test plan'; break; case 'test:diagnostic': + case 'test:stderr': + case 'test:stdout': yield `${event.data.message}\n`; break; case 'test:coverage': { @@ -762,6 +795,15 @@ export default async function * customReporter(source) { module.exports = async function * customReporter(source) { for await (const event of source) { switch (event.type) { + case 'test:dequeue': + yield `test ${event.data.name} dequeued`; + break; + case 'test:enqueue': + yield `test ${event.data.name} enqueued`; + break; + case 'test:watch:drained': + yield 'test watch queue drained'; + break; case 'test:start': yield `test ${event.data.name} started\n`; break; @@ -775,6 +817,8 @@ module.exports = async function * customReporter(source) { yield 'test plan\n'; break; case 'test:diagnostic': + case 'test:stderr': + case 'test:stdout': yield `${event.data.message}\n`; break; case 'test:coverage': {