From 5a90473d1241390eaf5f19d22dde0208fc702a03 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 4 Feb 2014 15:26:58 -0300 Subject: [PATCH] tests work in browser and node --- .jshintrc | 5 +---- Gruntfile.js | 2 +- bitcore.js | 15 +++++++++++++++ main.js | 9 --------- test/adapter.js | 17 +++++++++++++++++ test/index.html | 1 + test/test.base58.js | 3 +++ test/test.main.js | 2 ++ 8 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 bitcore.js delete mode 100644 main.js create mode 100644 test/adapter.js diff --git a/.jshintrc b/.jshintrc index a10b83a89..7b801cb6a 100644 --- a/.jshintrc +++ b/.jshintrc @@ -31,10 +31,7 @@ "after", "afterEach", "requirejs", - "it", - "chai", - "bitcore" - + "it" ], "indent": false, // Specify indentation spacing "devel": true, // Allow development statements e.g. `console.log();`. diff --git a/Gruntfile.js b/Gruntfile.js index d0da8e8ac..a26a2c654 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -11,7 +11,7 @@ module.exports = function(grunt) { grunt.initConfig({ browserify: { client: { - src: ['main.js'], + src: ['bitcore.js'], dest: 'browser/bundle.js', options: { alias: ['browserify-bignum/bignumber.js:bignum'], diff --git a/bitcore.js b/bitcore.js new file mode 100644 index 000000000..3b01f7aba --- /dev/null +++ b/bitcore.js @@ -0,0 +1,15 @@ +/* + * Bitcore bindings for the browser + */ + + +module.exports.bignum = require('bignum'); +module.exports.base58 = require('base58-native'); +//module.exports.Address = require('./Address'); + + + +if (typeof process.versions === 'undefined') { + module.exports.bignum.config({EXPONENTIAL_AT: 9999999, DECIMAL_PLACES: 0, ROUNDING_MODE: 1}); +} + diff --git a/main.js b/main.js deleted file mode 100644 index 9e9a55060..000000000 --- a/main.js +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Bitcore bindings for the browser - */ - -module.exports.bignum = require('bignum'); -module.exports.base58 = require('base58-native'); - -module.exports.bignum.config({EXPONENTIAL_AT: 9999999, DECIMAL_PLACES: 0, ROUNDING_MODE: 1}); - diff --git a/test/adapter.js b/test/adapter.js new file mode 100644 index 000000000..b3639da9d --- /dev/null +++ b/test/adapter.js @@ -0,0 +1,17 @@ +'use strict'; + +if (typeof require === 'undefined') { + var that = this; + that.require = function(name) { + var split = name.split('/'); + if (split.length > 0) { + name = split.pop(); + } + var module = that[name]; + if (!module) { + throw new Error('Cannot find module "'+name+'"'); + } + return module; + }; + +} diff --git a/test/index.html b/test/index.html index 803199004..b176c8b65 100644 --- a/test/index.html +++ b/test/index.html @@ -8,6 +8,7 @@
+ diff --git a/test/test.base58.js b/test/test.base58.js index 911aa4ee4..54d57eb13 100644 --- a/test/test.base58.js +++ b/test/test.base58.js @@ -1,5 +1,8 @@ 'use strict'; +var chai = require('chai'); +var bitcore = require('../bitcore'); + var expect = chai.expect; var should = chai.should(); diff --git a/test/test.main.js b/test/test.main.js index b03d59edc..aa6e8a237 100644 --- a/test/test.main.js +++ b/test/test.main.js @@ -1,5 +1,7 @@ 'use strict'; +var chai = require('chai'); +var bitcore = require('../bitcore'); var expect = chai.expect; var should = chai.should();