From 8767fc006801baa18726f2faacb3e5b40673416e Mon Sep 17 00:00:00 2001 From: Ivan Tivonenko Date: Sat, 6 Feb 2016 05:15:56 +0200 Subject: [PATCH] fixes for minified version test minified version in SauceLabs --- Gulpfile.js | 33 ++++++++++++++++++++++------ npm-shrinkwrap.json | 4 ++-- package.json | 2 +- scripts/ci.sh | 6 ++++-- src/common/browser-hacks.js | 2 +- test/hacks/phantomhacks.js | 37 ++++++++++++++++++++++++++++++++ test/localintegrationrunner.html | 36 +------------------------------ test/localrunner.html | 36 +------------------------------ test/localrunnermin.html | 33 ++++++++++++++++++++++++++++ test/saucerunner.html | 4 ++-- 10 files changed, 108 insertions(+), 85 deletions(-) create mode 100644 test/hacks/phantomhacks.js create mode 100644 test/localrunnermin.html diff --git a/Gulpfile.js b/Gulpfile.js index aa5e62b3..e74927c7 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -13,6 +13,17 @@ var fs = require('fs'); var pkg = require('./package.json'); +var uglifyOptions = { + mangle: { + except: ['_', 'RippleError', 'RippledError', 'UnexpectedError', + 'LedgerVersionError', 'ConnectionError', 'NotConnectedError', + 'DisconnectedError', 'TimeoutError', 'ResponseFormatError', + 'ValidationError', 'NotFoundError', 'MissingLedgerHistoryError', + 'PendingLedgerVersionError' + ] + } +}; + function webpackConfig(extension, overrides) { overrides = overrides || {}; var defaults = { @@ -85,13 +96,17 @@ gulp.task('build-tests', function(callback) { 'integration/'), done); }); +function createLink(from, to) { + if (fs.existsSync(to)) { + fs.unlinkSync(to); + } + fs.linkSync(from, to); +} + function createBuildLink(callback) { return function(err, res) { - var latestBuildName = './build/ripple-latest.js'; - if (fs.existsSync(latestBuildName)) { - fs.unlinkSync(latestBuildName); - } - fs.linkSync('./build/ripple-' + pkg.version + '.js', latestBuildName); + createLink('./build/ripple-' + pkg.version + '.js', + './build/ripple-latest.js'); callback(err, res); }; } @@ -102,9 +117,13 @@ gulp.task('build', function(callback) { gulp.task('build-min', ['build'], function() { return gulp.src(['./build/ripple-', '.js'].join(pkg.version)) - .pipe(uglify()) + .pipe(uglify(uglifyOptions)) .pipe(rename(['ripple-', '-min.js'].join(pkg.version))) - .pipe(gulp.dest('./build/')); + .pipe(gulp.dest('./build/')) + .on('end', function() { + createLink('./build/ripple-' + pkg.version + '-min.js', + './build/ripple-latest-min.js'); + }); }); gulp.task('build-debug', function(callback) { diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 0e3c68ca..81353bd7 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -155,8 +155,8 @@ } }, "ripple-binary-codec": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/ripple-binary-codec/-/ripple-binary-codec-0.1.1.tgz", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ripple-binary-codec/-/ripple-binary-codec-0.1.2.tgz", "dependencies": { "babel-runtime": { "version": "5.8.34", diff --git a/package.json b/package.json index 7bc9f758..aaf50081 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "jayson": "^1.2.2", "lodash": "^3.1.0", "ripple-address-codec": "^2.0.1", - "ripple-binary-codec": "^0.1.1", + "ripple-binary-codec": "^0.1.2", "ripple-hashes": "^0.1.0", "ripple-keypairs": "^0.10.0", "ripple-lib-transactionparser": "^0.6.0", diff --git a/scripts/ci.sh b/scripts/ci.sh index b6006474..40eb6558 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -36,11 +36,13 @@ unittest() { mocha --opts test-compiled/mocha.opts test-compiled # compile tests for browser testing - gulp build build-tests + gulp build-min build-tests node --harmony test-compiled/mocked-server.js > /dev/null & echo "Running tests in PhantomJS" mocha-phantomjs test/localrunner.html + echo "Running tests using minified version in PhantomJS" + mocha-phantomjs test/localrunnermin.html echo "Running tests in SauceLabs" http-server & @@ -56,7 +58,7 @@ integrationtest() { mocha test/integration/http-integration-test.js # run integration tests in PhantomJS - gulp build-tests build + gulp build-tests build-min echo "Running integragtion tests in PhantomJS" mocha-phantomjs test/localintegrationrunner.html } diff --git a/src/common/browser-hacks.js b/src/common/browser-hacks.js index 646840b9..62f207f0 100644 --- a/src/common/browser-hacks.js +++ b/src/common/browser-hacks.js @@ -11,7 +11,7 @@ function setPrototypeOf(object, prototype) { function getConstructorName(object) { // hack for internet explorer return process.browser ? - object.constructor.toString().match(/^function\s(.+)\(/)[1] : + object.constructor.toString().match(/^function\s+([^(]*)/)[1] : object.constructor.name; } diff --git a/test/hacks/phantomhacks.js b/test/hacks/phantomhacks.js new file mode 100644 index 00000000..396dd580 --- /dev/null +++ b/test/hacks/phantomhacks.js @@ -0,0 +1,37 @@ +'use strict'; +// this one will be directly run in browser, so disable eslint +/* eslint-disable no-var, no-extend-native, consistent-this, func-style */ + +(function() { + var phantomTest = /PhantomJS/; + if (phantomTest.test(navigator.userAgent)) { + // mocha-phantomjs-core has wrong shim for Function.bind, so we + // will replace it with correct one + // this bind polyfill copied from MDN documentation + Function.prototype.bind = function(oThis) { + if (typeof this !== 'function') { + // closest thing possible to the ECMAScript 5 + // internal IsCallable function + throw new TypeError( + 'Function.prototype.bind - what is trying to be bound is not callable' + ); + } + + var aArgs = Array.prototype.slice.call(arguments, 1); + var fToBind = this; + var FNOP = function() {}; + var fBound = function() { + return fToBind.apply(this instanceof FNOP ? this : oThis, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + if (this.prototype) { + // native functions don't have a prototype + FNOP.prototype = this.prototype; + } + fBound.prototype = new FNOP(); + + return fBound; + }; + } +})(); diff --git a/test/localintegrationrunner.html b/test/localintegrationrunner.html index 438f3e56..24b075a2 100644 --- a/test/localintegrationrunner.html +++ b/test/localintegrationrunner.html @@ -9,41 +9,7 @@
- + - + + + +
+
+ + + + + + + + + + + + + + + + diff --git a/test/saucerunner.html b/test/saucerunner.html index a6f6e76e..b7bd5a46 100644 --- a/test/saucerunner.html +++ b/test/saucerunner.html @@ -10,9 +10,9 @@
- + - +