Skip to content

Commit

Permalink
fixes for minified version test minified version in SauceLabs
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdarkdragon committed Feb 9, 2016
1 parent 66b0762 commit 8767fc0
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 85 deletions.
33 changes: 26 additions & 7 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
};
}
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/browser-hacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
37 changes: 37 additions & 0 deletions test/hacks/phantomhacks.js
Original file line number Diff line number Diff line change
@@ -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;
};
}
})();
36 changes: 1 addition & 35 deletions test/localintegrationrunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,7 @@
<div id="deb"></div>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script>
(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),
fToBind = this,
fNOP = function() {},
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;
};
}
})();
</script>
<script src="hacks/phantomhacks.js"></script>
<script src="../build/ripple-latest.js"></script>
<script>
if (window.initMochaPhantomJS) {
Expand Down
36 changes: 1 addition & 35 deletions test/localrunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,7 @@
<div id="deb"></div>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script>
(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),
fToBind = this,
fNOP = function() {},
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;
};
}
})();
</script>
<script src="hacks/phantomhacks.js"></script>
<script src="../build/ripple-latest.js"></script>
<script>
if (window.initMochaPhantomJS) {
Expand Down
33 changes: 33 additions & 0 deletions test/localrunnermin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<html>
<head>
<meta charset="utf-8">
<!-- encoding must be set for mocha's special characters to render properly -->
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<script src="./vendor/lodash.min.js"></script>
</head>
<body>
<div id="deb"></div>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="hacks/phantomhacks.js"></script>
<script src="../build/ripple-latest-min.js"></script>
<script>
if (window.initMochaPhantomJS) {
window.initMochaPhantomJS();
}
mocha.ui('bdd')
</script>

<script src="../test-compiled-for-web/api-test.js"></script>

<script src="../test-compiled-for-web/broadcast-api-test.js"></script>

<script src="../test-compiled-for-web/connection-test.js"></script>

<script src="../test-compiled-for-web/rangeset-test.js"></script>

<script>
mocha.run()
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions test/saucerunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<div id="mocha"></div>
<script src="/node_modules/mocha/mocha.js"></script>

<script src="/node_modules/mocha-sauce/client.js"></script>
<script src="/node_modules/mocha-in-sauce/client.js"></script>

<script src="/build/ripple-latest.js"></script>
<script src="/build/ripple-latest-min.js"></script>
<script>
mocha.ui('bdd')
</script>
Expand Down

0 comments on commit 8767fc0

Please sign in to comment.