Skip to content

Commit

Permalink
chore: cleaned up server logic on run.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
lquixada committed May 6, 2023
1 parent e276218 commit 6abf91b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
5 changes: 4 additions & 1 deletion test/fetch-api/browser/run.sh
@@ -1,2 +1,5 @@
#!/bin/sh
./bin/server --exec "npx mocha-headless-chrome -f $(dirname $0)/index.html?globals=on" --closeOnExec

source test/setup/server.sh

npx mocha-headless-chrome -f http://127.0.0.1:8000/$(dirname $0)/index.html?globals=on
5 changes: 4 additions & 1 deletion test/fetch-api/node-fetch/run.sh
@@ -1,2 +1,5 @@
#!/bin/sh
./bin/server --exec "npx nyc mocha $(dirname $0)/index.js" --closeOnExec

source test/setup/server.sh

npx nyc mocha $(dirname $0)/index.js
5 changes: 4 additions & 1 deletion test/fetch-api/node/run.sh
@@ -1,2 +1,5 @@
#!/bin/sh
./bin/server --exec "npx nyc mocha $(dirname $0)/index.js" --closeOnExec

source test/setup/server.sh

npx nyc mocha $(dirname $0)/index.js
5 changes: 4 additions & 1 deletion test/fetch-api/whatwg/run.sh
@@ -1,2 +1,5 @@
#!/bin/sh
./bin/server --exec "npx mocha-headless-chrome -f $(dirname $0)/index.html?globals=off" --closeOnExec

source test/setup/server.sh

npx mocha-headless-chrome -f http://127.0.0.1:8000/$(dirname $0)/index.html?globals=off
25 changes: 25 additions & 0 deletions test/setup/server.sh
@@ -0,0 +1,25 @@
#!/bin/sh

start_server () {
./bin/server &
pid=$!
}

kill_server() {
kill $pid
wait $pid 2> /dev/null
}

is_server_ready() {
lsof -i :8000 > /dev/null
}

wait_server() {
while ! is_server_ready; do sleep 0.1; done
}

trap kill_server EXIT

start_server

wait_server

0 comments on commit 6abf91b

Please sign in to comment.