mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Continue tweaking timing based tests.
This commit is contained in:
29
test/test.js
29
test/test.js
@@ -260,7 +260,7 @@
|
|||||||
asyncTest('supports loading ' + basename + ' in a web worker', 1, function() {
|
asyncTest('supports loading ' + basename + ' in a web worker', 1, function() {
|
||||||
if (Worker && !isModularize) {
|
if (Worker && !isModularize) {
|
||||||
var limit = 2000,
|
var limit = 2000,
|
||||||
start = new Date;
|
start = +new Date;
|
||||||
|
|
||||||
var attempt = function() {
|
var attempt = function() {
|
||||||
var actual = _._VERSION;
|
var actual = _._VERSION;
|
||||||
@@ -1481,20 +1481,23 @@
|
|||||||
|
|
||||||
asyncTest('should work with `maxWait` option', 4, function() {
|
asyncTest('should work with `maxWait` option', 4, function() {
|
||||||
if (!(isRhino && isModularize)) {
|
if (!(isRhino && isModularize)) {
|
||||||
var limit = 100,
|
var now,
|
||||||
|
stamp,
|
||||||
|
limit = 100,
|
||||||
withCount = 0,
|
withCount = 0,
|
||||||
withoutCount = 0;
|
withoutCount = 0;
|
||||||
|
|
||||||
var withMaxWait = _.debounce(function() {
|
var withMaxWait = _.debounce(function() {
|
||||||
withCount++;
|
withCount++;
|
||||||
|
stamp = +new Date;
|
||||||
}, 32, { 'maxWait': 64 });
|
}, 32, { 'maxWait': 64 });
|
||||||
|
|
||||||
var withoutMaxWait = _.debounce(function() {
|
var withoutMaxWait = _.debounce(function() {
|
||||||
withoutCount++;
|
withoutCount++;
|
||||||
}, 32);
|
}, 32);
|
||||||
|
|
||||||
var start = new Date;
|
var start = +new Date;
|
||||||
while ((new Date - start) < limit) {
|
while (((now = +new Date) - start) < limit || now == stamp) {
|
||||||
withMaxWait();
|
withMaxWait();
|
||||||
withoutMaxWait();
|
withoutMaxWait();
|
||||||
}
|
}
|
||||||
@@ -5442,9 +5445,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('supports not passing a `max` argument', 1, function() {
|
test('supports not passing a `max` argument', 1, function() {
|
||||||
var actual = _.random(5),
|
var actual = _.random(5);
|
||||||
start = new Date;
|
|
||||||
|
|
||||||
ok(_.some(array, function() {
|
ok(_.some(array, function() {
|
||||||
return _.random(5) != 5;
|
return _.random(5) != 5;
|
||||||
}));
|
}));
|
||||||
@@ -6886,13 +6887,15 @@
|
|||||||
_.times(2, function(index) {
|
_.times(2, function(index) {
|
||||||
asyncTest('should trigger trailing call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), 2, function() {
|
asyncTest('should trigger trailing call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), 2, function() {
|
||||||
if (!(isRhino && isModularize)) {
|
if (!(isRhino && isModularize)) {
|
||||||
var count = 0,
|
var now,
|
||||||
limit = 160,
|
stamp,
|
||||||
|
count = 0,
|
||||||
|
limit = 100,
|
||||||
options = index ? { 'leading': false } : {},
|
options = index ? { 'leading': false } : {},
|
||||||
throttled = _.throttle(function() { count++; }, 64, options),
|
throttled = _.throttle(function() { count++; stamp = +new Date; }, 32, options),
|
||||||
start = new Date;
|
start = +new Date;
|
||||||
|
|
||||||
while ((new Date - start) < limit) {
|
while (((now = +new Date) - start) < limit || now == stamp) {
|
||||||
throttled();
|
throttled();
|
||||||
}
|
}
|
||||||
var lastCount = count;
|
var lastCount = count;
|
||||||
@@ -6901,7 +6904,7 @@
|
|||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
ok(count > lastCount);
|
ok(count > lastCount);
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}, 256);
|
}, 64);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(2);
|
skipTest(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user