-
Notifications
You must be signed in to change notification settings - Fork 182
Add cohttp-lwt-jsoo test suite. #764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
077cc79
Add cohttp-lwt-jsoo test.
mefyl 890e96d
Install node dependencies on github action runners.
mefyl db313d1
Use conf-npm to ensure npm installation.
mefyl 441b984
Run javascript test on Github only.
mefyl 9cc649b
Move node-related files to the JSOO test suite.
mefyl f12c5f7
Merge master into feature/jsoo-test.
mefyl 3c7b602
Fill CHANGES.md.
mefyl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ _build/ | |
| *.install | ||
| .merlin | ||
| _opam/ | ||
| node_modules | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ build: | |
| test: | ||
| dune runtest | ||
|
|
||
| js-test: | ||
| dune build @runjstest | ||
|
|
||
| clean: | ||
| dune clean | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "ocaml-cohttp", | ||
| "version": "4.0.0", | ||
| "description": "An OCaml library for HTTP clients and servers", | ||
| "repository": "https://github.com/mirage/ocaml-cohttp", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "xmlhttprequest": "^1.8.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| module Client = Cohttp_lwt_jsoo.Client | ||
| module Js = Js_of_ocaml.Js | ||
|
|
||
| let _Promise = Js.Unsafe.global##._Promise | ||
| let ( let* ) = Lwt.( >>= ) | ||
| let ( let+ ) = Lwt.( >|= ) | ||
|
|
||
| let promise_of_lwt lwt = | ||
| new%js _Promise | ||
| (Js.wrap_callback (fun resolve reject -> | ||
| try%lwt | ||
| let+ res = lwt () in | ||
| Js.Unsafe.fun_call resolve [| Js.Unsafe.inject res |] | ||
| with e -> | ||
| let msg = Printexc.to_string e in | ||
| Js.Unsafe.fun_call reject | ||
| [| Js.Unsafe.inject (new%js Js.error_constr (Js.string msg)) |])) | ||
|
|
||
| let () = | ||
| Js.export_all | ||
| (object%js | ||
| method request uri = | ||
| let f () = | ||
| let uri = Uri.of_string (Js.to_string uri) in | ||
| let* response, body = Client.get uri in | ||
| let+ body = Cohttp_lwt.Body.to_string body in | ||
| let status = | ||
| Cohttp.Response.status response |> Cohttp.Code.code_of_status | ||
| in | ||
| Js.array | ||
| [| Js.Unsafe.inject status; Js.Unsafe.inject @@ Js.string body |] | ||
| in | ||
| promise_of_lwt f | ||
| end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| (executable | ||
| (name cohttp_lwt_jsoo_test) | ||
| (modes js) | ||
| (libraries cohttp cohttp-lwt cohttp-lwt-jsoo lwt js_of_ocaml-lwt) | ||
| (preprocess | ||
| (pps lwt_ppx js_of_ocaml-ppx))) | ||
|
|
||
| (rule | ||
| (alias runjstest) | ||
| (deps test.js cohttp_lwt_jsoo_test.bc.js) | ||
| (action | ||
| (setenv | ||
| NODE_PATH | ||
| "%{project_root}/cohttp_lwt_jsoo_test/node_modules" | ||
| (run ./test.js)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const assert = require('assert'); | ||
|
|
||
| global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; | ||
| const tests = require('./cohttp_lwt_jsoo_test.bc.js') | ||
|
|
||
| async function main() { | ||
| { | ||
| const [status, body] = await tests.request("https://mirage.io"); | ||
|
mseri marked this conversation as resolved.
|
||
| assert(status == 200); | ||
| } | ||
| { | ||
| const [status, body] = await tests.request("https://this.domain.does.not.exist"); | ||
| assert(status == 0); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test checks what e18e6a8 fixed. |
||
| } | ||
| } | ||
|
|
||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
| # yarn lockfile v1 | ||
|
|
||
|
|
||
| xmlhttprequest@^1.8.0: | ||
| version "1.8.0" | ||
| resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" | ||
| integrity sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw= |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.