Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Last active July 20, 2026 19:33
Show Gist options
  • Select an option

  • Save Janiczek/af5ec1d387a34175bd0a8ae64ad9c433 to your computer and use it in GitHub Desktop.

Select an option

Save Janiczek/af5ec1d387a34175bd0a8ae64ad9c433 to your computer and use it in GitHub Desktop.
elm-test log capture only for final fuzz test run
<html>
<head>
<script>
const oldConsoleLog = console.log;
let mode = "passthrough";
let capturedTestName = null;
let capturedOutput = {};
console.log = function(x) {
if (x.startsWith('[elm-test-console-log:ignore]: ()')) {
mode = "ignore";
capturedTestName = null;
} else if (x.startsWith('[elm-test-console-log:capture]: "')) {
mode = "capture";
capturedTestName = x.slice(33,-1);
} else if (x.startsWith('[elm-test-console-log:reset]: ()')) {
// This is only for demonstration purposes, wouldn't be in the real elm test runner code
oldConsoleLog({capturedOutput});
// End of throwaway code
mode = "passthrough";
capturedOutput = {};
capturedTestName = null;
} else {
switch (mode) {
case "passthrough":
oldConsoleLog(x);
break;
case "ignore":
// ignore
break;
case "capture":
if (!(capturedTestName in capturedOutput)) {
capturedOutput[capturedTestName] = [];
}
capturedOutput[capturedTestName].push(x);
break;
default:
throw new Exception("Unknown elm-test capture mode: " + mode);
}
}
};
</script>
<script src="elm.js" />
</head>
<body>
<main></main>
<script>
var app = Elm.Main.init({ node: document.querySelector('main') });
</script>
</body>
</html>
module Main exposing (main)
import Browser
import Html
untouchableTestedFn : Int -> ()
untouchableTestedFn n =
let _ = Debug.log "you can't change this string" ( "nor this value", n ) in
()
main =
let _ = Debug.log "this gets shown" () in
let _ = Debug.log "[elm-test-console-log:ignore]" () in
let _ = Debug.log "doesn't get captured" () in
-- imagine we're shrinking
let _ = untouchableTestedFn 5 in
let _ = untouchableTestedFn 3 in
let _ = untouchableTestedFn 1 in
let _ = untouchableTestedFn 2 in
-- finished, found 2
let _ = Debug.log "[elm-test-console-log:capture]" "my test name" in
let _ = untouchableTestedFn 2 in
let _ = Debug.log "[elm-test-console-log:reset]" () in
Html.text "Check browser console"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment