Skip to content

Commit

Permalink
[BUGFIX Release] Add warning for addons missing project
Browse files Browse the repository at this point in the history
Some addons may not have been instantiated correctly (for latest CoreObject)
This detects a common failure mode. Hopefully this helps us catch and
upgrade these addons quickly.
  • Loading branch information
stefanpenner committed Jun 10, 2016
1 parent 5be9842 commit 4b97c8a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/models/addon.js
Expand Up @@ -283,6 +283,10 @@ var Addon = CoreObject.extend({
*/
treeGenerator: function(dir) {
var tree;

if (!this.project) {
console.warn('Addon: `' + this.name + '` is missing addon.project, this may be the result of an addon forgetting to invoke `super` in its init.');
}
// TODO: fix law of demeter `_watchmanInfo.canNestRoots` is obviously a poor idea
if ((this.project && this.project._watchmanInfo.canNestRoots) ||
this.isDevelopingAddon()) {
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/models/addon-test.js
Expand Up @@ -32,14 +32,26 @@ describe('models/addon.js', function() {
});

describe('old core object compat', function() {
var oldWarn = console.warn;

after(function() {
console.warn = oldWarn;
});

it('treeGenerator works without .project', function() {
var TheAddon = Addon.extend({
name: 'such name',
root: path.resolve(fixturePath, 'simple')
});
var addon = new TheAddon();
expect(function() {
var warning;
console.warn = function(message) {
warning = message;
}

addon.treeGenerator('foo');
expect(warning).to.match(/Addon: `such name` is missing addon.project/);
}).to.not.throw();
});
});
Expand Down

0 comments on commit 4b97c8a

Please sign in to comment.