diff --git a/.gitignore b/.gitignore index ed4b243..a56a7ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules -dist/bitauth.browser.js -dist/bitauth.browser.min.js + diff --git a/README.md b/README.md index e58aed4..1c450d1 100644 --- a/README.md +++ b/README.md @@ -185,3 +185,27 @@ BitAuth exposes a connect middleware for use in connect or ExpressJS application var bitauth = require('bitauth'); app.use( bitauth.middleware ); ``` + +## Development + +To build a browser compatible version of BitAuth, run the following command from the project's root directory: + +``` +npm run make-dist +``` + +This will output `bitauth.browser.min.js` to the `dist` directory. The script introduces a global variable at `window.bitauth`. + + +To then run tests for a web browser open `test/index.html` in a browser, such as: + +```bash +firefox test/index.html +chromium-browser test/index.html +``` + +To run tests for Node.js: + +```bash +npm run test +``` diff --git a/dist/.gitignore b/dist/.gitignore new file mode 100644 index 0000000..600a000 --- /dev/null +++ b/dist/.gitignore @@ -0,0 +1,3 @@ +# Ignore everything in this directory +* +!.gitignore \ No newline at end of file diff --git a/dist/README.md b/dist/README.md deleted file mode 100644 index f503e49..0000000 --- a/dist/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# BitAuth Browser Bundle - -To build a browser compatible version of BitAuth, run the following command from -the project's root directory: - -``` -npm run make-dist -``` - -This will output `bitauth.browser.js` to this directory. The script introduces a -global variable at `window.bitauth`. diff --git a/package.json b/package.json index a214189..c91e004 100644 --- a/package.json +++ b/package.json @@ -22,12 +22,11 @@ ], "scripts": { "make-dist": "sh scripts/make-dist.sh", - "test": "mocha test/* --reporter spec", + "test": "mocha test/*.js --reporter spec", "postinstall": "npm run make-dist" }, "main": "index.js", "version": "0.1.1", - "repository": "https://github.com/bitpay/bitauth.git", "dependencies": { "bitcore": "0.1.32", "request": "^2.36.0", @@ -37,9 +36,8 @@ }, "devDependencies": { "uglify-js": "~2.4.14", - "browserify": "~4.1.11", - "should": "~4.0.4", - "expect.js": "~0.3.1", + "browserify": "=6.1.0", + "chai": "=1.9.1", "mocha": "~1.20.1" } } diff --git a/scripts/make-dist.sh b/scripts/make-dist.sh index 4a2650e..6b01c4b 100644 --- a/scripts/make-dist.sh +++ b/scripts/make-dist.sh @@ -1,11 +1,10 @@ cd node_modules/bitcore echo "Building browser bundle for bitcore..." node browser/build -s lib/Key,lib/SINKey,lib/SIN,util/util -echo "Building browser bundle for bitauth..." cd ../../ -node_modules/.bin/browserify lib/bitauth.js -s bitauth -x buffertools -i bitcore -o dist/bitauth.browser.js -echo "Compiling bitcore and bitauth..." -node_modules/.bin/uglifyjs node_modules/bitcore/browser/bundle.js dist/bitauth.browser.js -b -o dist/bitauth.browser.js -echo "Minifying bundle..." -node_modules/.bin/uglifyjs dist/bitauth.browser.js -o dist/bitauth.browser.min.js +cp node_modules/bitcore/browser/bundle.js dist/bitcore.bundle.js +echo "Building browser bundle for bitauth..." +node_modules/.bin/browserify lib/bitauth.js -s bitauth -x buffertools -x bitcore -o dist/bitauth.bundle.js +echo "Minifying bitcore and bitauth..." +node_modules/.bin/uglifyjs dist/bitcore.bundle.js dist/bitauth.bundle.js -o dist/bitauth.browser.min.js echo "Done!" diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..9fae4cb --- /dev/null +++ b/test/index.html @@ -0,0 +1,21 @@ + + + + + BitAuth Tests + + +
+ + + + + + + + + diff --git a/test/bitauth.js b/test/test.bitauth.js similarity index 66% rename from test/bitauth.js rename to test/test.bitauth.js index 384063b..67bd572 100644 --- a/test/bitauth.js +++ b/test/test.bitauth.js @@ -1,9 +1,17 @@ -var should = require('should'); -var expect = require('expect.js'); -var bitauth = require('../index'); +'use strict'; + +if ( typeof(window) === 'undefined' ) { + var bitauth = require('../index'); +} else { + var bitauth = window.bitauth; +} + +var chai = chai || require('chai'); describe('bitauth', function() { + var should = chai.should(); + var keys = null; var sin = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMHX'; var sinb = 'Tf1Jc1xSbqasm5QLwwSQc5umddx2h7mAMhX'; @@ -84,48 +92,47 @@ describe('bitauth', function() { describe('#validateSinCallback', function() { - var received; - - var valid = bitauth.validateSin(sinb, function(err){ - if ( err && typeof(err) == 'object' ) { - received = true; - } - }); - - it('should receive error callback', function() { - expect(received).to.eql(true); - }); - - }); - - describe('#encrypt', function() { - - it('should encrypt the secret message', function(done) { - enc = bitauth.encrypt(password, secret); - should.exist(enc); - done(); - }); - - }); - - describe('#decrypt', function() { - - it('should decrypt the secret message', function(done) { - var dec = bitauth.decrypt(password, enc); - should.exist(dec); - done(); - }); - - }); - - describe('#middleware', function() { - - it('should expose an express middleware', function(done) { - bitauth.middleware( {} , {} , function() { + it('should receive error callback', function(done) { + var valid = bitauth.validateSin(sinb, function(err){ + should.exist(err); done(); }); }); }); + // node specific tests + if ( typeof(window) === 'undefined' ) { + + describe('#encrypt', function() { + + it('should encrypt the secret message', function(done) { + enc = bitauth.encrypt(password, secret); + should.exist(enc); + done(); + }); + }); + + describe('#decrypt', function() { + + it('should decrypt the secret message', function(done) { + var dec = bitauth.decrypt(password, enc); + should.exist(dec); + done(); + }); + + }); + + describe('#middleware', function() { + + it('should expose an express middleware', function(done) { + bitauth.middleware( {} , {} , function() { + done(); + }); + }); + + }); + + } + });