Skip to content

Commit

Permalink
Add tests for dataRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jul 26, 2018
1 parent 71dcd49 commit 0cc1fea
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/JBrowse/ConfigManager.js
Expand Up @@ -266,15 +266,13 @@ _noRecursiveMerge: function( propName ) {
* @private
*/
_mergeConfigs: function( a, b ) {
console.log(a,b);
console.log(a.dataRoot,b.dataRoot);
if( b === null )
return null;

if( a === null )
a = {};

Object.keys(b).forEach(prop => {
for (var prop in b) {
if( prop == 'tracks' && (prop in a) ) {
a[prop] = this._mergeTrackConfigs( a[prop] || [], b[prop] || [] );
}
Expand All @@ -285,13 +283,12 @@ _mergeConfigs: function( a, b ) {
a[prop] = Util.deepUpdate( a[prop], b[prop] );
} else if(prop == 'dataRoot') {
if(typeof a[prop] == 'undefined' || a[prop] == 'data' && typeof b[prop] != 'undefined' ){
console.log(a[prop],b[prop])
a[prop] = b[prop];
}
} else if( typeof a[prop] == 'undefined' || typeof b[prop] != 'undefined' ){
a[prop] = b[prop]
a[prop] = b[prop];
}
})
}
return a;
},

Expand Down
3 changes: 3 additions & 0 deletions tests/data/conf/dataRoot.json
@@ -0,0 +1,3 @@
{
"dataRoot": "notdefault",
}
64 changes: 63 additions & 1 deletion tests/js_tests/spec/ConfigManager.spec.js
Expand Up @@ -94,5 +94,67 @@ describe("ConfigManager", function () {
expect(config.tracks[0].label).toEqual('zoo');
});
});

it( "should work with dataRoot specified in baseConfig", function() {
var m = new ConfigManager({
bootConfig: { dataRoot: 'notdefault' },
defaults: { dataRoot: 'data' },
browser: { fatalError: function(error) { throw error; } },
skipValidation: true
});
var config;
expect(m).toBeTruthy();
waitsFor( function() { return config; }, 1000 );
m.getFinalConfig().then( function(c) {
config = c;
});
runs(function() {
expect(config.dataRoot).toEqual('notdefault');
});
});


it( "should work with dataRoot not specified in baseConfig", function() {
var m = new ConfigManager({
bootConfig: { foo: 'a' },
defaults: { dataRoot: 'data' },
browser: { fatalError: function(error) { throw error; } },
skipValidation: true
});
var config;
expect(m).toBeTruthy();
waitsFor( function() { return config; }, 1000 );
m.getFinalConfig().then( function(c) {
config = c;
});
runs(function() {
expect(config.dataRoot).toEqual('data');
});
});


it( "should work with a config with dataRoot in it", function() {
var m = new ConfigManager({
bootConfig: {
include: [ '../data/conf/dataRoot.json'],
},
defaults: { dataRoot: 'data' },
browser: { fatalError: function(error) { throw error; } },
skipValidation: true
});
var config;
expect(m).toBeTruthy();
waitsFor( function() { return config; }, 1000 );
m.getFinalConfig().then( function(c) {
config = c;
});
runs(function() {
expect(config.dataRoot).toEqual('notdefault');
});
});




});
});
});

0 comments on commit 0cc1fea

Please sign in to comment.