Skip to content

Commit

Permalink
scripts: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Jul 12, 2016
1 parent 50daf1f commit 5357ca2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 16 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "A 5kb framework for creating sturdy frontend applications",
"main": "index.js",
"scripts": {
"deps": "dependency-check . && dependency-check . --extra --no-dev -i xhr",
"test:electron": "browserify tests/**/*.js -t es2020 -p proxyquire-universal | tape-run",
"test:cov": "browserify tests/**/*.js -t es2020 -p proxyquire-universal -p tape-istanbul/plugin | tape-run | tape-istanbul && istanbul report",
"test:server": "standard && npm run deps && NODE_ENV=test node tests/server/*",
"test:browser": "standard && npm run deps && NODE_ENV=test zuul tests/browser/*",
"test:browser:local": "standard && npm run deps && NODE_ENV=test zuul --local 8080 -- tests/browser/*",
"deps": "./scripts/test deps",
"test:electron": "./scripts/test electron",
"test:cov": "./scripts/test cov",
"test:server": "./scripts/test server",
"test:browser": "./scripts/test browser",
"test:browser-local": "./scripts/test browser-local",
"preversion": "if [ ! -z $SKIP_TEST ]; then npm run test:browser; fi",
"test": "npm run test:electron",
"build:dev": "./scripts/build dev",
Expand Down
10 changes: 0 additions & 10 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ build_min () {
> dist/choo.min.js
}

# set CLI flags
getopt -T > /dev/null
if [ "$?" -eq 4 ]; then
args="$(getopt --long help dev min --options hdm -- "$*")"
else
args="$(getopt h "$*")";
fi
[ ! $? -eq 0 ] && { usage && exit 2; }
eval set -- "$args"

# parse CLI flags
while true; do
case "$1" in
Expand Down
85 changes: 85 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/sh

# setting exit because we're linting and need to exit on failure
set -e

dirname=$(dirname "$(readlink -f "$0")")

dependency_check="$dirname/../node_modules/.bin/dependency-check"
tape_istanbul="$dirname/../node_modules/.bin/tape-istanbul"
browserify="$dirname/../node_modules/.bin/browserify"
standard="$dirname/../node_modules/.bin/standard"
tape_run="$dirname/../node_modules/.bin/tape-run"
istanbul="$dirname/../node_modules/.bin/istanbul"
zuul="$dirname/../node_modules/.bin/zuul"

usage () {
printf "Usage: test\n"
}

lint () {
"$standard"
}

test_electron () {
check_deps
lint
"$browserify" tests/**/*.js \
-t es2020 \
-p proxyquire-universal \
| "$tape_run"
}

test_cov () {
check_deps
lint
"$browserify" tests/**/*.js \
-t es2020 \
-p proxyquire-universal \
-p tape-istanbul/plugin \
| "$tape_run" \
| "$tape_istanbul" \
&& "$istanbul" report
}

test_server () {
lint
standard
check_deps
NODE_ENV=test node tests/server/*
}

test_browser () {
NODE_ENV=test "$zuul" tests/browser/*
}

test_browser_local () {
lint
check_deps
NODE_ENV=test "$zuul" --local 8080 -- tests/browser/*
}

check_deps () {
"$dependency_check" . --entry 'index.js'
"$dependency_check" . --entry 'index.js' --extra --no-dev \
-i xhr
}

# set CLI flags
# parse CLI flags
while true; do
case "$1" in
-h|--help) usage && exit 1 ;;
-- ) shift; break ;;
* ) break ;;
esac
done

case "$1" in
e|electron) shift; test_electron "$@" && exit ;;
b|browser) shift; test_browser "$@" && exit ;;
l|browser-local) shift; test_browser_local "$@" && exit ;;
s|server) shift; test_server "$@" && exit ;;
c|cov) shift; test_cov "$@" && exit ;;
d|deps) shift; check_deps "$@" && exit ;;
esac

0 comments on commit 5357ca2

Please sign in to comment.