Skip to content

Commit

Permalink
Fix tests failing in dev (#5127)
Browse files Browse the repository at this point in the history
* * Fix reporting test to match the new output
* Fix number formatter to return the expected 0 when data is NaN
* Remove excessive logging during test runs from cob plugin

* Run all tests in one go

* Fixes D3 invocations for tests. Note this also removes transition timers (most of which seemed to be timed so fast they actually had no effect as the timer was faster than what it takes to draw a frame in Nightscout)

* Run tests independently

* Try not running tap-set-exit

* Remove tap-set-exit
  • Loading branch information
sulkaharo authored Oct 21, 2019
1 parent 36de82b commit e10d483
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 123 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ travis:
python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
# NODE_ENV=test ${MONGO_SETTINGS} \
# ${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 5000 -R tap ${TESTS}
for var in tests/*.js; do ${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap $$var; done | tap-set-exit
for var in tests/*.js; do ${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap $$var; done

docker_release:
# Get the version from the package.json file
Expand Down
21 changes: 3 additions & 18 deletions lib/client/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var PADDING_BOTTOM = 30
, CONTEXT_MIN = 36
, FOCUS_MAX = 510
, FOCUS_MIN = 30
, DEFAULT_TRANS_MS = 100
;

function init (client, d3, $) {
Expand Down Expand Up @@ -481,7 +480,7 @@ function init (client, d3, $) {
} else {

// for subsequent updates use a transition to animate the axis to the new position
var focusTransition = chart.focus.transition().duration(DEFAULT_TRANS_MS);
var focusTransition = chart.focus;

focusTransition.select('.x')
.attr('transform', 'translate(0,' + focusHeight + ')')
Expand All @@ -491,7 +490,7 @@ function init (client, d3, $) {
.attr('transform', 'translate(' + chartWidth + ', 0)')
.call(chart.yAxis);

var contextTransition = chart.context.transition().duration(DEFAULT_TRANS_MS);
var contextTransition = chart.context;

chart.context
.attr('transform', 'translate(0,' + focusHeight + ')')
Expand All @@ -500,7 +499,7 @@ function init (client, d3, $) {
.attr('transform', 'translate(0,' + contextHeight + ')')
.call(chart.xAxis2);

chart.basals.transition().duration(DEFAULT_TRANS_MS);
chart.basals;

// reset brush location
chart.theBrush.selectAll('rect')
Expand All @@ -514,68 +513,59 @@ function init (client, d3, $) {

// transition lines to correct location
chart.focus.select('.high-line')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale(currentRange[0]))
.attr('y1', chart.yScale(utils.scaleMgdl(client.settings.thresholds.bgHigh)))
.attr('x2', chart.xScale(currentRange[1]))
.attr('y2', chart.yScale(utils.scaleMgdl(client.settings.thresholds.bgHigh)));

chart.focus.select('.target-top-line')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale(currentRange[0]))
.attr('y1', chart.yScale(utils.scaleMgdl(client.settings.thresholds.bgTargetTop)))
.attr('x2', chart.xScale(currentRange[1]))
.attr('y2', chart.yScale(utils.scaleMgdl(client.settings.thresholds.bgTargetTop)));

chart.focus.select('.target-bottom-line')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale(currentRange[0]))
.attr('y1', chart.yScale(utils.scaleMgdl(client.settings.thresholds.bgTargetBottom)))
.attr('x2', chart.xScale(currentRange[1]))
.attr('y2', chart.yScale(utils.scaleMgdl(client.settings.thresholds.bgTargetBottom)));

chart.focus.select('.low-line')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale(currentRange[0]))
.attr('y1', chart.yScale(utils.scaleMgdl(client.settings.thresholds.bgLow)))
.attr('x2', chart.xScale(currentRange[1]))
.attr('y2', chart.yScale(utils.scaleMgdl(client.settings.thresholds.bgLow)));

// transition open-top line to correct location
chart.context.select('.open-top')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale2(currentRange[0]))
.attr('y1', chart.yScale2(utils.scaleMgdl(CONTEXT_MAX)))
.attr('x2', chart.xScale2(currentRange[1]))
.attr('y2', chart.yScale2(utils.scaleMgdl(CONTEXT_MAX)));

// transition open-left line to correct location
chart.context.select('.open-left')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale2(currentRange[0]))
.attr('y1', chart.yScale2(contextYDomain[0]))
.attr('x2', chart.xScale2(currentRange[0]))
.attr('y2', chart.yScale2(contextYDomain[1]));

// transition open-right line to correct location
chart.context.select('.open-right')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale2(currentRange[1]))
.attr('y1', chart.yScale2(contextYDomain[0]))
.attr('x2', chart.xScale2(currentRange[1]))
.attr('y2', chart.yScale2(contextYDomain[1]));

// transition high line to correct location
chart.context.select('.high-line')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale2(dataRange[0]))
.attr('y1', chart.yScale2(utils.scaleMgdl(client.settings.thresholds.bgTargetTop)))
.attr('x2', chart.xScale2(dataRange[1]))
.attr('y2', chart.yScale2(utils.scaleMgdl(client.settings.thresholds.bgTargetTop)));

// transition low line to correct location
chart.context.select('.low-line')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale2(dataRange[0]))
.attr('y1', chart.yScale2(utils.scaleMgdl(client.settings.thresholds.bgTargetBottom)))
.attr('x2', chart.xScale2(dataRange[1]))
Expand Down Expand Up @@ -630,37 +620,32 @@ function init (client, d3, $) {

// transition open-top line to correct location
chart.context.select('.open-top')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale2(currentRange[0]))
.attr('y1', chart.yScale2(contextYDomain[1]))
.attr('x2', chart.xScale2(currentRange[1]))
.attr('y2', chart.yScale2(contextYDomain[1]));

// transition open-left line to correct location
chart.context.select('.open-left')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale2(currentRange[0]))
.attr('y1', chart.yScale2(contextYDomain[0]))
.attr('x2', chart.xScale2(currentRange[0]))
.attr('y2', chart.yScale2(contextYDomain[1]));

// transition open-right line to correct location
chart.context.select('.open-right')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale2(currentRange[1]))
.attr('y1', chart.yScale2(contextYDomain[0]))
.attr('x2', chart.xScale2(currentRange[1]))
.attr('y2', chart.yScale2(contextYDomain[1]));

chart.focus.select('.now-line')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale(nowDate))
.attr('y1', chart.yScale(focusYDomain[0]))
.attr('x2', chart.xScale(nowDate))
.attr('y2', chart.yScale(focusYDomain[1]));

chart.context.select('.now-line')
.transition().duration(DEFAULT_TRANS_MS)
.attr('x1', chart.xScale2(currentBrushExtent[1]))
.attr('y1', chart.yScale2(contextYDomain[0]))
.attr('x2', chart.xScale2(currentBrushExtent[1]))
Expand Down
21 changes: 12 additions & 9 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ client.init = function init (callback) {

client.load = function load (serverSettings, callback) {

var UPDATE_TRANS_MS = 750 // milliseconds
, FORMAT_TIME_12 = '%-I:%M %p'
var FORMAT_TIME_12 = '%-I:%M %p'
, FORMAT_TIME_12_COMPACT = '%-I:%M'
, FORMAT_TIME_24 = '%H:%M%'
, FORMAT_TIME_12_SCALE = '%-I %p'
Expand Down Expand Up @@ -1143,7 +1142,7 @@ client.load = function load (serverSettings, callback) {
});
}

function dataUpdate (received) {
function dataUpdate (received, headless) {
console.info('got dataUpdate', new Date(client.now));

var lastUpdated = Date.now();
Expand Down Expand Up @@ -1177,17 +1176,21 @@ client.load = function load (serverSettings, callback) {
prepareEntries();
updateTitle();

// Don't invoke D3 in headless mode

if (!isInitialData) {
isInitialData = true;
chart = client.chart = require('./chart')(client, d3, $);
brushed();
chart.update(true);
if (!headless) {
chart = client.chart = require('./chart')(client, d3, $);
brushed();
chart.update(true);
}
} else if (!inRetroMode()) {
chart.update(false);
if (!headless) chart.update(false);
client.plugins.updateVisualisations(client.nowSBX);
brushed();
if (!headless) brushed();
} else {
chart.updateContext();
if (!headless) chart.updateContext();
}
}
};
Expand Down
42 changes: 19 additions & 23 deletions lib/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ var times = require('../times');
var DEFAULT_FOCUS = times.hours(3).msecs
, WIDTH_SMALL_DOTS = 420
, WIDTH_BIG_DOTS = 800
, TOOLTIP_TRANS_MS = 100 // milliseconds
, DEFAULT_TRANS_MS = 10 // milliseconds
, TOOLTIP_WIDTH = 150 //min-width + padding
;

Expand Down Expand Up @@ -47,8 +45,7 @@ function init (client, d3) {
}

function hideTooltip () {
client.tooltip.transition().duration(TOOLTIP_TRANS_MS)
.style('opacity', 0);
client.tooltip.style('opacity', 0);
}

// get the desired opacity for context chart based on the brush extent
Expand Down Expand Up @@ -166,7 +163,7 @@ function init (client, d3) {

var rawbgInfo = getRawbgInfo();

client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9);
client.tooltip.style('opacity', .9);
client.tooltip.html('<strong>' + translate('BG') + ':</strong> ' + client.sbx.scaleEntry(d) +
(d.type === 'mbg' ? '<br/><strong>' + translate('Device') + ': </strong>' + d.device : '') +
(d.type === 'forecast' && d.forecastType ? '<br/><strong>' + translate('Forecast Type') + ': </strong>' + d.forecastType : '') +
Expand All @@ -178,7 +175,7 @@ function init (client, d3) {
}

// if already existing then transition each circle to its new position
updateFocusCircles(focusCircles.transition().duration(DEFAULT_TRANS_MS));
updateFocusCircles(focusCircles);

// if new circle then just display
prepareFocusCircles(focusCircles.enter().append('circle'))
Expand Down Expand Up @@ -317,13 +314,13 @@ function init (client, d3) {
}

// if already existing then transition each circle to its new position
updateTreatCircles(treatCircles.transition().duration(DEFAULT_TRANS_MS));
updateTreatCircles(treatCircles);

// if new circle then just display
prepareTreatCircles(treatCircles.enter().append('circle'))
.attr('class', 'treatment-dot')
.on('mouseover', function(d) {
client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9);
client.tooltip.style('opacity', .9);
client.tooltip.html(d.isAnnouncement ? announcementTooltip(d) : treatmentTooltip(d))
.style('left', tooltipLeft())
.style('top', (d3.event.pageY + 15) + 'px');
Expand Down Expand Up @@ -404,7 +401,7 @@ function init (client, d3) {
}

// if transitioning, update rect text, position, and width
var rectUpdates = treatRects.transition().duration(DEFAULT_TRANS_MS);
var rectUpdates = treatRects;
rectUpdates.attr('transform', rectTranslate);

rectUpdates.select('text')
Expand All @@ -420,7 +417,7 @@ function init (client, d3) {
.attr('class', 'g-duration')
.attr('transform', rectTranslate)
.on('mouseover', function(d) {
client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9);
client.tooltip.style('opacity', .9);
client.tooltip.html(d.isAnnouncement ? announcementTooltip(d) : treatmentTooltip(d))
.style('left', tooltipLeft())
.style('top', (d3.event.pageY + 15) + 'px');
Expand Down Expand Up @@ -481,7 +478,7 @@ function init (client, d3) {
}

// if already existing then transition each circle to its new position
prepareContextCircles(contextCircles.transition().duration(DEFAULT_TRANS_MS));
prepareContextCircles(contextCircles);

// if new circle then just display
prepareContextCircles(contextCircles.enter().append('circle'));
Expand Down Expand Up @@ -622,7 +619,7 @@ function init (client, d3) {
glucose = Math.round(glucose * decimals) / decimals;
}

client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9);
client.tooltip.style('opacity', .9);
client.tooltip.html('<strong>' + translate('Time') + ':</strong> ' + client.formatTime(new Date(treatment.mills)) + '<br/>' + '<strong>' + translate('Treatment type') + ':</strong> ' + translate(client.careportal.resolveEventName(treatment.eventType)) + '<br/>' +
(treatment.carbs ? '<strong>' + translate('Carbs') + ':</strong> ' + treatment.carbs + '<br/>' : '') +
(treatment.protein ? '<strong>' + translate('Protein') + ':</strong> ' + treatment.protein + '<br/>' : '') +
Expand All @@ -649,7 +646,7 @@ function init (client, d3) {
//console.log(treatment);
var windowWidth = $(client.tooltip.node()).parent().parent().width();
var left = d3.event.x + TOOLTIP_WIDTH < windowWidth ? d3.event.x : windowWidth - TOOLTIP_WIDTH - 10;
client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9)
client.tooltip.style('opacity', .9)
.style('left', left + 'px')
.style('top', (d3.event.pageY ? d3.event.pageY + 15 : 40) + 'px');

Expand Down Expand Up @@ -742,7 +739,7 @@ function init (client, d3) {
})
.on('drag', function() {
//console.log(d3.event);
client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9);
client.tooltip.style('opacity', .9);
var x = Math.min(Math.max(0, d3.event.x), chart().charts.attr('width'));
var y = Math.min(Math.max(0, d3.event.y), chart().focusHeight);

Expand Down Expand Up @@ -793,7 +790,7 @@ function init (client, d3) {
}
, function callback (result) {
console.log(result);
chart().drag.selectAll('.arrow').transition().duration(5000).style('opacity', 0).remove();
chart().drag.selectAll('.arrow').style('opacity', 0).remove();
}
);
} else {
Expand All @@ -810,7 +807,7 @@ function init (client, d3) {
}
, function callback (result) {
console.log(result);
chart().drag.selectAll('.arrow').transition().duration(5000).style('opacity', 0).remove();
chart().drag.selectAll('.arrow').style('opacity', 0).remove();
}
);
} else {
Expand All @@ -827,7 +824,7 @@ function init (client, d3) {
}
, function callback (result) {
console.log(result);
chart().drag.selectAll('.arrow').transition().duration(5000).style('opacity', 0).remove();
chart().drag.selectAll('.arrow').style('opacity', 0).remove();
}
);
} else {
Expand All @@ -843,7 +840,7 @@ function init (client, d3) {
}
, function callback (result) {
console.log(result);
chart().drag.selectAll('.arrow').transition().duration(5000).style('opacity', 0).remove();
chart().drag.selectAll('.arrow').style('opacity', 0).remove();
}
);
} else {
Expand Down Expand Up @@ -871,7 +868,7 @@ function init (client, d3) {
}
, function callback (result) {
console.log(result);
chart().drag.selectAll('.arrow').transition().duration(5000).style('opacity', 0).remove();
chart().drag.selectAll('.arrow').style('opacity', 0).remove();
}
);
} else {
Expand Down Expand Up @@ -899,7 +896,7 @@ function init (client, d3) {
}
, function callback (result) {
console.log(result);
chart().drag.selectAll('.arrow').transition().duration(5000).style('opacity', 0).remove();
chart().drag.selectAll('.arrow').style('opacity', 0).remove();
}
);
} else {
Expand Down Expand Up @@ -1213,8 +1210,7 @@ function init (client, d3) {
return ret;
};

treatProfiles.transition().duration(0)
.attr('transform', function(t) {
treatProfiles.attr('transform', function(t) {
// change text of record on left side
return 'rotate(-90,' + chart().xScale(t.mills) + ',' + chart().yScaleBasals(topOfText) + ') ' +
'translate(' + chart().xScale(t.mills) + ',' + chart().yScaleBasals(topOfText) + ')';
Expand All @@ -1234,7 +1230,7 @@ function init (client, d3) {
})
.text(generateText)
.on('mouseover', function(d) {
client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9);
client.tooltip.style('opacity', .9);
client.tooltip.html(profileTooltip(d))
.style('left', (d3.event.pageX) + 'px')
.style('top', (d3.event.pageY + 15) + 'px');
Expand Down
1 change: 0 additions & 1 deletion lib/plugins/cob.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function init (ctx) {

if (_.isEmpty(result) || _.isNil(result.cob) || (Date.now() - result.mills) > TEN_MINUTES) {

console.log('Calculating COB');
var treatmentCOB = (treatments !== undefined && treatments.length) ? cob.fromTreatments(treatments, devicestatus, profile, time, spec_profile) : {};

result = treatmentCOB;
Expand Down
Loading

0 comments on commit e10d483

Please sign in to comment.