Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Test nested addon import #6043

Merged
merged 1 commit into from
Jul 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 26 additions & 4 deletions lib/models/addon.js
Expand Up @@ -376,6 +376,31 @@ var Addon = CoreObject.extend({
return tree;
},

/**
This method climbs up the hierarchy of addons
up to the host application.

This prevents previous addons (prior to `this.import`, ca 2.7.0)
to break at importing assets when they are used nested in other addons.

@private
@method _findHost
```
*/
_findHost: function() {
var app = this.app;
var parent = this.parent;
while (parent.parent) {
if (parent.app) {
app = parent.app;
break;
}

parent = parent.parent;
}
return app;
},

/**
This method is called when the addon is included in a build. You
would typically use this hook to perform additional imports
Expand Down Expand Up @@ -420,10 +445,7 @@ var Addon = CoreObject.extend({
@param {String} [options.destDir] Destination directory, defaults to the name of the directory the asset is in
*/
import: function(asset, options) {
var app = this.app;
while (app.app) {
app = app.app;
}
var app = this._findHost();
app.import(asset, options);
},

Expand Down
59 changes: 59 additions & 0 deletions tests/acceptance/nested-addons-smoke-test-slow.js
@@ -0,0 +1,59 @@
'use strict';

var path = require('path');
var fs = require('fs-extra');

var runCommand = require('../helpers/run-command');
var acceptance = require('../helpers/acceptance');
var copyFixtureFiles = require('../helpers/copy-fixture-files');
var createTestTargets = acceptance.createTestTargets;
var teardownTestTargets = acceptance.teardownTestTargets;
var linkDependencies = acceptance.linkDependencies;
var cleanupRun = acceptance.cleanupRun;

var chai = require('../chai');
var expect = chai.expect;
var file = chai.file;
var dir = chai.dir;

var appName = 'some-cool-app';

describe('Acceptance: nested-addons-smoke-test', function() {
this.timeout(360000);

before(function() {
return createTestTargets(appName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this part here takes quite a long time it might be beneficial to combine this with other "slow" tests. e.g. if there is something like an addons-smoke-test-slow already then you should probably just add it there instead.

});

after(function() {
return teardownTestTargets();
});

beforeEach(function() {
return linkDependencies(appName);
});

afterEach(function() {
return cleanupRun(appName).then(function() {
expect(dir('tmp/' + appName)).to.not.exist;
});
});

it('addons with nested addons compile correctly', function() {
return copyFixtureFiles('addon/with-nested-addons')
.then(function() {
var packageJsonPath = path.join(__dirname, '..', '..', 'tmp', appName, 'package.json');
var packageJson = fs.readJsonSync(packageJsonPath);
packageJson.devDependencies['ember-top-addon'] = 'latest';

return fs.writeJsonSync(packageJsonPath, packageJson);
})
.then(function() {
return runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
})
.then(function() {
expect(file('dist/assets/vendor.js')).to.contain('INNER_ADDON_IMPORT_WITH_APP_IMPORT');
expect(file('dist/assets/vendor.js')).to.contain('INNER_ADDON_IMPORT_WITH_THIS_IMPORT');
});
});
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.