Skip to content

Commit

Permalink
Refactor importProject functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hakantunc committed Feb 11, 2016
1 parent 5f4486e commit 28e318f
Show file tree
Hide file tree
Showing 4 changed files with 176,681 additions and 55 deletions.
49 changes: 38 additions & 11 deletions test/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,52 @@
*/

var testFixture = require('webgme/test/_globals'),
WEBGME_CONFIG_PATH = '../config';
WEBGME_CONFIG_PATH = '../config';

// This flag will make sure the config.test.js is being used
// process.env.NODE_ENV = 'test'; // This is set by the require above, overwrite it here.

var WebGME = testFixture.WebGME,
gmeConfig = require(WEBGME_CONFIG_PATH),
getGmeConfig = function () {
'use strict';
// makes sure that for each request it returns with a unique object and tests will not interfere
if (!gmeConfig) {
// if some tests are deleting or unloading the config
gmeConfig = require(WEBGME_CONFIG_PATH);
}
return JSON.parse(JSON.stringify(gmeConfig));
};
gmeConfig = require(WEBGME_CONFIG_PATH),
getGmeConfig = function () {
'use strict';
// makes sure that for each request it returns with a unique object and tests will not interfere
if (!gmeConfig) {
// if some tests are deleting or unloading the config
gmeConfig = require(WEBGME_CONFIG_PATH);
}
return JSON.parse(JSON.stringify(gmeConfig));
};

WebGME.addToRequireJsPaths(gmeConfig);

testFixture.getGmeConfig = getGmeConfig;

testFixture.clearDbImportProject = function (obj) {
var deferred = testFixture.Q.defer();
var gmeAuth, storage;
testFixture.clearDBAndGetGMEAuth(gmeConfig, null)
.then(function (gmeAuth_) {
gmeAuth = gmeAuth_;
storage = testFixture.getMemoryStorage(obj.logger, gmeConfig, gmeAuth_);
return storage.openDatabase();
})
.then(function () {
return testFixture.importProject(storage, {
projectSeed: obj.seed,
projectName: obj.projectName,
gmeConfig: gmeConfig,
logger: obj.logger
});
})
.then(function (result) {
deferred.resolve({
gmeAuth: gmeAuth,
storage: storage,
result: result
});
});
return deferred.promise;
};

module.exports = testFixture;
43 changes: 18 additions & 25 deletions test/plugins/utils/ImporterUtil.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ImporterUtil', function () {

var importer_util;
before(function (done) {
clearDbImportProjectSetContextAndCore().nodeify(done);
importProject().nodeify(done);
});
after(function (done) {
Q.allDone([
Expand All @@ -45,14 +45,14 @@ describe('ImporterUtil', function () {
describe('import several different nesC components', function () {
var component_paths;
before(function(done) {
clearDbImportProjectSetContextAndCore()
importProject()
.then(function () {
component_paths = importer_util._getComponents();
})
.nodeify(done);
});
beforeEach(function (done) {
clearDbImportProjectSetContextAndCore().nodeify(done);
importProject().nodeify(done);
});
it('SchedulerBasicP', function (done) {
importer_util.importAComponentFromPath(component_paths['SchedulerBasicP.nc'])
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('ImporterUtil', function () {
var components;
this.timeout(12000); // TODO
before(function (done) {
clearDbImportProjectSetContextAndCore()
importProject()
.then(function () {
components = importer_util._getComponents(target);
return importer_util.importAComponentFromPath(components['MainC.nc']);
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('ImporterUtil', function () {
describe('import a component from a directory that includes Makefile', function () {
this.timeout(8000);
before(function (done) {
clearDbImportProjectSetContextAndCore().nodeify(done);
importProject().nodeify(done);
});
it('imports SenseAndSend from Makefile', function (done) {
importer_util.importAComponentFromPath(path.join(__dirname, './NescUtil/SenseAndSend/'))
Expand All @@ -298,7 +298,7 @@ describe('ImporterUtil', function () {

describe('import AMPacket', function () {
before(function (done) {
clearDbImportProjectSetContextAndCore()
importProject()
.then(function () {
importer_util = new ImporterUtil(context, target);
})
Expand All @@ -318,7 +318,7 @@ describe('ImporterUtil', function () {
describe('import AMReceiverC (generic configuration)', function () {
this.timeout(8000);
before(function (done) {
clearDbImportProjectSetContextAndCore()
importProject()
.then(function () {
importer_util = new ImporterUtil(context, target);
})
Expand All @@ -338,7 +338,7 @@ describe('ImporterUtil', function () {
describe('import header files once', function () {
this.timeout(16000);
before(function (done) {
clearDbImportProjectSetContextAndCore()
importProject()
.then(function () {
importer_util = new ImporterUtil(context, target);
})
Expand Down Expand Up @@ -375,7 +375,7 @@ describe('ImporterUtil', function () {
describe.skip('#importAllTosComponents', function () {
this.timeout(800000);
before(function (done) {
clearDbImportProjectSetContextAndCore()
importProject()
.then(function () {
importer_util = new ImporterUtil(context, target);
})
Expand Down Expand Up @@ -437,23 +437,16 @@ describe('ImporterUtil', function () {
return children_obj;
}

function clearDbImportProjectSetContextAndCore () {
return testFixture.clearDBAndGetGMEAuth(gmeConfig, null)
.then(function (gmeAuth_) {
gmeAuth = gmeAuth_;
storage = testFixture.getMemoryStorage(logger, gmeConfig, gmeAuth_);
return storage.openDatabase();
function importProject() {
return testFixture.clearDbImportProject({
logger: logger,
seed: 'src/seeds/Meta/Meta.json',
projectName: projectName
})
.then(function () {
return testFixture.importProject(storage, {
projectSeed: 'src/seeds/Meta/Meta.json',
projectName: projectName,
gmeConfig: gmeConfig,
logger: logger
});
})
.then(function (result) {
context = result;
.then(function (res) {
gmeAuth = res.gmeAuth;
storage = res.storage;
context = res.result;
core = context.core;
importer_util = new ImporterUtil(context, target);
});
Expand Down
53 changes: 34 additions & 19 deletions test/plugins/utils/NescUtil.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,7 @@ describe('NescUtil', function () {
this.timeout(4000);

before(function (done) {
testFixture.clearDBAndGetGMEAuth(gmeConfig, null)
.then(function (gmeAuth_) {
gmeAuth = gmeAuth_;
storage = testFixture.getMemoryStorage(logger, gmeConfig, gmeAuth_);
return storage.openDatabase();
})
.then(function () {
return testFixture.importProject(storage, {
projectSeed: 'test/seeds/SenseAndSend.json',
projectName: projectName,
gmeConfig: gmeConfig,
logger: logger
});
})
.then(function (result) {
context = result;
core = context.core;
project = result.project;
})
importProject('test/seeds/SenseAndSend.json')
.then(setSenseNode)
.nodeify(done);
});
Expand Down Expand Up @@ -267,4 +249,37 @@ describe('NescUtil', function () {
});
});

describe.skip('Msp430Adc12P', function() {
this.timeout(12000);
before(function (done) {
importProject('test/seeds/Msp430Adc12P.json').nodeify(done);
});
it('should generate nesC code', function(done) {
var registry_paths = core.getRegistry(context.rootNode, 'paths');
core.loadByPath(context.rootNode, registry_paths.components.Msp430Adc12P)
.then(function (node) {
return nesc_util.generateNescCode(context, node);
})
.then(function (source) {
console.log(source);
expect(source).to.contain('interface Resource[uint8_t id];');
})
.nodeify(done);
});
});

function importProject(seed) {
return testFixture.clearDbImportProject({
logger: logger,
seed: seed,
projectName: projectName
})
.then(function (res) {
gmeAuth = res.gmeAuth;
storage = res.storage;
context = res.result;
core = context.core;
});
}

});
Loading

0 comments on commit 28e318f

Please sign in to comment.