From 7e6af86d80eff33114f7c5e8150e7835c81dbb88 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 16 Nov 2023 14:55:40 -0600 Subject: [PATCH 1/4] Restore the http post test with an http echo server 'one-liner' --- bdd/spec/023_http_spec.sh | 63 ++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/bdd/spec/023_http_spec.sh b/bdd/spec/023_http_spec.sh index d64b1aae..1dd07db6 100644 --- a/bdd/spec/023_http_spec.sh +++ b/bdd/spec/023_http_spec.sh @@ -31,36 +31,39 @@ 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)" & + 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 + 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() { From 5748b2891ce635bb7ba809c354d249c4a2c99580 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 16 Nov 2023 16:25:39 -0600 Subject: [PATCH 2/4] Fix 'kill' causing a test failure in MacOS and Windows --- bdd/spec/023_http_spec.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bdd/spec/023_http_spec.sh b/bdd/spec/023_http_spec.sh index 1dd07db6..e85335b9 100644 --- a/bdd/spec/023_http_spec.sh +++ b/bdd/spec/023_http_spec.sh @@ -49,7 +49,7 @@ Describe "basic post" BeforeAll before after() { - kill -9 $ECHO_PID + kill -9 $ECHO_PID || true cleanTemp } AfterAll after From e3cf173b72fcde0a1dba43c32ee52da26406b79b Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 16 Nov 2023 17:12:28 -0600 Subject: [PATCH 3/4] Is it complaining about the stderr output? --- bdd/spec/023_http_spec.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bdd/spec/023_http_spec.sh b/bdd/spec/023_http_spec.sh index e85335b9..9825ef99 100644 --- a/bdd/spec/023_http_spec.sh +++ b/bdd/spec/023_http_spec.sh @@ -49,7 +49,7 @@ Describe "basic post" BeforeAll before after() { - kill -9 $ECHO_PID || true + kill -9 $ECHO_PID 1>/dev/null 2>/dev/null || true cleanTemp } AfterAll after From 70546277f9dcde58af923e486369e2413f1385b9 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 16 Nov 2023 21:33:46 -0600 Subject: [PATCH 4/4] 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bdd/spec/023_http_spec.sh b/bdd/spec/023_http_spec.sh index 9825ef99..c8fd37f0 100644 --- a/bdd/spec/023_http_spec.sh +++ b/bdd/spec/023_http_spec.sh @@ -34,8 +34,9 @@ Describe "@std/http" 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)" & + 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