Skip to content

Commit

Permalink
Restore the http post test with an http echo server 'one-liner' (#648)
Browse files Browse the repository at this point in the history
* Restore the http post test with an http echo server 'one-liner'

* Fix 'kill' causing a test failure in MacOS and Windows

* Is it complaining about the stderr output?

* Apparently need to disown the process to prevent it's death from breaking the test suite -- but only when the full test suite is run. That's a weird behavior of shellspec
  • Loading branch information
dfellis authored Nov 17, 2023
1 parent 1106f8d commit 9a824ef
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions bdd/spec/023_http_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,40 @@ Describe "@std/http"
End
End

# TODO: Revive this test when an alternative to reqbin is found. It no longer works.
# Describe "basic post"
# before() {
# sourceToAll "
# from @std/app import start, print, exit
# from @std/http import post
#
# on start {
# print(post('https://reqbin.com/echo/post/json', '{\"test\":\"test\"}'));
# emit exit 0;
# }
# "
# }
# BeforeAll before
#
# after() {
# cleanTemp
# }
# AfterAll after
#
# It "runs js"
# When run test_js
# The output should eq "{\"success\":\"true\"}"
# End
#
# It "runs agc"
# When run test_agc
# The output should eq "{\"success\":\"true\"}"
# End
# End
Describe "basic post"
before() {
# All my homies hate CORS...
node -e "const http = require('http'); http.createServer((req, res) => { const headers = { 'Access-Control-Allow-Origin': '*','Access-Control-Allow-Methods': 'OPTIONS, POST, GET, PUT','Access-Control-Max-Age': 2592000, 'Access-Control-Allow-Headers': '*', }; if (req.method === 'OPTIONS') { res.writeHead(204, headers); res.end(); return; } res.writeHead(200, headers); req.pipe(res); req.on('end', () => res.end()); }).listen(8765)" 1>/dev/null 2>/dev/null &
ECHO_PID=$!
disown $ECHO_PID
sourceToAll "
from @std/app import start, print, exit
from @std/http import post
on start {
print(post('http://localhost:8765', '{\"test\":\"test\"}'));
emit exit 0;
}
"
}
BeforeAll before

after() {
kill -9 $ECHO_PID 1>/dev/null 2>/dev/null || true
cleanTemp
}
AfterAll after

It "runs js"
When run test_js
The output should eq "{\"test\":\"test\"}"
End

It "runs agc"
When run test_agc
The output should eq "{\"test\":\"test\"}"
End
End

Describe "fetch directly"
before() {
Expand Down

0 comments on commit 9a824ef

Please sign in to comment.