Creating ember addon for integration tests - can't get file into tests


#1

Apologies for the x post - I have put this on SO also.

I am trying to turn this:

into an ember-cli-addon (

https://github.com/wayne-o/ember-cli-qunit-assert-html )

I have read https://gist.github.com/kristianmandrup/ae3174217f68a6a51ed5 which is great but I am stuck figuring out how to make the qunit-assert-html.min.js available in my tests.

All I have done so far is add the file to /vendor and then imported it inside index.js:

npm linking the add-on into my project successfully adds the /vendor/qunit-assert-html.min.js to my apps /vendor folder but I can’t figure out how to make that available in my integration tests.

Any help appreciated!


#2

There’s a few ways to make dependencies available in your add-on: it’s either have to be a bower_components or vendor. Those are the ONLY two folders that you are allowed to include files from. It is possible to include node_modules or any other folder in your add-on, but there’s quite a few hoops to jump through to get there.

bower_components are standard installed through bower package manager, but because bower flattens dependency tree, your add-on has to instruct the dependent app to install it. You do this through a default blueprint. Don’t forget to add the dependency to your add-on’s bower.json too for dev purpose.

vendor follows the convention of vendor/package/file.js. I don’t think this is documented, but your vendor file MUST follow this convention for import to work correctly.

Including node_modules and other folders requires you to implement treeFor* hooks in your addon. These hooks are invoked by ember-cli to allow you to include additional broccoli trees in the build cycle. In order to include other folders, you have to use these hooks to move your files into the vendor/ folder, then import it again in the included hook.

Hope that helps.


#3

Nice one - thank you


#4

I’m struggling with dependencies in an addon right now. Is there any documentation? This is a great summary but I need a little more help figuring out how to make all of the dependencies I’ll need play nice.

Thanks!


#5

Wayne can you please post back your findings and examples on getting this to work with integration tests? Thanks!


#6

Actually, I found the answer finally.

in ember-cli-build.js file

'use strict';

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
  let app = new EmberAddon(defaults, {
    // Add options here
  });

  /*
    This build file specifies the options for the dummy test app of this
    addon, located in `/tests/dummy`
    This build file does *not* influence how the addon or the app using it
    behave. You most likely want to be modifying `./index.js` or app's build file
  */
  if (app.env === 'test') {
    app.import('vendor/ember/ember-template-compiler.js');
  }

  return app.toTree();
};