From ef88c75c650cae5dd780a9786e8b0ebaa1782c5a Mon Sep 17 00:00:00 2001 From: Haydn Ewers Date: Fri, 28 Aug 2015 12:42:05 +0930 Subject: [PATCH] Improve the test scripts & other tooling. --- CONTRIBUTING.md | 42 ++++++++++++++++++++++++++++-------------- package.json | 11 ++++++++--- scripts/release | 21 +++++++++------------ scripts/test | 24 +++++++++++++++++++----- 4 files changed, 64 insertions(+), 34 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f5e8b34..646d631 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,19 @@ -## Tests +## Development Requirements + +- Node.js +- PhantomJS + +## Getting Started + +Clone the project and install NPM packages: + +``` +git clone git@github.com:haydn/json-api-store.git +cd json-api-store +npm install +``` + +## Running Tests You can run tests once-off with NPM: @@ -6,34 +21,33 @@ You can run tests once-off with NPM: npm test ``` -Alternatively, you can run tests in watch mode using -[nodemon](http://nodemon.io): +Alternatively, you can run tests in watch mode: ``` -nodemon node_modules/jasmine/bin/jasmine.js +npm start ``` -## Documentation +## Generating Documentation -You can generate the documentation with [esdoc](https://esdoc.org/): +You can regenerate the documentation with: ``` -esdoc -c esdoc.json +npm run docs ``` -## Building +## Building Distribution -You can rebuild the the output from the source using -[babel](https://babeljs.io): +You can rebuild the the output from the source using: ``` -babel src/store.js -m umd --module-id Store --compact true --no-comments -o dist/store.js +npm run build ``` -## Releases +## Making Releases -You can make a new release using the script: +There's a script available for making releases. Without the required +permissions, you won't get you very far, but if you're curious here it is: ``` -script/release +npm run release ``` diff --git a/package.json b/package.json index 701426a..8d93de3 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,11 @@ "repository": "haydn/json-api-store", "main": "dist/store.js", "scripts": { - "test": "scripts/test", - "build": "node_modules/.bin/babel src/store.js -m umd --module-id Store" + "build": "./node_modules/.bin/babel src/store.js -m umd --module-id Store --compact --no-comments -o dist/store.js -s", + "docs": "./node_modules/.bin/esdoc -c esdoc.json", + "release": "./scripts/release", + "start": "./scripts/test --watch", + "test": "./scripts/test" }, "author": "Haydn Ewers", "license": "MIT", @@ -14,8 +17,10 @@ "babel": "^5.8.21", "babelify": "^6.2.0", "browserify": "^11.0.1", + "chokidar-cli": "^1.0.1", + "esdoc": "^0.2.2", "sinon": "^1.16.1", - "tap-dot": "^1.0.0", + "tap-spec": "^4.1.0", "tape": "^4.2.0", "tape-run": "^1.1.0" }, diff --git a/scripts/release b/scripts/release index 2615c8e..312e685 100755 --- a/scripts/release +++ b/scripts/release @@ -1,13 +1,11 @@ #!/usr/bin/env bash -if [ $(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') != "master" ] -then +if [ $(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') != "master" ]; then echo >&2 "Looks like you're not on the master branch. Checkout master and run this script." exit 1 fi -if [[ -n $(git status --porcelain 2> /dev/null) ]] -then +if [[ -n $(git status --porcelain 2> /dev/null) ]]; then echo >&2 "Looks like you're in a dirty head state. Clean-up un-committed files before and run this script again." exit 1 fi @@ -21,8 +19,7 @@ npm install echo "$ npm test" npm test -if [ $? -ne 0 ] -then +if [ $? -ne 0 ]; then echo >&2 "Looks like there are failing tests. Make sure all tests pass and run this script again." exit 1 fi @@ -30,8 +27,7 @@ fi echo "$ eslint --quiet src" eslint --quiet src -if [ $? -ne 0 ] -then +if [ $? -ne 0 ]; then echo >&2 "Looks like there are linting errors. Make sure all errors are cleaned-up and run this script again." exit 1 fi @@ -42,9 +38,9 @@ git tag -l read -p "Enter the version number for this release (eg '1.4.5'): " version echo "Building docs..." -esdoc -c esdoc.json +npm run docs echo "Building dist..." -babel src/store.js -m umd --module-id Store --compact true --no-comments -o dist/store.js +npm run build echo "Updating NPM and Bower manifests..." sed -i.bak -E "s/\"version\": \"[0-9]+\.[0-9]+\.[0-9]+\"/\"version\": \"$version\"/" package.json rm package.json.bak @@ -52,8 +48,9 @@ sed -i.bak -E "s/\"version\": \"[0-9]+\.[0-9]+\.[0-9]+\"/\"version\": \"$version rm bower.json.bak read -p "Are you sure you want to release v$version? (yes/no) " confirm -if [ $confirm != "yes" ] -then + +if [ $confirm != "yes" ]; then + echo "Aborting." exit 0 fi diff --git a/scripts/test b/scripts/test index 461a2c1..71c5b04 100755 --- a/scripts/test +++ b/scripts/test @@ -1,15 +1,29 @@ #!/usr/bin/env bash if [ "$TARGET" = "browser" ]; then - node_modules/.bin/browserify spec/client.js -t babelify | node_modules/.bin/tape-run + ./node_modules/.bin/browserify spec/client.js -t babelify | node_modules/.bin/tape-run exit $? fi if [ "$TARGET" = "node" ]; then - node_modules/.bin/babel-node spec/server.js + ./node_modules/.bin/babel-node spec/server.js exit $? fi -node_modules/.bin/babel-node spec/server.js | node_modules/.bin/tap-dot || true -node_modules/.bin/browserify spec/client.js -t babelify | node_modules/.bin/tape-run | node_modules/.bin/tap-dot || true -exit 0 +result=1 + +if [ "$1" = "--watch" ]; then + ./node_modules/.bin/chokidar './src/**/*.js' './spec/**/*.js' -c './scripts/test' + result=$? +else + echo "Testing in node:" + ./node_modules/.bin/babel-node spec/server.js | node_modules/.bin/tap-spec + result=$? + if [ $result -eq 0 ]; then + echo "Testing in browser:" + ./node_modules/.bin/browserify spec/client.js -t babelify | node_modules/.bin/tape-run | node_modules/.bin/tap-spec + result=$? + fi +fi + +exit $result -- 2.51.2