| <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" |