mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
Unit test teardown improvements (#6821)
* Clear module require()s between tests Clear profile cache between tests * Fix authentication for careportal test * Add logging to see where the careportal test gets to * Even more logging for headless setup * Change to use before and after in careportal test * Add time logging * Bump headless setup time to a full minute * More timers to figure out what's slow in GA * Bump up timeout on failing test
This commit is contained in:
@@ -42,20 +42,20 @@ hashauth.init = function init (client, $) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.message === 'OK') {
|
||||
if (response.message === 'OK' || message.message === 'OK') {
|
||||
hashauth.authenticated = true;
|
||||
console.log('Authentication passed.');
|
||||
next(true);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Authentication failed.', response);
|
||||
console.log('Authentication failed!', response);
|
||||
hashauth.removeAuthentication();
|
||||
next(false);
|
||||
return;
|
||||
|
||||
}).fail(function verifyfail (err) {
|
||||
console.log('Authentication failed.', err);
|
||||
console.log('Authentication failure', err);
|
||||
hashauth.removeAuthentication();
|
||||
next(false);
|
||||
});
|
||||
|
||||
@@ -7,10 +7,10 @@ var times = require('./times');
|
||||
|
||||
var cacheTTL = 5000;
|
||||
var prevBasalTreatment = null;
|
||||
var cache = new c.Cache();
|
||||
|
||||
function init (profileData) {
|
||||
|
||||
var cache = new c.Cache();
|
||||
var profile = {};
|
||||
|
||||
profile.clear = function clear() {
|
||||
@@ -19,6 +19,8 @@ function init (profileData) {
|
||||
prevBasalTreatment = null;
|
||||
}
|
||||
|
||||
profile.clear();
|
||||
|
||||
profile.loadData = function loadData (profileData) {
|
||||
if (profileData && profileData.length) {
|
||||
profile.data = profile.convertToProfileStore(profileData);
|
||||
@@ -36,7 +38,7 @@ function init (profileData) {
|
||||
var newObject = {};
|
||||
newObject.defaultProfile = 'Default';
|
||||
newObject.store = {};
|
||||
newObject.startDate = profile.startDate;
|
||||
newObject.startDate = profile.startDate ? profile.startDate : '1980-01-01';
|
||||
newObject._id = profile._id;
|
||||
newObject.convertedOnTheFly = true;
|
||||
delete profile.startDate;
|
||||
|
||||
+2
-1
@@ -11,4 +11,5 @@ ALARM_TYPES="predict"
|
||||
LANGUAGE=en
|
||||
INSECURE_USE_HTTP=true
|
||||
PORT=1337
|
||||
NODE_ENV=development
|
||||
NODE_ENV=development
|
||||
AUTH_FAIL_DELAY=50
|
||||
+3
-3
@@ -27,9 +27,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"test": "env-cmd -f ./my.test.env mocha --exit tests/*.test.js",
|
||||
"test-single": "env-cmd -f ./my.test.env mocha --exit tests/$TEST.test.js",
|
||||
"test-ci": "env-cmd -f ./ci.test.env nyc --reporter=lcov --reporter=text-summary mocha --exit tests/*.test.js",
|
||||
"test": "env-cmd -f ./my.test.env mocha --require ./tests/hooks.js -exit ./tests/*.test.js",
|
||||
"test-single": "env-cmd -f ./my.test.env mocha --require ./tests/hooks.js --exit ./tests/$TEST.test.js",
|
||||
"test-ci": "env-cmd -f ./ci.test.env nyc --reporter=lcov --reporter=text-summary mocha --require ./tests/hooks.js --exit ./tests/*.test.js",
|
||||
"env": "env",
|
||||
"postinstall": "webpack --mode production --config webpack.config.js && npm run-script update-buster",
|
||||
"bundle": "webpack --mode production --config webpack.config.js && npm run-script update-buster",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const should = require('should');
|
||||
require('should');
|
||||
|
||||
const ctx = {};
|
||||
|
||||
|
||||
@@ -26,10 +26,6 @@ describe('Devicestatus API', function ( ) {
|
||||
});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
// delete process.env.API_SECRET;
|
||||
});
|
||||
|
||||
it('post a devicestatus, query, delete, verify gone', function (done) {
|
||||
// insert a devicestatus - needs to be unique from example data
|
||||
console.log('Inserting devicestatus entry');
|
||||
|
||||
+21
-17
@@ -2,8 +2,6 @@
|
||||
|
||||
require('should');
|
||||
var benv = require('benv');
|
||||
var read = require('fs').readFileSync;
|
||||
var serverSettings = require('./fixtures/default-server-settings');
|
||||
|
||||
var nowData = {
|
||||
sgvs: [
|
||||
@@ -12,33 +10,35 @@ var nowData = {
|
||||
, treatments: []
|
||||
};
|
||||
|
||||
describe('client', function ( ) {
|
||||
this.timeout(40000); // TODO: see why this test takes longer on Travis to complete
|
||||
|
||||
var self = this;
|
||||
describe('careportal', function ( ) {
|
||||
this.timeout(60000); // TODO: see why this test takes longer on Travis to complete
|
||||
|
||||
var headless = require('./fixtures/headless')(benv, this);
|
||||
|
||||
before(function (done) {
|
||||
done( );
|
||||
|
||||
const t = Date.now();
|
||||
console.log('Starting headless setup for Careportal test');
|
||||
|
||||
function d () {
|
||||
console.log('Done called by headless', Date.now() - t );
|
||||
done();
|
||||
}
|
||||
|
||||
headless.setup({mockAjax: true}, d);
|
||||
console.log('Headless setup for Careportal test done');
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
done( );
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
headless.setup({mockAjax: true}, done);
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
headless.teardown( );
|
||||
done( );
|
||||
});
|
||||
|
||||
it ('open careportal, and enter a treatment', function (done) {
|
||||
|
||||
var client = window.Nightscout.client;
|
||||
console.log('Careportal test client start');
|
||||
|
||||
var client = window.Nightscout.client;
|
||||
|
||||
var hashauth = require('../lib/client/hashauth');
|
||||
hashauth.init(client,$);
|
||||
@@ -47,7 +47,9 @@ describe('client', function ( ) {
|
||||
next(true);
|
||||
};
|
||||
|
||||
console.log('Careportal test client init');
|
||||
client.init();
|
||||
console.log('Careportal test client data update');
|
||||
client.dataUpdate(nowData, true);
|
||||
|
||||
client.careportal.prepareEvents();
|
||||
@@ -81,8 +83,10 @@ describe('client', function ( ) {
|
||||
return true;
|
||||
};
|
||||
|
||||
window.alert = function mockAlert() {};
|
||||
window.alert = function mockAlert(messages) { messages.should.equal(''); };
|
||||
|
||||
console.log('Careportal test saving');
|
||||
|
||||
client.careportal.save();
|
||||
|
||||
done();
|
||||
|
||||
+2
-1
@@ -14,7 +14,8 @@ describe('COB', function ( ) {
|
||||
var cob = require('../lib/plugins/cob')(ctx);
|
||||
|
||||
var profileData = {
|
||||
sens: 95
|
||||
startDate: '2015-06-21'
|
||||
, sens: 95
|
||||
, carbratio: 18
|
||||
, carbs_hr: 30
|
||||
};
|
||||
|
||||
Vendored
+16
-5
@@ -9,26 +9,36 @@ function headless (benv, binding) {
|
||||
}
|
||||
|
||||
function init (opts, callback) {
|
||||
var localStorage = opts.localStorage || './localstorage';
|
||||
|
||||
const t = Date.now();
|
||||
|
||||
console.log('Headless init');
|
||||
|
||||
var htmlFile = opts.htmlFile || __dirname + '/../../views/index.html';
|
||||
var serverSettings = opts.serverSettings || require('./default-server-settings');
|
||||
var someData = opts.mockAjax || { };
|
||||
|
||||
console.log('Entering setup', Date.now() - t);
|
||||
|
||||
benv.setup(function() {
|
||||
|
||||
console.log('Setting up benv', Date.now() - t);
|
||||
|
||||
benv.require(__dirname + '/../../tmp/js/bundle.report.js');
|
||||
|
||||
|
||||
console.log('Bundle loaded', Date.now() - t);
|
||||
|
||||
self.$ = $;
|
||||
|
||||
self.localCookieStorage = self.localStorage = self.$.localStorage = require('./localstorage');
|
||||
|
||||
//self.$ = require('jquery');
|
||||
//self.$.localStorage = require(localStorage);
|
||||
|
||||
self.$.fn.tooltip = function mockTooltip ( ) { };
|
||||
|
||||
var indexHtml = read(htmlFile, 'utf8');
|
||||
self.$('body').html(indexHtml);
|
||||
|
||||
console.log('HTML set', Date.now() - t);
|
||||
|
||||
var d3 = require('d3');
|
||||
//disable all d3 transitions so most of the other code can run with jsdom
|
||||
d3.timer = function mockTimer() { };
|
||||
@@ -124,6 +134,7 @@ function headless (benv, binding) {
|
||||
};
|
||||
}
|
||||
|
||||
console.log('Benv expose', Date.now() - t);
|
||||
|
||||
benv.expose({
|
||||
$: self.$
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
'use strict;'
|
||||
|
||||
function clearRequireCache () {
|
||||
Object.keys(require.cache).forEach(function(key) {
|
||||
delete require.cache[key];
|
||||
});
|
||||
}
|
||||
|
||||
exports.mochaHooks = {
|
||||
afterEach (done) {
|
||||
clearRequireCache();
|
||||
done();
|
||||
}
|
||||
};
|
||||
@@ -7,6 +7,7 @@ var language = require('../lib/language')();
|
||||
describe('API_SECRET', function ( ) {
|
||||
var api;
|
||||
var scope = this;
|
||||
this.timeout(5000);
|
||||
|
||||
function setup_app (env, fn) {
|
||||
api = require('../lib/api/');
|
||||
@@ -18,7 +19,7 @@ describe('API_SECRET', function ( ) {
|
||||
});
|
||||
}
|
||||
|
||||
it('should work fail set unauthorized', function (done) {
|
||||
it('should fail when unauthorized', function (done) {
|
||||
var known = 'b723e97aa97846eb92d5264f084b2823f57c4aa1';
|
||||
delete process.env.API_SECRET;
|
||||
process.env.API_SECRET = 'this is my long pass phrase';
|
||||
|
||||
Reference in New Issue
Block a user