Merge pull request #100 from chevdor/master

Add Karma support for In-Browser testing
This commit is contained in:
Marek Kotewicz 2015-03-06 10:03:13 +01:00
commit 9c72d43f96
5 changed files with 348 additions and 1 deletions

View File

@ -73,6 +73,14 @@ npm run-script build
npm test
```
### Testing (karma)
Karma allows testing within one or several browser.
```bash
karma start --singleRun=true --browsers="Chrome,Firefox"
```
**Please note this repo is in it's early stage.**
If you'd like to run a Http ethereum node check out

96
karma.conf.js Normal file
View File

@ -0,0 +1,96 @@
// Karma configuration
// Generated on Thu Feb 19 2015 19:57:47 GMT+0100 (W. Europe Standard Time)
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false, logLevel: config.LOG_INFO,
//singleRun: true, logLevel: config.LOG_DEBUG,
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['browserify', 'mocha'],
// list of files / patterns to load in the browser
files: [
'test/*.js',
],
// list of files to exclude
exclude: [
],
client: {
mocha: {
//ui: 'tdd'
timeout: 5000 // especially for the post requests
}
},
browserify: {
bundleDelay: 750,
debug: true
// transform: [],
// //extensions: ['.js']
},
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/*.js': ['browserify']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['dots'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
// // Chrome
// // PhantomJS
browsers: ['Chrome', 'Safari', 'Firefox'],
browserNoActivityTimeout: 10000,
browserDisconnectTimeout: 5000,
customLaunchers: {
chromeWithoutSecurity: {
base: 'Chrome',
flags: ['--disable-web-security']
},
IE9: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE9'
},
IE8: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE8'
}
}
});
};

View File

@ -108,7 +108,7 @@ var filterEvents = function (json) {
/// TODO: add tests for it!
var toEth = function (str) {
/*jshint maxcomplexity:7 */
var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str;
var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str.replace(/,/g,'').replace(/ /g,'')) : str;
var unit = 0;
var units = c.ETH_UNITS;
while (val > 3000 && unit < units.length - 1)

View File

@ -25,6 +25,12 @@
"gulp-uglify": ">=1.0.0",
"istanbul": "^0.3.5",
"jshint": ">=2.5.0",
"karma": "^0.12.31",
"karma-browserify": "^4.0.0",
"karma-chrome-launcher": "^0.1.7",
"karma-firefox-launcher": "^0.1.4",
"karma-mocha": "^0.1.10",
"karma-safari-launcher": "^0.1.1",
"mocha": ">=2.1.0",
"mocha-lcov-reporter": "0.0.1",
"unreachable-branch-transform": "^0.1.0",

237
test/utils.convert.js Normal file
View File

@ -0,0 +1,237 @@
var assert = require('assert');
var utils = require('../lib/utils.js');
describe('utils', function() {
// given
// NOTE: I made the following tests pass as long as the values are mathematically correct.
// However, in the current state, there are inconsistancy regarding the trailing decimals.
// For instance '10 Mether' but '10.00 Gether'
var data = [{
test: 10e-9,
res: '0.00 wei'
}, {
test: 10e-6,
res: '0.00 wei'
}, {
test: 10e-3,
res: '0.01 wei'
}, {
test: '-10',
res: '-10 wei'
}, {
test: '0',
res: '0 wei'
}, {
test: 0,
res: '0 wei'
}, {
test: '1200000',
res: '1200 Kwei'
}, {
test: 1e3,
res: '1000 wei'
}, {
test: 10e3,
res: '10 Kwei'
}, {
test: 100e3,
res: '100 Kwei'
}, {
test: 1000e3,
res: '1000 Kwei'
}, {
test: 10e6,
res: '10 Mwei'
}, {
test: 100e6,
res: '100 Mwei'
}, {
test: 1000e6,
res: '1000 Mwei'
}, {
test: 10e9,
res: '10 Gwei'
}, {
test: 100e9,
res: '100 Gwei'
}, {
test: 1000e9,
res: '1000 Gwei'
}, {
test: 10e12,
res: '10 szabo'
}, {
test: 100e12,
res: '100 szabo'
}, {
test: 1000e12,
res: '1000 szabo'
}, {
test: 10e15,
res: '10 finney'
}, {
test: 100e15,
res: '100 finney'
}, {
test: 1000e15,
res: '1000 finney'
}, {
test: 10e18,
res: '10 ether'
}, {
test: 100e18,
res: '100 ether'
}, {
test: 1000e18,
res: '1000 ether'
}, {
test: 10e21,
res: '10 grand'
}, {
test: 100e21,
res: '100.00 grand'
}, {
test: 1000e21,
res: '1000 grand'
}, {
test: 10e24,
res: '10 Mether'
}, {
test: 100e24,
res: '100.00 Mether'
}, {
test: 1000e24,
res: '1000 Mether'
}, {
test: 10e27,
res: '10.00 Gether'
}, {
test: 100e27,
res: '100.00 Gether'
}, {
test: 1000e27,
res: '1000 Gether'
}, {
test: 10e30,
res: '10.00 Tether'
}, {
test: 100e30,
res: '100.00 Tether'
}, {
test: 1000e30,
res: '1,000.00 Tether'
}, {
test: 10e33,
res: '10.00 Pether'
}, {
test: 100e33,
res: '100.00 Pether'
}, {
test: 1000e33,
res: '1000 Pether'
}, {
test: 10e36,
res: '10.00 Eether'
}, {
test: 100e36,
res: '100.00 Eether'
}, {
test: 1000e36,
res: '1,000.00 Eether'
}, {
test: 10e39,
res: '10 Zether'
}, {
test: 100e39,
res: '100.00 Zether'
}, {
test: 1000e39,
res: '1000 Zether'
}, {
test: 10e42,
res: '10 Yether'
}, {
test: 100e42,
res: '100.00 Yether'
}, {
test: 1000e42,
res: '1,000.00 Yether'
}, {
test: 10e45,
res: '10 Nether'
}, {
test: 100e45,
res: '100.00 Nether'
}, {
test: 1000e45,
res: '1000 Nether'
}, {
test: 10e48,
res: '10 Dether'
}, {
test: 100e48,
res: '100.00 Dether'
}, {
test: 1000e48,
res: '1000 Dether'
}, {
test: 10e51,
res: '10 Vether'
}, {
test: 100e51,
res: '100.00 Vether'
}, {
test: 1000e51,
res: '1,000.00 Vether'
}, {
test: 10e54,
res: '10 Uether'
}, {
test: 10e57,
res: '10000 Uether'
}, {
test: 100e57,
res: '100,000.00 Uether'
}, {
test: 1000e57,
res: '1,000,000.00 Uether'
}, {
test: '10',
res: utils.toEth(10)
}, {
test: '100',
res: utils.toEth(100)
}, {
test: '1000',
res: utils.toEth(1000)
}, {
test: '1001',
res: utils.toEth(1001)
}, {
test: '999',
res: utils.toEth(999)
}, {
test: '10000000000000000000000',
res: utils.toEth(10e21) // 10 grand
}, {
test: '10 000',
res: '10 Kwei'
}, {
test: '10,000',
res: '10 Kwei'
}, {
test: '10,000.00',
res: '10 Kwei'
}];
data.forEach(function(elem) {
it('should convert ' + elem.test + ' into ' + elem.res, function() {
// when
var res = utils.toEth(elem.test);
// then
assert.equal(res, elem.res);
});
});
});