From 9a824efc74b0b6e13f0560d1952dbf2fd6f9bf81 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 16 Nov 2023 22:35:17 -0600 Subject: [PATCH] Restore the http post test with an http echo server 'one-liner' (#648) * 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 --- bdd/spec/023_http_spec.sh | 64 +++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/bdd/spec/023_http_spec.sh b/bdd/spec/023_http_spec.sh index d64b1aae..c8fd37f0 100644 --- a/bdd/spec/023_http_spec.sh +++ b/bdd/spec/023_http_spec.sh @@ -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() {