Skip to content

TestConsole has no warnLines, so a test cannot read Console.warn output #10665

Closed

Description

@usirin

TestConsole (from effect/testing) keeps every console call, Console.warn included. But it only has readers for log and error lines: logLines and errorLines. There is no warnLines, so a test cannot assert on what a program warned.

Checked on 4.1.3, 4.1.4 and main: packages/effect/src/testing/TestConsole.ts has logLines and errorLines only. make already records warn calls through createEntryUnsafe("warn"); they just cannot be read back.

Repro

import { Console, Effect } from "effect"
import { TestConsole } from "effect/testing"

const program = Effect.gen(function*() {
  yield* Console.log("a log line")
  yield* Console.warn("a warn line")
  yield* Console.error("an error line")
  return {
    log: yield* TestConsole.logLines,
    error: yield* TestConsole.errorLines,
    warn: yield* TestConsole.warnLines // type error: Property 'warnLines' does not exist
  }
})

Effect.runSync(program.pipe(Effect.provide(TestConsole.layer)))

In plain JavaScript on effect@4.1.3, the same program with warn: TestConsole.warnLines (not yielded) prints:

{ log: [ 'a log line' ], error: [ 'an error line' ], warn: undefined }

Expected

TestConsole.warnLines (and a warnLines field on the TestConsole interface), built the same way as errorLines, returning ["a warn line"] here.

Proposed change

The same shape as errorLines: filter the kept entries on method === "warn", add the field to the interface and to the object make returns, and add a top-level warnLines accessor through testConsoleWith. We apply this locally with pnpm patch on 4.1.3, and it applies cleanly to the file at the effect@4.1.4 tag.

The patch we apply locally
diff --git a/src/testing/TestConsole.ts b/src/testing/TestConsole.ts
--- a/src/testing/TestConsole.ts
+++ b/src/testing/TestConsole.ts
@@ -79,6 +79,16 @@ export interface TestConsole extends Console.Console {
    * instance.
    */
   readonly errorLines: Effect.Effect<ReadonlyArray<unknown>>
+  /**
+   * Returns an array of all items that have been logged by the program using
+   * `Console.warn` thus far.
+   *
+   * **When to use**
+   *
+   * Use to inspect captured `Console.warn` calls through a `TestConsole`
+   * instance.
+   */
+  readonly warnLines: Effect.Effect<ReadonlyArray<unknown>>
 }
 
 /**
@@ -195,6 +205,8 @@ export const make = Effect.gen(function*() {
     Array.flatMap(entries, (entry) => entry.method === "error" ? entry.parameters : [])
   )
 
+  const warnLines = Effect.sync(() => Array.flatMap(entries, (entry) => entry.method === "warn" ? entry.parameters : []))
+
   return {
     assert: createEntryUnsafe("assert"),
     clear: createEntryUnsafe("clear"),
@@ -216,7 +228,8 @@ export const make = Effect.gen(function*() {
     trace: createEntryUnsafe("trace"),
     warn: createEntryUnsafe("warn"),
     logLines,
-    errorLines
+    errorLines,
+    warnLines
   } as TestConsole
 })
 
@@ -376,3 +389,23 @@ export const logLines: Effect.Effect<ReadonlyArray<unknown>, never, never> = tes
 export const errorLines: Effect.Effect<ReadonlyArray<unknown>, never, never> = testConsoleWith(
   (console) => console.errorLines
 )
+
+/**
+ * Returns an array of all items that have been logged by the program using
+ * `Console.warn` thus far.
+ *
+ * **When to use**
+ *
+ * Use to assert on captured `Console.warn` output from a program provided
+ * with `TestConsole.layer`.
+ *
+ * @see {@link errorLines} for reading captured `Console.error` output
+ * @see {@link layer} for capturing console calls during a test
+ *
+ * @stability unstable
+ * @category testing
+ * @since 4.0.0
+ */
+export const warnLines: Effect.Effect<ReadonlyArray<unknown>, never, never> = testConsoleWith(
+  (console) => console.warnLines
+)

Activity

  1. self-assigned this
    on Nov 16, 2026
  2. usirin commented on Nov 16, 2026

    @usirin
    Author

    The same gap holds for info and debug: on 4.1.3, "warnLines" in TestConsole, "infoLines" in TestConsole and "debugLines" in TestConsole are all false, while make records those calls too. If you would rather fix it once, infoLines and debugLines could be added the same way as warnLines. Our local patch adds only warnLines, the one we needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions