Skip to content

Commit

Permalink
aura_spec & aura.extensions_spec ok
Browse files Browse the repository at this point in the history
  • Loading branch information
sbellity committed Jan 23, 2013
1 parent 30625da commit 2a3aead
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 50 deletions.
13 changes: 8 additions & 5 deletions lib/aura.app.js
Expand Up @@ -87,12 +87,15 @@ define([
// Then we call all the `afterAppStart` provided by the extensions
base.util.each(exts, function(i, ext) {
if (ext && typeof(ext.afterAppStart) === 'function') {
ext.afterAppStart(app);
try {
ext.afterAppStart(app);
} catch(e) {
console.error("Error on ", (ext.name || ext) , ".afterAppStart callback: (", e.message, ")", e);
}
}
});

freeze(app.sandbox);
freeze(app.core);
});
// freeze(app.sandbox);
// freeze(app.core);
});

// If there was an error in the boot sequence we
Expand Down
23 changes: 15 additions & 8 deletions lib/aura.extensions.js
Expand Up @@ -48,7 +48,7 @@ define(['./base'], function(base) {

this.initStarted = true;

var extensions = this._extensions.slice(0),
var extensions = _.compact(this._extensions.slice(0)),
initialized = [],
initStatus = this.initStatus;

Expand All @@ -58,14 +58,19 @@ define(['./base'], function(base) {
(function _init(extDef) {
if (extDef) {
var ext = initExtension(extDef);
ext.done(function() { _init(extensions.shift()); });
ext.fail(initStatus.reject);
initialized.push(ext);
ext.done(function() { _init(extensions.shift()); });
ext.fail(function(err) {
console.error("Failed loading extension ", ext, (err && err.message), err);
initStatus.reject();
});
} else if (extensions.length === 0) {
when.apply(undefined, initialized).done(function() {
initStatus.resolve(Array.prototype.slice.call(arguments));
});
}
})(extensions.shift());

when.apply(undefined, initialized).done(initStatus.resolve);

return initStatus.promise();
};

Expand Down Expand Up @@ -170,17 +175,19 @@ define(['./base'], function(base) {
if (ext && ext.require && ext.require.paths) {
var deps = Object.keys(ext.require.paths) || [];
require.config(ext.require);
require(deps, function() { dfd.resolve(ext); }, reject);
require(deps, function() {
dfd.resolve(ext);
}, reject);
} else {
dfd.resolve(ext);
}
}
} catch(err) {
console.error("Error resolving ext: ", err);
reject(err);
}
};

var reject = function(err) {
console.error("Error loading ext:", ext, err);
dfd.reject(err);
};

Expand Down
9 changes: 4 additions & 5 deletions lib/ext/widgets.js
Expand Up @@ -245,9 +245,8 @@ define('aura/ext/widgets', function() {

name: 'widgets',

config: {
require: { paths: { text: 'requirejs-text/text' } }
},
require: { paths: { text: 'components/requirejs-text/text' } },


init: function(app) {

Expand Down Expand Up @@ -275,8 +274,8 @@ define('aura/ext/widgets', function() {

afterAppStart: function(app) {
// Auto start widgets when the app is loaded.
if (app.options.widgets) {
app.sandbox.start(app.options.widgets);
if (app.startOptions.widgets) {
app.sandbox.start(app.startOptions.widgets);
}
}

Expand Down
1 change: 0 additions & 1 deletion notes/base.md
Expand Up @@ -18,7 +18,6 @@ Current status:
- eventemitter2, for the moment. we could also have a look at postal.js which is extensible and may suit more our needs.
- the selector engine is required by the widgets extension, which is always included for the moment. but we don't really have to.


### since we're here, is their a minimum browser requirement for aura? a recommended browser/cpu requirement?

it should work everywhere. aura itself is really tiny !
Expand Down
1 change: 1 addition & 0 deletions notes/widgets.md
@@ -0,0 +1 @@
# Widgets extension
9 changes: 5 additions & 4 deletions spec/lib/aura.extensions_spec.js
Expand Up @@ -79,13 +79,14 @@ define(['aura/aura.extensions'], function(ExtManager) {

it("Should be possible to add an extension via its module ref name", function(done) {
var mgr = new ExtManager(),
ext = { init: sinon.spy(), foo: "bar" };
ext = { init: sinon.spy(), foo: "bar" },
ctx = { foo: "bar" };

define("myExt", ext);
mgr.add({ ref: "myExt", context: "yep" });
mgr.add({ ref: "myExt", context: ctx });
mgr.init().done(function(extResolved) {
ext.init.should.have.been.calledWith("yep");
extResolved.foo.should.equal("bar");
extResolved[0].foo.should.equal("bar");
ext.init.should.have.been.calledWith(ctx);
done();
});
});
Expand Down
52 changes: 25 additions & 27 deletions spec/lib/aura_spec.js
Expand Up @@ -6,52 +6,52 @@ define(['aura/aura'], function(aura) {
describe("Aura Apps", function() {
describe("App Public API", function() {

var env;
var ext = {
init: sinon.spy(function(appEnv) {
env = appEnv;
env.sandbox.foo = "bar";
init: sinon.spy(function(app) {
app.sandbox.foo = "bar";
}),
afterAppStart: sinon.spy()
};

var app = aura();
var App = aura();

app.use(ext);
App.use(ext);

var startOptions = { foo: "bar" };
var initStatus = app.start(startOptions);
var startOptions = { foo: "bar" };
var initStatus = App.start(startOptions);

// Make sure the app is started before...
before(function(done) {
initStatus.done(function() { done(); });
initStatus.done(function() {
done();
});
initStatus.fail(done);
});

it("Should have loaded its core dependencies", function() {
env.core.data.deferred.should.be.a('function');
App.core.data.deferred.should.be.a('function');
});

it("Should have a public API", function() {
app.use.should.be.a('function');
app.start.should.be.a('function');
app.stop.should.be.a('function');
App.use.should.be.a('function');
App.start.should.be.a('function');
App.stop.should.be.a('function');
});

it("Should call init method on extension", function() {
ext.init.should.have.been.calledWith(env);
ext.init.should.have.been.calledWith(App);
});

it("Should call afterAppStart method on extension", function() {
ext.afterAppStart.should.have.been.calledWith(env);
ext.afterAppStart.should.have.been.called; //With(App);
});

it("Should have extended the sandbox", function() {
env.sandbox.foo.should.equal('bar');
App.sandbox.foo.should.equal('bar');
});

it("Should complain if I try to use a new extension and the app is already started", function() {
app.use.should.Throw(Error);
App.use.should.Throw(Error);
});
});

Expand All @@ -66,29 +66,27 @@ define(['aura/aura'], function(aura) {
});

it("Should be able to use extensions defined as functions", function(done) {
var env;
var insideExt = sinon.spy();
var ext = sinon.spy(function(appEnv) {
env = appEnv;
insideExt('foo');
});
aura().use(ext).start().done(function() {
ext.should.have.been.calledWith(env);
var App = aura().use(ext);
App.start().done(function() {
ext.should.have.been.calledWith(App);
insideExt.should.have.been.calledWith('foo');
done();
});
});

it("Should pass the start options to the extensions...", function(done) {
var env;
var startOptions = { foo: 'bar' };
var insideExt = sinon.spy();
var ext = sinon.spy(function(appEnv) {
env = appEnv;
insideExt(env.options);
var ext = sinon.spy(function(app) {
insideExt(app.startOptions);
});
aura().use(ext).start(startOptions).done(function() {
ext.should.have.been.calledWith(env);
var App = aura().use(ext);
App.start(startOptions).done(function() {
ext.should.have.been.calledWith(App);
insideExt.should.have.been.calledWith(startOptions);
done();
});
Expand Down

0 comments on commit 2a3aead

Please sign in to comment.