Skip to content

Commit

Permalink
Updated router config generation. Fixes #236 (#237)
Browse files Browse the repository at this point in the history
* WIP #236 updated router config gen

* WIP #236 updated router config test

* WIP #236 updated tests
  • Loading branch information
brollb committed Dec 16, 2017
1 parent b9f0033 commit 9d80b84
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/res/config.template.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var config = require('webgme/config/config.default'),

<%= routers.map(function(router) {
return [
'config.rest[\'' + router.name + '\'] = {',
'config.rest.components[\'' + router.name + '\'] = {',
' src: __dirname + \'/../' + router.srcFile + '\',',
' mount: \'' + router.mount + '\',',
' options: {}',
Expand Down
9 changes: 5 additions & 4 deletions test/layout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ describe('Layout tests', function() {
});

it('should add the layout (relative) path to the config file', function() {
var config = require(path.join(PROJECT_DIR, WebGMEConfig));
// check that basePath has been added!
var relativeBase = LayoutBasePath.replace(PROJECT_DIR+path.sep, '');
assert.notEqual(config.visualization.layout.basePaths.indexOf(relativeBase), -1);
const config = require(path.join(PROJECT_DIR, WebGMEConfig));
const layoutPaths = config.visualization.layout.basePaths.map(dir => path.resolve(dir));
const layoutDir = path.resolve(LayoutBasePath);

assert(layoutPaths.includes(layoutDir));
});

it('should record the layout in webgme-setup.json', function() {
Expand Down
21 changes: 13 additions & 8 deletions test/res/BasicProject/config/config.webgme.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@ var config = require('webgme/config/config.default'),
validateConfig = require('webgme/config/validator');

// The paths can be loaded from the webgme-setup.json
config.plugin.basePaths.push('src/plugins');
config.addOn.basePaths.push('src/addOns/MyAddon');
config.visualization.layout.basePaths.push('src/layouts');
config.seedProjects.basePaths.push('src/seeds/test');
config.plugin.basePaths.push(__dirname + '/../src/plugins');
config.addOn.basePaths.push(__dirname + '/../src/addOns/MyAddon');
config.visualization.layout.basePaths.push(__dirname + '/../src/layouts');
config.seedProjects.basePaths.push(__dirname + '/../src/seeds/test');

config.addOn.enable = true;

config.visualization.panelPaths.push('src/visualizers/panels');
config.visualization.panelPaths.push(__dirname + '/../src/visualizers/panels');


config.rest.components['routers/MyRouter'] = __dirname + '/../src/routers/MyRouter/MyRouter.js'
config.rest.components['MyRouter'] = {
src: __dirname + '/../src/routers/MyRouter/MyRouter.js',
mount: 'routers/MyRouter',
options: {}
};

// Visualizer descriptors
config.visualization.visualizerDescriptors.push('./src/visualizers/Visualizers.json');
config.visualization.visualizerDescriptors.push(__dirname + '/../src/visualizers/Visualizers.json');
// Add requirejs paths
config.requirejsPaths = {
'panels': './src/visualizers/panels',
'widgets': './src/visualizers/widgets'
'widgets': './src/visualizers/widgets',
'basicproject': './src/common'
};

config.visualization.layout.default = 'EnabledLayout';
Expand Down
8 changes: 4 additions & 4 deletions test/router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Router tests', function() {
let routerConfig;
before(() => {
let gmeConfig = require(`${PROJECT_DIR}/config/config.webgme.js`);
routerConfig = gmeConfig.rest[ROUTER_NAME];
routerConfig = gmeConfig.rest.components[ROUTER_NAME];
});

it('should update the webgme config', function() {
Expand Down Expand Up @@ -234,10 +234,10 @@ describe('Router tests', function() {
});

it('should add the path to the webgme config', function() {
var config = require(path.join(PROJECT_DIR, WebGMEConfig)),
mntPt = 'other/mount/point';
const config = require(path.join(PROJECT_DIR, WebGMEConfig));
const mntPt = 'other/mount/point';

assert.equal(config.rest[OTHER_ROUTER].mount, mntPt);
assert.equal(config.rest.components[OTHER_ROUTER].mount, mntPt);
});

describe('rm dependency router', function() {
Expand Down
20 changes: 13 additions & 7 deletions test/visualizers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ describe('Viz tests', function() {
before(function(done) {
process.chdir(PROJECT_DIR); // Start in different directory
manager.new({visualizerID: NEW_VIZ}, function() {
utils.requireReload(path.join(VizBasePath, 'Visualizers.json'));
utils.requireReload(
path.join(VizBasePath, 'Visualizers.json'),
path.join(PROJECT_DIR, WebGMEConfig)
);
done();
});
});
Expand All @@ -76,8 +79,10 @@ describe('Viz tests', function() {
});

it('should add panelPaths', function() {
var config = require(path.join(PROJECT_DIR, WebGMEConfig));
assert.notEqual(config.visualization.panelPaths.indexOf('src/visualizers/panels'), -1);
const config = require(path.join(PROJECT_DIR, WebGMEConfig));
const localPanelPath = config.visualization.panelPaths
.find(panelPath => panelPath.includes('src/visualizers/panels'))
assert(localPanelPath);
});

it('should add panels and widgets to requirejsPaths', function() {
Expand All @@ -87,11 +92,12 @@ describe('Viz tests', function() {
});

it('should add Visualizers.json to config.webgme.js', function() {
var config = require(path.join(PROJECT_DIR, WebGMEConfig)),
index = config.visualization.visualizerDescriptors
.indexOf('./src/visualizers/Visualizers.json');
console.log(fse.readFileSync(path.join(PROJECT_DIR, WebGMEConfig), 'utf8'));
const config = require(path.join(PROJECT_DIR, WebGMEConfig));
const localVisJson = config.visualization.visualizerDescriptors
.find(desc => desc.includes('./src/visualizers/Visualizers.json'));

assert.notEqual(index, -1);
assert(localVisJson);
});

it('should add the viz (relative) path to the Visualizers.json', function() {
Expand Down

0 comments on commit 9d80b84

Please sign in to comment.