Comparing version 0.0.11 to 0.0.12
@@ -49,3 +49,3 @@ 'use strict'; | ||
else { | ||
this.$modules[resolvedName] = module; | ||
this.$modules[resolvedName].content = module; | ||
} | ||
@@ -52,0 +52,0 @@ callback(null, this.$modules[resolvedName].content); |
{ | ||
"name": "r42", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Dependency injection done right.", | ||
@@ -5,0 +5,0 @@ "author": "Quentin Raynaud <npm@qraynaud.eu>", |
@@ -120,7 +120,10 @@ 'use strict'; | ||
it('initialize $modules[<moduleName>] to null during instantiation', function () { | ||
it('initialize $modules[<moduleName>] to {dependent: [], content: {}} during instantiation', function () { | ||
var called = 0; | ||
mc.addModule('test', function () { | ||
++called; | ||
expect(mc.$modules.test).to.be.null; | ||
expect(mc.$modules.test).to.be.deep.eql({ | ||
dependent: [], | ||
content: {}, | ||
}); | ||
}, function () {}); | ||
@@ -175,3 +178,3 @@ expect(called).to.be.eql(1); | ||
expect(err).not.to.exist; | ||
expect(mc.$modules.test).to.be.eql(moduleValue); | ||
expect(mc.$modules.test.content).to.be.eql(moduleValue); | ||
}); | ||
@@ -178,0 +181,0 @@ expect(called).to.be.eql(1); |
@@ -18,5 +18,5 @@ 'use strict'; | ||
describe('::runString', function () { | ||
describe('::runFile', function () { | ||
it('is a function', function () { | ||
expect(run.runString).to.be.a('Function'); | ||
expect(run.runFile).to.be.a('Function'); | ||
}); | ||
@@ -26,3 +26,3 @@ | ||
'javascript is invalid', function () { | ||
run.runString('test.js', 'invalidCode(', null, function (err) { | ||
run.runFile('test.js', null, function (err) { | ||
expect(err.constructor.name).to.be.eql('SyntaxError'); | ||
@@ -33,3 +33,3 @@ }); | ||
it('calls the provided callback with a null if execution goes well', function () { | ||
run.runString('test.js', '42', null, function (err) { | ||
run.runFile('test.js', null, function (err) { | ||
expect(err).to.be.null; | ||
@@ -40,3 +40,3 @@ }); | ||
it('automatically provides the global environment in the execution env', function () { | ||
run.runString('test.js', 'process.env.NODE_ENV = "toto"', null, function (err) { | ||
run.runFile('test.js', 'process.env.NODE_ENV = "toto"', null, function (err) { | ||
expect(err).to.be.null; | ||
@@ -48,3 +48,3 @@ }); | ||
'javascript uses an invalid global variable', function () { | ||
run.runString('test.js', 'testEnv.super = 42', null, function (err) { | ||
run.runFile('test.js', 'testEnv.super = 42', null, function (err) { | ||
expect(err.constructor.name).to.be.eql('ReferenceError'); | ||
@@ -55,3 +55,3 @@ }); | ||
it('merges the provided environment into the execution env', function () { | ||
run.runString('test.js', 'testEnv.super = 42', { | ||
run.runFile('test.js', 'testEnv.super = 42', { | ||
testEnv: {}, | ||
@@ -63,34 +63,2 @@ }, function (err) { | ||
}); | ||
describe('::runFile', function () { | ||
beforeEach(function () { | ||
sinon.spy(run, 'runString'); | ||
}); | ||
afterEach(function () { | ||
run.runString.restore(); | ||
}); | ||
it('is a function', function () { | ||
expect(run.runFile).to.be.a('Function'); | ||
}); | ||
it('returns an error if given an invalid file path', function (done) { | ||
run.runFile('unknown.js', null, function (err, res) { | ||
expect(err).to.be.an.instanceOf(Error); | ||
expect(err.message).to.be.eql('Error reading file unknown.js'); | ||
}.dotry(done, true)); | ||
}); | ||
it('calls run.runString with file content', function (done) { | ||
var filepath = path.join(__dirname, 'run.txt'); | ||
run.runFile(filepath, null, function (err, res) { | ||
expect(err).to.not.exist; | ||
expect(run.runString).to.have.been.calledOnce.and | ||
.to.have.been.calledWithMatch( | ||
filepath, | ||
'"42 is cool"' | ||
); | ||
}.dotry(done, true)); | ||
}); | ||
}); | ||
}); |
26813
22
717