Skip to content

Commit

Permalink
Add test for internal errors
Browse files Browse the repository at this point in the history
  • Loading branch information
miniBill committed Sep 27, 2024
1 parent fc19db7 commit be3c1fa
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/BackendTask/Custom.elm
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import Date
import FatalError exposing (FatalError)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
import Pages.StaticHttpRequest
import TerminalText
import Time

Expand Down Expand Up @@ -331,7 +332,6 @@ request :
}
-> BackendTask { fatal : FatalError, recoverable : Error } a
request { body, expect } =
-- elm-review: known-unoptimized-recursion
BackendTask.Http.request
{ url = "elm-pages-internal://port"
, method = "GET"
Expand All @@ -343,8 +343,6 @@ request { body, expect } =
expect
|> BackendTask.onError
(\error ->
-- TODO avoid crash here, this should be handled as an internal error
--request params
case error.recoverable of
BackendTask.Http.BadBody (Just jsonError) _ ->
{ recoverable = DecodeError jsonError
Expand All @@ -353,8 +351,5 @@ request { body, expect } =
|> BackendTask.fail

_ ->
{ recoverable = Error
, fatal = error.fatal
}
|> BackendTask.fail
Pages.StaticHttpRequest.InternalError error.fatal
)
4 changes: 4 additions & 0 deletions test-scripts/custom-backend-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export async function environmentVariable(input) {
input.mutable++;
return "Done";
}
58 changes: 58 additions & 0 deletions test-scripts/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"type": "application",
"source-directories": [
"src",
"../src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"avh4/elm-color": "1.0.0",
"danfishgold/base64-bytes": "1.1.0",
"danyx23/elm-mimetype": "4.0.1",
"dillonkearns/elm-bcp47-language-tag": "2.0.0",
"dillonkearns/elm-cli-options-parser": "3.2.0",
"dillonkearns/elm-date-or-date-time": "2.0.0",
"dillonkearns/elm-form": "3.0.0",
"elm/browser": "1.0.2",
"elm/bytes": "1.0.8",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3",
"elm-community/list-extra": "8.6.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"mdgriffith/elm-codegen": "5.0.0",
"miniBill/elm-codec": "2.0.0",
"noahzgordon/elm-color-extra": "1.0.2",
"robinheghan/fnv1a": "1.0.0",
"rtfeldman/elm-css": "18.0.0",
"the-sett/elm-syntax-dsl": "6.0.2",
"vito/elm-ansi": "10.0.1"
},
"indirect": {
"Chadtech/elm-bool-extra": "2.4.2",
"elm/file": "1.0.5",
"elm-community/basics-extra": "4.1.0",
"elm-community/maybe-extra": "5.3.0",
"fredcy/elm-parseint": "2.0.1",
"robinheghan/murmur3": "1.0.0",
"rtfeldman/elm-hex": "1.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.4",
"stil4m/elm-syntax": "7.3.6",
"stil4m/structured-writer": "1.0.3",
"the-sett/elm-pretty-printer": "3.1.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
70 changes: 70 additions & 0 deletions test-scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test-scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"license": "BSD-3-Clause",
"devDependencies": {
"elm-pages": "file:.."
}
}
18 changes: 18 additions & 0 deletions test-scripts/src/Main.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Main exposing (run)

import BackendTask exposing (BackendTask)
import BackendTask.Custom
import FatalError exposing (FatalError)
import Json.Decode
import Json.Encode
import Pages.Script as Script exposing (Script)


run : Script
run =
BackendTask.Custom.run "environmentVariable"
(Json.Encode.object [ ( "mutable", Json.Encode.int 0 ) ])
Json.Decode.string
|> BackendTask.allowFatal
|> BackendTask.andThen Script.log
|> Script.withoutCliOptions
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ npx elm-test-rs --compiler lamdera
npm run test:snapshot
elm-verify-examples --run-tests --elm-test-args '--compiler=lamdera'
(cd generator && vitest run)
(cd test-scripts && npm i && npx elm-pages run src/Main.elm)

0 comments on commit be3c1fa

Please sign in to comment.