Tests should read telemetry from in-memory exporters (like MyInMemorySpanExporter, introduced in #465) rather than spying on console.dir / cds.test.log() and parsing formatted output. Console spying is brittle (couples tests to exporter formatting), order-sensitive, and — as the jest→vitest migration (#474) showed — sensitive to log-timing windows.
The console-based tests fall into three groups; handle each accordingly.
1. Trace-span tests still spying on console.dir → use MyInMemorySpanExporter
These use the sdk-trace-node console exporter (tracing-console / formerly tracing-attributes profile) and read spans out of the console.dir spy. They should switch to the tracing-in-memory profile and read captured from MyInMemorySpanExporter (as tracing.test.js, tracing-mt.test.js, tracing-scheduled.test.js etc. already do post-#465):
test/tracing-remote-cloudsdk.test.js (getSpans/getCapSpans off console.dir → captured)
test/tracing-remote-native.test.js (same)
test/tracing-span-names.test.js (same)
Once these move off it, the tracing-console profile (@opentelemetry/sdk-trace-node console exporter) in test/bookshop/.cdsrc.json may become unused — remove it if so. (Note: there's a separate deferred task to rename that profile; this supersedes it — it just goes away.)
2. Metric tests spying on console.dir → need an in-memory metric reader
#465 only added an in-memory span exporter; there is no metric equivalent yet. These read metric datapoints (descriptor.name, dataPoints) out of the ConsoleMetricExporter console.dir output:
test/metrics-outbox.test.js
test/metrics-outbox-multitenant.test.js
test/metrics-outbox-disabled.test.js
Add a MyInMemoryMetricReader (companion to MyInMemorySpanExporter, wired via a .cdsrc.json profile) that captures the exported ResourceMetrics in a module-level array, and convert these three tests to assert against it. forceFlush() on the reader replaces the current sleep+scrape pattern.
3. Genuine console-output tests → LEAVE AS-IS
These legitimately assert on what is printed to the console, which is the behavior under test — not a backdoor to spans/metrics. Do NOT convert:
test/metrics.test.js — asserts the ConsoleMetricExporter's host-metrics text output (process/network/nodejs.eventloop.* lines). This is testing the console formatter itself.
test/logging.test.js — asserts the LogRecord objects the logging path emits (body, exception.* attributes). (If a MyInMemoryLogRecordExporter is ever added, revisit; not required here.)
Definition of done
Tests should read telemetry from in-memory exporters (like
MyInMemorySpanExporter, introduced in #465) rather than spying onconsole.dir/cds.test.log()and parsing formatted output. Console spying is brittle (couples tests to exporter formatting), order-sensitive, and — as the jest→vitest migration (#474) showed — sensitive to log-timing windows.The console-based tests fall into three groups; handle each accordingly.
1. Trace-span tests still spying on
console.dir→ useMyInMemorySpanExporterThese use the
sdk-trace-nodeconsole exporter (tracing-console/ formerlytracing-attributesprofile) and read spans out of theconsole.dirspy. They should switch to thetracing-in-memoryprofile and readcapturedfromMyInMemorySpanExporter(astracing.test.js,tracing-mt.test.js,tracing-scheduled.test.jsetc. already do post-#465):test/tracing-remote-cloudsdk.test.js(getSpans/getCapSpansoffconsole.dir→captured)test/tracing-remote-native.test.js(same)test/tracing-span-names.test.js(same)Once these move off it, the
tracing-consoleprofile (@opentelemetry/sdk-trace-nodeconsole exporter) intest/bookshop/.cdsrc.jsonmay become unused — remove it if so. (Note: there's a separate deferred task to rename that profile; this supersedes it — it just goes away.)2. Metric tests spying on
console.dir→ need an in-memory metric reader#465only added an in-memory span exporter; there is no metric equivalent yet. These read metric datapoints (descriptor.name,dataPoints) out of theConsoleMetricExporterconsole.diroutput:test/metrics-outbox.test.jstest/metrics-outbox-multitenant.test.jstest/metrics-outbox-disabled.test.jsAdd a
MyInMemoryMetricReader(companion toMyInMemorySpanExporter, wired via a.cdsrc.jsonprofile) that captures the exportedResourceMetricsin a module-level array, and convert these three tests to assert against it.forceFlush()on the reader replaces the current sleep+scrape pattern.3. Genuine console-output tests → LEAVE AS-IS
These legitimately assert on what is printed to the console, which is the behavior under test — not a backdoor to spans/metrics. Do NOT convert:
test/metrics.test.js— asserts theConsoleMetricExporter's host-metrics text output (process/network/nodejs.eventloop.*lines). This is testing the console formatter itself.test/logging.test.js— asserts theLogRecordobjects the logging path emits (body,exception.*attributes). (If aMyInMemoryLogRecordExporteris ever added, revisit; not required here.)Definition of done
jest.spyOn(console, ...)/console.dir = …/cds.test.log()span-scraping in the tracing tests (group 1).consoleDirLogs.