mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-23 18:29:09 +00:00
Boot & kill servers in a separate script, offer npm run scripts for both ways
This commit is contained in:
parent
ad67413724
commit
182ebf37ec
4 changed files with 73 additions and 48 deletions
|
|
@ -22,7 +22,7 @@ before_script:
|
|||
script:
|
||||
- npm run build
|
||||
- npm run test
|
||||
- npm run test:acceptance || true
|
||||
- npm run test:acceptance:handleservers || true
|
||||
- git config --global user.name 'Uppy Bot'
|
||||
- git config --global user.email 'uppybot@uppy.io'
|
||||
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ] && [ "${TRAVIS_BRANCH}" == "master" ];
|
||||
|
|
|
|||
61
bin/bootandkill-servers
Executable file
61
bin/bootandkill-servers
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env bash
|
||||
# How to run:
|
||||
#
|
||||
# ./bootandkill-servers ./test-acceptance
|
||||
#
|
||||
# this will boot hexo & uppy-server, run the script that you provided as an argument,
|
||||
# and tear down the servers
|
||||
|
||||
set -o pipefail
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
# set -o xtrace
|
||||
|
||||
# Set magic variables for current file & dir
|
||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
||||
__base="$(basename ${__file} .sh)"
|
||||
__root="$(cd "$(dirname "${__dir}")" && pwd)"
|
||||
|
||||
if [ ! -f "${__root}/env.sh" ]; then
|
||||
cp "${__root}/env.example.sh" "${__root}/env.sh"
|
||||
fi
|
||||
if [ "${UPPYSERVER_DROPBOX_KEY:-}" = "" ] || [ "${UPPYSERVER_DROPBOX_KEY:-***}" = "***" ]; then
|
||||
source "${__root}/env.sh"
|
||||
fi
|
||||
if [ "${UPPYSERVER_DROPBOX_KEY:-}" = "" ] || [ "${UPPYSERVER_DROPBOX_KEY:-***}" = "***" ]; then
|
||||
echo "[${__base}] Env var UPPYSERVER_DROPBOX_KEY still had the example value '${UPPYSERVER_DROPBOX_KEY:-}'. "
|
||||
echo "[${__base}] Please save the actual secrets in '${__root}/env.sh' and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function killProcessListeningOnPort () {
|
||||
local port="${1}"
|
||||
lsof -n -i4TCP:${port} | awk '/LISTEN/ {print $2}' |xargs kill -9
|
||||
}
|
||||
|
||||
function cleanup_servers () {
|
||||
echo "[${__base}] --> Killing any server listening on port 4000"
|
||||
killProcessListeningOnPort 4000 || true
|
||||
|
||||
echo "[${__base}] --> Killing any server listening on port 8080"
|
||||
killProcessListeningOnPort 8080 || true
|
||||
|
||||
kill -9 ${tailPid}
|
||||
}
|
||||
|
||||
echo "[${__base}] --> Killing any server listening on port 4000"
|
||||
killProcessListeningOnPort 4000 || true
|
||||
echo "[${__base}] --> Killing any server listening on port 8080"
|
||||
killProcessListeningOnPort 8080 || true
|
||||
|
||||
echo "[${__base}] --> Start webserver and uppy-server in the background"
|
||||
rm -f nohup.out || true
|
||||
touch nohup.out
|
||||
nohup npm run start &
|
||||
tail -f nohup.out &
|
||||
tailPid=${!}
|
||||
|
||||
trap cleanup_servers EXIT
|
||||
|
||||
${@}
|
||||
|
|
@ -1,9 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
# How to run:
|
||||
#
|
||||
# - When using `./bin/test-acceptance handle-servers` this script boots and kills servers too (handy for Travis and quick access)
|
||||
# - When using `./bin/test-acceptance` this script assumes you have your own servers on localhost running (handy for going in depth)
|
||||
# ./bootandkill-servers ./test-acceptance
|
||||
#
|
||||
# this will boot hexo & uppy-server, run the acceptance tests,
|
||||
# and tear down the servers.
|
||||
#
|
||||
# To run just the acceptance tests:
|
||||
#
|
||||
# ./test-acceptance
|
||||
#
|
||||
|
||||
|
||||
set -o pipefail
|
||||
set -o errexit
|
||||
|
|
@ -16,24 +23,6 @@ __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
|||
__base="$(basename ${__file} .sh)"
|
||||
__root="$(cd "$(dirname "${__dir}")" && pwd)"
|
||||
|
||||
mode="${1:-}"
|
||||
|
||||
if [ ! -f "${__root}/env.sh" ]; then
|
||||
cp "${__root}/env.example.sh" "${__root}/env.sh"
|
||||
fi
|
||||
if [ "${UPPYSERVER_DROPBOX_KEY:-}" = "" ] || [ "${UPPYSERVER_DROPBOX_KEY:-***}" = "***" ]; then
|
||||
source "${__root}/env.sh"
|
||||
fi
|
||||
if [ "${UPPYSERVER_DROPBOX_KEY:-}" = "" ] || [ "${UPPYSERVER_DROPBOX_KEY:-***}" = "***" ]; then
|
||||
echo "[${__base}] Env var UPPYSERVER_DROPBOX_KEY still had the example value '${UPPYSERVER_DROPBOX_KEY:-}'. "
|
||||
echo "[${__base}] Please save the actual secrets in '${__root}/env.sh' and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function killProcessListeningOnPort () {
|
||||
local port="${1}"
|
||||
lsof -n -i4TCP:${port} | awk '/LISTEN/ {print $2}' |xargs kill -9
|
||||
}
|
||||
|
||||
function waitForPortOpen () {
|
||||
local port="${1}"
|
||||
|
|
@ -51,32 +40,6 @@ function waitForPortOpen () {
|
|||
done
|
||||
}
|
||||
|
||||
function cleanup_servers () {
|
||||
echo "[${__base}] --> Killing any server listening on port 4000"
|
||||
killProcessListeningOnPort 4000 || true
|
||||
|
||||
echo "[${__base}] --> Killing any server listening on port 8080"
|
||||
killProcessListeningOnPort 8080 || true
|
||||
|
||||
kill -9 ${tailPid}
|
||||
}
|
||||
|
||||
if [ "${mode}" = "handle-servers" ]; then
|
||||
echo "[${__base}] --> Killing any server listening on port 4000"
|
||||
killProcessListeningOnPort 4000 || true
|
||||
echo "[${__base}] --> Killing any server listening on port 8080"
|
||||
killProcessListeningOnPort 8080 || true
|
||||
|
||||
echo "[${__base}] --> Start webserver and uppy-server in the background"
|
||||
rm -f nohup.out || true
|
||||
touch nohup.out
|
||||
nohup npm run start &
|
||||
tail -f nohup.out &
|
||||
tailPid=${!}
|
||||
|
||||
trap cleanup_servers EXIT
|
||||
fi
|
||||
|
||||
echo "[${__base}] --> Wait for hexo webserver to be online"
|
||||
waitForPortOpen 4000
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
"release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && git push && git push --tags && npm publish",
|
||||
"start:server": "uppy-server --port 8080",
|
||||
"start": "parallelshell 'npm run watch' 'npm run start:server' 'npm run web:preview'",
|
||||
"test:acceptance": "bin/test-acceptance handle-servers",
|
||||
"test:acceptance:handleservers": "bin/bootandkill-servers bin/test-acceptance",
|
||||
"test:acceptance": "bin/test-acceptance",
|
||||
"test:unit": "node test/index.js",
|
||||
"test": "npm run lint && npm run test:unit",
|
||||
"travis:deletecache": "travis cache --delete",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue