diff --git a/deno.lock b/deno.lock index 1e5899e..6c3a6d4 100644 --- a/deno.lock +++ b/deno.lock @@ -1,102 +1,72 @@ { "version": "3", + "packages": { + "specifiers": { + "jsr:@std/assert@1.0.0": "jsr:@std/assert@1.0.0", + "jsr:@std/assert@1.0.0-rc.2": "jsr:@std/assert@1.0.0-rc.2", + "jsr:@std/expect@0.224.5": "jsr:@std/expect@0.224.5", + "jsr:@std/internal@^1.0.0": "jsr:@std/internal@1.0.1", + "jsr:@std/internal@^1.0.1": "jsr:@std/internal@1.0.1", + "jsr:@std/media-types@1.0.1": "jsr:@std/media-types@1.0.1", + "npm:graphql-http@1.22.0": "npm:graphql-http@1.22.0_graphql@16.8.1", + "npm:graphql@16.8.1": "npm:graphql@16.8.1" + }, + "jsr": { + "@std/assert@1.0.0": { + "integrity": "0e4f6d873f7f35e2a1e6194ceee39686c996b9e5d134948e644d35d4c4df2008", + "dependencies": [ + "jsr:@std/internal@^1.0.1" + ] + }, + "@std/assert@1.0.0-rc.2": { + "integrity": "0484eab1d76b55fca1c3beaff485a274e67dd3b9f065edcbe70030dfc0b964d3", + "dependencies": [ + "jsr:@std/internal@^1.0.0" + ] + }, + "@std/expect@0.224.5": { + "integrity": "ae6e57ee6f23a2fd5ae130cb84448eef182354cb902e1a2a98d64c72ac3a5a1c", + "dependencies": [ + "jsr:@std/assert@1.0.0-rc.2", + "jsr:@std/internal@^1.0.0" + ] + }, + "@std/internal@1.0.1": { + "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6" + }, + "@std/media-types@1.0.1": { + "integrity": "f2ddc3497be0bd87ac0c9b9b26bb454f76bdc45e1b9a12146af47fab3ba2828c" + } + }, + "npm": { + "graphql-http@1.22.0_graphql@16.8.1": { + "integrity": "sha512-9RBUlGJWBFqz9LwfpmAbjJL/8j/HCNkZwPBU5+Bfmwez+1Ay43DocMNQYpIWsWqH0Ftv6PTNAh2aRnnMCBJgLw==", + "dependencies": { + "graphql": "graphql@16.8.1" + } + }, + "graphql@16.8.1": { + "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", + "dependencies": {} + } + } + }, "remote": { - "https://deno.land/std@0.106.0/fmt/colors.ts": "d2f8355f00a74404668fc5a1e4a92983ce1a9b0a6ac1d40efbd681cb8f519586", - "https://deno.land/std@0.182.0/fmt/colors.ts": "d67e3cd9f472535241a8e410d33423980bec45047e343577554d3356e1f0ef4e", - "https://deno.land/std@0.182.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", - "https://deno.land/std@0.182.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", - "https://deno.land/std@0.182.0/testing/asserts.ts": "e16d98b4d73ffc4ed498d717307a12500ae4f2cbe668f1a215632d19fcffc22f", - "https://deno.land/std@0.197.0/_util/diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", - "https://deno.land/std@0.197.0/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9", - "https://deno.land/std@0.197.0/assert/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", - "https://deno.land/std@0.197.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", - "https://deno.land/std@0.197.0/assert/assert_almost_equals.ts": "e15ca1f34d0d5e0afae63b3f5d975cbd18335a132e42b0c747d282f62ad2cd6c", - "https://deno.land/std@0.197.0/assert/assert_array_includes.ts": "6856d7f2c3544bc6e62fb4646dfefa3d1df5ff14744d1bca19f0cbaf3b0d66c9", - "https://deno.land/std@0.197.0/assert/assert_equals.ts": "a0ee60574e437bcab2dcb79af9d48dc88845f8fd559468d9c21b15fd638ef943", - "https://deno.land/std@0.197.0/assert/assert_exists.ts": "407cb6b9fb23a835cd8d5ad804e2e2edbbbf3870e322d53f79e1c7a512e2efd7", - "https://deno.land/std@0.197.0/assert/assert_false.ts": "a9962749f4bf5844e3fa494257f1de73d69e4fe0e82c34d0099287552163a2dc", - "https://deno.land/std@0.197.0/assert/assert_instance_of.ts": "09fd297352a5b5bbb16da2b5e1a0d8c6c44da5447772648622dcc7df7af1ddb8", - "https://deno.land/std@0.197.0/assert/assert_is_error.ts": "b4eae4e5d182272efc172bf28e2e30b86bb1650cd88aea059e5d2586d4160fb9", - "https://deno.land/std@0.197.0/assert/assert_match.ts": "c4083f80600bc190309903c95e397a7c9257ff8b5ae5c7ef91e834704e672e9b", - "https://deno.land/std@0.197.0/assert/assert_not_equals.ts": "9f1acab95bd1f5fc9a1b17b8027d894509a745d91bac1718fdab51dc76831754", - "https://deno.land/std@0.197.0/assert/assert_not_instance_of.ts": "0c14d3dfd9ab7a5276ed8ed0b18c703d79a3d106102077ec437bfe7ed912bd22", - "https://deno.land/std@0.197.0/assert/assert_not_match.ts": "3796a5b0c57a1ce6c1c57883dd4286be13a26f715ea662318ab43a8491a13ab0", - "https://deno.land/std@0.197.0/assert/assert_not_strict_equals.ts": "ca6c6d645e95fbc873d25320efeb8c4c6089a9a5e09f92d7c1c4b6e935c2a6ad", - "https://deno.land/std@0.197.0/assert/assert_object_match.ts": "27439c4f41dce099317566144299468ca822f556f1cc697f4dc8ed61fe9fee4c", - "https://deno.land/std@0.197.0/assert/assert_rejects.ts": "45c59724de2701e3b1f67c391d6c71c392363635aad3f68a1b3408f9efca0057", - "https://deno.land/std@0.197.0/assert/assert_strict_equals.ts": "5cf29b38b3f8dece95287325723272aa04e04dbf158d886d662fa594fddc9ed3", - "https://deno.land/std@0.197.0/assert/assert_string_includes.ts": "b821d39ebf5cb0200a348863c86d8c4c4b398e02012ce74ad15666fc4b631b0c", - "https://deno.land/std@0.197.0/assert/assert_throws.ts": "63784e951475cb7bdfd59878cd25a0931e18f6dc32a6077c454b2cd94f4f4bcd", - "https://deno.land/std@0.197.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", - "https://deno.land/std@0.197.0/assert/equal.ts": "9f1a46d5993966d2596c44e5858eec821859b45f783a5ee2f7a695dfc12d8ece", - "https://deno.land/std@0.197.0/assert/fail.ts": "c36353d7ae6e1f7933d45f8ea51e358c8c4b67d7e7502028598fe1fea062e278", - "https://deno.land/std@0.197.0/assert/mod.ts": "08d55a652c22c5da0215054b21085cec25a5da47ce4a6f9de7d9ad36df35bdee", - "https://deno.land/std@0.197.0/assert/unimplemented.ts": "d56fbeecb1f108331a380f72e3e010a1f161baa6956fd0f7cf3e095ae1a4c75a", - "https://deno.land/std@0.197.0/assert/unreachable.ts": "4600dc0baf7d9c15a7f7d234f00c23bca8f3eba8b140286aaca7aa998cf9a536", - "https://deno.land/std@0.197.0/fmt/colors.ts": "a7eecffdf3d1d54db890723b303847b6e0a1ab4b528ba6958b8f2e754cf1b3bc", - "https://deno.land/std@0.197.0/testing/asserts.ts": "b4e4b1359393aeff09e853e27901a982c685cb630df30426ed75496961931946", - "https://deno.land/std@0.210.0/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9", - "https://deno.land/std@0.210.0/assert/_diff.ts": "2c9371f17cf08cbb843c924bc31ca77af422ec4fe162f73d42c651d547573fa8", - "https://deno.land/std@0.210.0/assert/_format.ts": "335ce8e15c65b679ad142dbc9e5e97e5d58602c39dd3c9175cef6c85fe22d6d5", - "https://deno.land/std@0.210.0/assert/assert_equals.ts": "991b0c2b437a015d623654f758e48bfd931068211a52e8131b397cdf005c595f", - "https://deno.land/std@0.210.0/assert/assert_false.ts": "99cf237fe374cabf57072d2fb41b3eaff389029f850fbb96f643c875792f10ce", - "https://deno.land/std@0.210.0/assert/assert_instance_of.ts": "7c093d36b1a86666d5a60a8c290c91a51a627153b821a5a4dc40b24cab69f1e7", - "https://deno.land/std@0.210.0/assert/assert_is_error.ts": "a8a758581661edec514c453910bee2f9c91b1346a515c58404963b130d81cd80", - "https://deno.land/std@0.210.0/assert/assert_match.ts": "e541a9769cf5726312ff9e15031e2faa2df3c59fbdc5573c8758b1f4668ccc62", - "https://deno.land/std@0.210.0/assert/assert_not_equals.ts": "6bce4b28f3316029c0aef107f8390796798835c382d31c1004160baef0b80db0", - "https://deno.land/std@0.210.0/assert/assert_not_instance_of.ts": "866243fd28bc6665e2ffcc027a9df1d2a69cb644aef1e9b8d1ce34377c6b8a84", - "https://deno.land/std@0.210.0/assert/assert_not_match.ts": "59707eceb0d2b16d6892fbf92ec86f92fd76fcfc55f8b61508299db7d2972cab", - "https://deno.land/std@0.210.0/assert/assert_not_strict_equals.ts": "c84b8e229450e8dfc44b9910d602788313ff7333d67d5bd8528371567b6a3632", - "https://deno.land/std@0.210.0/assert/assert_object_match.ts": "ebeff248d48e5810f787e8742ae4f6b39904f4640edc2f69796596ceb6dbcdf8", - "https://deno.land/std@0.210.0/assert/assert_strict_equals.ts": "4007dabef1c2e9d6f1bb0e948ba7ba99ec9b1bee97ba34d67f7c10e7e5d794f7", - "https://deno.land/std@0.210.0/assert/assertion_error.ts": "26ed1863d905005f00785c89750c001c3522c5417e4f58f95044b8143cfc1593", - "https://deno.land/std@0.210.0/assert/equal.ts": "6f81c8a3b12c08bdc3510c8a1293b4db1c083692219d7e3828d2234b448d3d3d", - "https://deno.land/std@0.210.0/expect/_format.ts": "872f1c3542df2dc85dbb89f65ffd34c38c6c01267f86324a9509fb79526c0e66", - "https://deno.land/std@0.210.0/expect/_inspect_args.ts": "0225bbc87c64899e5a72dcd4f54ca79ab1e8bd2c3934be2ec78be987cdaf7287", - "https://deno.land/std@0.210.0/expect/_matchers.ts": "2b3c17830c85a66b6d9d977717454d36375eef3fa7145ef44c6b0dc175b91026", - "https://deno.land/std@0.210.0/expect/_mock_util.ts": "af1127940f8f5243d3d0352a6552447f864ce948c3654b86590ec4aae7c4f8e6", - "https://deno.land/std@0.210.0/expect/_types.ts": "29e7de1c6bd4fbee6f58b5b812d9f95e60c7d3cb99c78617c9212870721fe9c9", - "https://deno.land/std@0.210.0/expect/expect.ts": "e9395770b4abe77e0351564cd26bd9988f19a0c26b03d5d22c4701d15dff3fa3", - "https://deno.land/std@0.210.0/expect/fn.ts": "4fb4b54df34a50ed3c638fd48ee6b5aab3d6e7b3d850631d8f7744f38a9cc620", - "https://deno.land/std@0.210.0/expect/mod.ts": "e963871d002da3d9eddceb01068d93d956bd477292537c4e58dbaf189880455b", - "https://deno.land/std@0.210.0/fmt/colors.ts": "2685c524bef9b16b3059a417daf6860c754eb755e19e812762ef5dff62f24481", - "https://deno.land/std@0.210.0/testing/_test_suite.ts": "30f018feeb3835f12ab198d8a518f9089b1bcb2e8c838a8b615ab10d5005465c", - "https://deno.land/std@0.210.0/testing/bdd.ts": "c41f019786c4a9112aadb7e5a7bbcc711f58429ac5904b3855fa248ba5fa0ba6", - "https://deno.land/std@0.97.0/fmt/colors.ts": "db22b314a2ae9430ae7460ce005e0a7130e23ae1c999157e3bb77cf55800f7e4", - "https://deno.land/std@0.97.0/testing/_diff.ts": "961eaf6d9f5b0a8556c9d835bbc6fa74f5addd7d3b02728ba7936ff93364f7a3", - "https://deno.land/std@0.97.0/testing/asserts.ts": "341292d12eebc44be4c3c2ca101ba8b6b5859cef2fa69d50c217f9d0bfbcfd1f", - "https://deno.land/x/expect@v0.2.9/expect.ts": "128c60f94ff3f977e2a649463238e403f9bdb8e6ab77e65214c0236bd61b0111", - "https://deno.land/x/expect@v0.2.9/matchers.ts": "ba7360b73c5031a22449fa98eb4d5dbe7f256a88dd4c22ccae96dc6c01f0b19c", - "https://deno.land/x/expect@v0.2.9/mock.ts": "562d4b1d735d15b0b8e935f342679096b64fe452f86e96714fe8616c0c884914", - "https://deno.land/x/expect@v0.2.9/mod.ts": "0304d2430e1e96ba669a8495e24ba606dcc3d152e1f81aaa8da898cea24e36c2", - "https://deno.land/x/expect@v0.3.0/expect.ts": "5e6717eddc9df376f7b2c9be6403e016130bb2edbb1acd261a2d6ea9608ee196", - "https://deno.land/x/expect@v0.3.0/matchers.ts": "a37ef4577739247af77a852cdcd69484f999a41ad86ec16bb63a88a7a47a2372", - "https://deno.land/x/expect@v0.3.0/mock.ts": "562d4b1d735d15b0b8e935f342679096b64fe452f86e96714fe8616c0c884914", - "https://deno.land/x/expect@v0.3.0/mod.ts": "0304d2430e1e96ba669a8495e24ba606dcc3d152e1f81aaa8da898cea24e36c2", - "https://deno.land/x/expect@v0.4.0/expect.ts": "1d1856758a750f440d0b65d74f19e5d4829bb76d8e576d05546abd8e7b1dfb9e", - "https://deno.land/x/expect@v0.4.0/matchers.ts": "55acf74a3c4a308d079798930f05ab11da2080ec7acd53517193ca90d1296bf7", - "https://deno.land/x/expect@v0.4.0/mock.ts": "562d4b1d735d15b0b8e935f342679096b64fe452f86e96714fe8616c0c884914", - "https://deno.land/x/expect@v0.4.0/mod.ts": "0304d2430e1e96ba669a8495e24ba606dcc3d152e1f81aaa8da898cea24e36c2", - "https://deno.land/x/free_port@v1.2.0/mod.ts": "512646732aaea41fbfd1f210f3ae82660f38251777d189d290da331d0235a58e", - "https://deno.land/x/tincan@1.0.1/mod.ts": "9473507398048cb24dbb37b3a220777106c69c28d573898648deb2bb84a7e131", - "https://deno.land/x/tincan@1.0.1/src/deps.ts": "b02ae57b7ab5035b903f2526b278c26a301e05242668a77eb9e2e82011b651aa", - "https://deno.land/x/tincan@1.0.1/src/environment.ts": "1096dc35b77ee070bba03584489f71c446574d3a7676936ab0bb4aed507d7e27", - "https://deno.land/x/tincan@1.0.1/src/mod.ts": "faf52271dbf61ff40b29d60e1d4f8d80f4ad167beebc40905d16779617d07463", - "https://deno.land/x/tincan@1.0.1/src/nodes/mod.ts": "c22f058dd205d10c3b261c9afdbcd95a8eb807401e822f9c899cca2ab0f16473", - "https://deno.land/x/tincan@1.0.1/src/nodes/nodes.ts": "a8b8b3178868c8b13a6d4d0c96cb41e4c1df48719a8cd2977495af9f9352ab04", - "https://deno.land/x/tincan@1.0.1/src/nodes/tree.ts": "c119fb6a2ee1fe9833b70111382cc8d9a3f5b875b4bb65a0e8774d919193faa3", - "https://deno.land/x/tincan@1.0.1/src/nodes/utilities.ts": "5e6a6f0e2650df4e10f7dfde889ef88a588fe9c3b3618aca2acd47e80b3ee3d8", - "https://deno.land/x/tincan@1.0.1/src/reporter.ts": "84e09297da18c840076be951c02c749678b75dc89b2575f34db1378cbb509939", - "https://deno.land/x/tincan@1.0.1/src/runner.ts": "54e1a0934a52469437bd4655df51f0c9148327d94a2b0d6c175f6f992a697b86", - "https://deno.land/x/tincan@1.0.2/mod.ts": "9473507398048cb24dbb37b3a220777106c69c28d573898648deb2bb84a7e131", - "https://deno.land/x/tincan@1.0.2/src/deps.ts": "cd4b02330db12f33c208706fc90626320152d9ea45f8370a135d69dd94818c49", - "https://deno.land/x/tincan@1.0.2/src/environment.ts": "1096dc35b77ee070bba03584489f71c446574d3a7676936ab0bb4aed507d7e27", - "https://deno.land/x/tincan@1.0.2/src/mod.ts": "a105a5d14ec3d40f1b240517eaa92eeeec1c70be331a12877d6bea25c07e3bd7", - "https://deno.land/x/tincan@1.0.2/src/nodes/mod.ts": "c22f058dd205d10c3b261c9afdbcd95a8eb807401e822f9c899cca2ab0f16473", - "https://deno.land/x/tincan@1.0.2/src/nodes/nodes.ts": "a8b8b3178868c8b13a6d4d0c96cb41e4c1df48719a8cd2977495af9f9352ab04", - "https://deno.land/x/tincan@1.0.2/src/nodes/tree.ts": "c119fb6a2ee1fe9833b70111382cc8d9a3f5b875b4bb65a0e8774d919193faa3", - "https://deno.land/x/tincan@1.0.2/src/nodes/utilities.ts": "5e6a6f0e2650df4e10f7dfde889ef88a588fe9c3b3618aca2acd47e80b3ee3d8", - "https://deno.land/x/tincan@1.0.2/src/reporter.ts": "84e09297da18c840076be951c02c749678b75dc89b2575f34db1378cbb509939", - "https://deno.land/x/tincan@1.0.2/src/runner.ts": "54e1a0934a52469437bd4655df51f0c9148327d94a2b0d6c175f6f992a697b86" + "https://deno.land/std@0.221.0/http/_negotiation/common.ts": "051a9f6edd1ed69507df89bbc16fc1b13b7654b9b8fd38072ec33ae4c185fc13", + "https://deno.land/std@0.221.0/http/_negotiation/encoding.ts": "fdedea1145c1dea3b3de2d5217e8eb927e764083eebc8c52d09a1ed3d9bb7a93", + "https://deno.land/std@0.221.0/http/_negotiation/language.ts": "300a5c586f844c97f246ab72c948e9fde9a8f45e92ec08e1cc9a9df80259e2a3", + "https://deno.land/std@0.221.0/http/_negotiation/media_type.ts": "87a1ecb22c1b268d0fa23d798e1ea238343505268cb1ff82bd038638de29ce31", + "https://deno.land/std@0.221.0/http/negotiation.ts": "d06ef2958ca712a7dbe4538eed6a46abfa2b87f8e150b7c89d83a6055dabd7cc", + "https://deno.land/std@0.221.0/http/status.ts": "ed61b4882af2514a81aefd3245e8df4c47b9a8e54929a903577643d2d1ebf514", + "https://deno.land/std@0.224.0/testing/_test_suite.ts": "f10a8a6338b60c403f07a76f3f46bdc9f1e1a820c0a1decddeb2949f7a8a0546", + "https://deno.land/std@0.224.0/testing/bdd.ts": "3e4de4ff6d8f348b5574661cef9501b442046a59079e201b849d0e74120d476b", + "https://deno.land/x/gql@2.0.2/deps.ts": "e59f927d0cc8a01c44f1fa2cc5b74cebd54b1d3a2b6c75eee9572a50bea8b819", + "https://deno.land/x/gql@2.0.2/graphiql/markup.ts": "825b76ac088b3813c85da2061e4b4e59ae5f57e38761f66e8c941bbd65999afa", + "https://deno.land/x/gql@2.0.2/graphiql/render.ts": "cb6533c133485093940678221b9eee3fb8ca14f2ac0c7b364d24edd3a074c270", + "https://deno.land/x/gql@2.0.2/mod.ts": "425588ebc6565240fb3908147f43d6a0b9498d3605832b0a829f8f23af5c9f39", + "https://deno.land/x/gql@2.0.2/types.ts": "c9b933567b747ce041f6f0d3e9bba32d102af62ae17785fa0b97310407af8481", + "https://esm.sh/v135/cssfilter@0.0.10/denonext/cssfilter.mjs": "b2dec5f4b51c7574509f04305aa54e33f9de336d66eade79f05552312f18f40b", + "https://esm.sh/v135/xss@1.0.15/denonext/xss.mjs": "b8f597b39cbfc8b9f9b0d73b5b8bb46ee08dd7a9b7eadccb1b524ea54617b031", + "https://esm.sh/xss@1.0.15/": "0d8e27aed5ce31e760e17b57bbc6f95a0146751387a2be56d5263297d92ac387" } } diff --git a/deps.ts b/deps.ts index 7754b2e..03f95bc 100644 --- a/deps.ts +++ b/deps.ts @@ -1,3 +1,3 @@ -export { expect } from 'https://deno.land/std@0.210.0/expect/mod.ts' -export { assertEquals } from 'https://deno.land/std@0.210.0/assert/assert_equals.ts' -export { assertMatch } from 'https://deno.land/std@0.210.0/assert/assert_match.ts' +export { assertEquals } from 'jsr:@std/assert@1.0.0/equals' +export { assertMatch } from 'jsr:@std/assert@1.0.0/match' +export { parseMediaType } from 'jsr:@std/media-types@1.0.1/parse-media-type' diff --git a/e2e_test.ts b/e2e_test.ts new file mode 100644 index 0000000..6676a07 --- /dev/null +++ b/e2e_test.ts @@ -0,0 +1,29 @@ +import { describe, it } from 'https://deno.land/std@0.224.0/testing/bdd.ts' +import { makeFetch } from './mod.ts' +import { GraphQLHTTP } from 'https://deno.land/x/gql@2.0.2/mod.ts' +import { buildSchema } from 'npm:graphql@16.8.1' + +describe('e2e', () => { + it('should work with GraphQL', async () => { + const schema = buildSchema(` + type Query { + hello: String + } + `) + + const handler = GraphQLHTTP({ + schema, + rootValue: { hello: () => 'Hello World!' }, + }) + + const fetch = makeFetch(handler) + + const res = await fetch('/', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ query: '{hello}' }), + }) + + res.expectBody({ data: { hello: 'Hello World!' } }) + }) +}) diff --git a/mod.ts b/mod.ts index 04eca42..d2a7250 100644 --- a/mod.ts +++ b/mod.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertMatch } from './deps.ts' +import { assertEquals, assertMatch, parseMediaType } from './deps.ts' import { Handler, HandlerOrListener } from './types.ts' // credit - 'https://deno.land/x/free_port@v1.2.0/mod.ts' @@ -39,9 +39,11 @@ const fetchEndpoint = async ( const res = await fetch(`http://localhost:${port}${url}`, params) let data: unknown const ct = res.headers.get('Content-Type') - if (ct === 'application/json') data = await res.json() - else if (ct?.includes('text')) data = await res.text() - else if (ct === null) data = await res.text() + if (ct === null) return { data: await res.text(), res } + const [mediaType] = parseMediaType(ct) + + if (mediaType === 'application/json') data = await res.json() + else if (mediaType.includes('text')) data = await res.text() else data = await res.arrayBuffer() return { res, data } } diff --git a/mod_test.ts b/mod_test.ts index 8068c21..7ce2ce6 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -1,8 +1,8 @@ -import { describe, it } from 'https://deno.land/std@0.210.0/testing/bdd.ts' -import { expect } from './deps.ts' +import { describe, it } from 'https://deno.land/std@0.224.0/testing/bdd.ts' +import { expect } from 'jsr:@std/expect@0.224.5/expect' import { makeFetch } from './mod.ts' import { Handler } from './types.ts' -import { AssertionError } from 'https://deno.land/std@0.210.0/assert/assertion_error.ts' +import { AssertionError } from 'jsr:@std/assert@1.0.0/assertion-error' // this simulates the listener class PseudoListener { @@ -23,7 +23,7 @@ class PseudoListener { this.rid = this.#listener.rid } - fetchRandomPort = () => { + fetchRandomPort() { return Math.round(Math.random() * (9000 - 2000)) + 2000 } @@ -53,6 +53,18 @@ describe('makeFetch', () => { res.expect('Hello World') }) + it('should not crash with text/plain', async () => { + const handler: Handler = () => + new Response('Hello World', { + headers: { + 'Content-Type': 'text/plain;charset=UTF-8', + }, + }) + const fetch = makeFetch(handler) + const res = await fetch('/') + + res.expect('Hello World') + }) it('should parse JSON if response is JSON', async () => { const handler: Handler = () => new Response(JSON.stringify({ hello: 'world' }), {