Преглед на файлове

Add a test-acceptance script which spins up servers in the background

Kevin van Zonneveld преди 9 години
родител
ревизия
37c622faf5
променени са 6 файла, в които са добавени 72 реда и са изтрити 6 реда
  1. 2 0
      .gitignore
  2. 0 0
      bin/install-chromedriver
  3. 64 0
      bin/test-acceptance
  4. 4 4
      package.json
  5. 1 1
      src/plugins/Dropbox.js
  6. 1 1
      website/themes/uppy/source/js/uppy.js

+ 2 - 0
.gitignore

@@ -19,3 +19,5 @@ npm-debug.log*
 website/themes/uppy/_config.yml
 
 config/
+
+nohup.out

+ 0 - 0
bin/post-install → bin/install-chromedriver


+ 64 - 0
bin/test-acceptance

@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+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)"
+
+function killProcessListeningOnPort () {
+  local port="${1}"
+  lsof -n -i4TCP:${port} | awk '/LISTEN/ {print $2}' |xargs kill -9
+}
+
+function waitForPortOpen () {
+  local port="${1}"
+  local limit="${2:-20}"
+  local attempts=0
+  echo "waiting on port ${port} to open... "
+  while ! echo exit | nc localhost ${port}; do
+    let "attempts = attempts + 1"
+    echo "still waiting on port ${port} to open... (${attempts} / ${limit}) "
+    sleep 1
+    if [ "${attempts}" -ge "${limit}" ]; then
+      echo "--> Port did not open for ${limit} seconds. Aborting. "
+      exit 1
+    fi
+  done
+}
+
+rm -f nohup.out || true
+
+echo "--> Killing any server listening on port 4000"
+killProcessListeningOnPort 4000 || true
+echo "--> Killing any server listening on port 8080"
+killProcessListeningOnPort 8080 || true
+
+echo "--> Start webserver and uppy-server in the background"
+nohup npm run start &
+
+function dump_logs_before_exit () {
+  echo "--> Killing any server listening on port 4000"
+  killProcessListeningOnPort 4000 || true
+
+  echo "--> Killing any server listening on port 8080"
+  killProcessListeningOnPort 8080 || true
+
+  if [ -f nohup.out ]; then
+    echo "--> Dumping server logs"
+    cat nohup.out
+  fi
+}
+trap dump_logs_before_exit EXIT
+
+echo "--> Wait for hexo webserver to come online"
+waitForPortOpen 4000
+
+echo "--> Wait for uppy-server to come online"
+waitForPortOpen 8080
+
+echo "--> Running acceptance tests"
+node test/multipart.spec.js

+ 4 - 4
package.json

@@ -5,13 +5,13 @@
   "main": "src/index.js",
   "scripts": {
     "start": "parallelshell 'npm run watch' 'npm run start:server' 'npm run web:preview'",
-    "start:server": "uppy-server --port 3002",
+    "start:server": "uppy-server --port 8080",
     "clean": "rm -rf lib && rm -rf dist",
     "docs": "cd website && documentation readme ../src/index.js --readme-file=src/api/docs.md --section 'Uppy Core & Plugins' -q --github -c doc-order.json",
     "lint": "eslint .",
     "lint:fix": "eslint . --fix",
     "test": "npm run lint && npm run test:unit",
-    "test:acceptance": "node test/multipart.spec.js",
+    "test:acceptance": "bin/test-acceptance",
     "test:unit": "node test/index.js",
     "build": "npm run build:lib && npm run build:bundle && npm run build:bundle:min && npm run build:css",
     "build:js": "npm run build:lib && npm run build:bundle && npm run build:bundle:min",
@@ -20,7 +20,7 @@
     "build:bundle:fullpath": "env OUT=uppy-fp.js ./bin/build-bundle --full-paths",
     "build:bundle:min": "./bin/build-bundle",
     "build:bundle": "./bin/build-bundle && ./bin/build-bundle-locales",
-    "install": "bin/post-install",
+    "install": "npm run web:install && bin/install-chromedriver",
     "release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && git push && git push --tags && npm publish",
     "release:major": "env SEMANTIC=major npm run release",
     "release:minor": "env SEMANTIC=minor npm run release",
@@ -29,7 +29,7 @@
     "watch:fast": "parallelshell 'npm run watch:css' 'npm run web:preview'",
     "watch:js": "nodemon --watch src --ext js -x 'npm run build:bundle && node website/update.js'",
     "watch:css": "nodemon --watch src --ext scss -x 'npm run build:css && node website/update.js'",
-    "web": "npm run web:install && npm run web:clean && npm run web:build",
+    "web": "npm run web:clean && npm run web:build",
     "web:kill": "killall -9 node; lsof -n -i4TCP:4000 | awk '/LISTEN/ {print $2}' |xargs kill -9",
     "web:preview": "cd website && parallelshell 'node build-examples.js watch' './node_modules/.bin/hexo server'",
     "web:build": "cd website && node update.js && ./node_modules/.bin/hexo generate --silent && node build-examples.js",

+ 1 - 1
src/plugins/Dropbox.js

@@ -24,7 +24,7 @@ export default class Dropbox extends Plugin {
   }
 
   getDirectory () {
-    // request.get('//localhost:3002/dropbox/readdir')
+    // request.get('//localhost:8080/dropbox/readdir')
     //   .query(opts)
     //   .set('Content-Type', 'application/json')
     //   .end((err, res) => {

+ 1 - 1
website/themes/uppy/source/js/uppy.js

@@ -2375,7 +2375,7 @@ var Dropbox = (function (_Plugin) {
       var opts = {
         dir: 'pizza'
       };
-      _superagent2['default'].get('//localhost:3002/dropbox/readdir').query(opts).set('Content-Type', 'application/json').end(function (err, res) {
+      _superagent2['default'].get('//localhost:8080/dropbox/readdir').query(opts).set('Content-Type', 'application/json').end(function (err, res) {
         console.log(err);
         console.log('yo!');
         console.log(res);