Skip to content
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

Restore the http post test with an http echo server 'one-liner' #648

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading