Repository navigation
Making addon dummy apps less special #119
Description
I would like to make dummy apps less of a special case. Right now they have some weird behaviors, like:
- ember-cli-build.js only really applies to the dummy app, but it appears at the root of the addon. This misleads people into thinking they can influence the addon's behavior by putting things in there.
- when building a dummy app, the
project.rootdirectory points at the true root of the addon repo, which is not the root of the dummy app itself. There is a Known Hack™️ for reliably getting the real app root likepath.join(project.configPath(), '../..'), sinceconfigPathdoes point at the right place for dummy apps. Due to this special case, many addons don't work correctly when you try to consume them inside a dummy app. - acceptance tests in
tests/acceptanceimplicitly run against the dummy app, which makes them different from what an app developer has come to expect. Now, obviously there is no other place for them to run against, but this is still a bit jarring when first encountered. ember-cli/lib/broccoli/ember-addonexists to build dummy apps, not addons (which makes its name confusing), and the only reason it needs to exist at all is that dummy apps are doing all these weird things.- I would argue
dummyis not a great name and we can come up with something more descriptive. Candidates includesample-apportest-harness-app. - Because the dummy app and the addon share a package.json, it's not possible to test what happens when an app depends on your addon but does not directly depend on your addon's own addon dependencies. In a dummy app, all the addon's dependencies are forced to be direct dependencies of the app too. For example, if you addon uses ember-cli-sass, you can't test what happens when your addon is used in an app that doesn't happen to also use ember-cli-sass.
The general shape of my proposal is:
-
move
./tests/dummyto./sample-appor whatever other name we bikeshed as a good default one. -
the root
ember-cli-build.jswould change to mostly delegating to./sample-app/ember-cli-build.js, in order to make it clear that there's no app config that lives at the root level. -
./sample-app/ember-cli-build.jswould importember-cli/lib/broccoli/ember-app, notember-cli/lib/broccoli/ember-addon(which would get deprecated) -
dummy apps would become 100% normal ember apps. They should have their own package.json (like
./sample-app/package.json), and you should be able tocd ./sample-app && ember sand everything works exactly as it would if you were in a normal standalone app. They can have the stock app.eslintrc.jsin their own directory, meaning no special lint rules are required. -
our previous work on fixing node_modules resolution means that a normal ember app located in
./sample-appis still able to access all the dependencies in./node_modules, so no special casing is required there. This also allows multiple dummy apps to choose to include only subsets of their parent addon's devDependencies just by not including them in the dummy app's package.json (this is already how ember-cli works -- no special cases for dummy apps). -
acceptance tests should live inside the app that they are testing. So today's
./tests/acceptancewould move to./sample-app/tests/acceptance. This makes them conform exactly to what app developers already know about acceptance tests. -
./tests/unitand./tests/integrationcan stay where they are, those test suites can (in principle) run even if you choose to have no dummy app at all.
The only chunk of API design that I see missing from the above is deciding in detail what to put into the top-level ember-cli-build such that you can conveniently
- run one or more dummy app's automatically in a single
ember sprocess. - run a test suite composed of the addon's own integration & unit tests
- run the above test suite and also run the tests in each of any number of dummy apps
A totally strawman example of the new top-level ember-cli-build.js would look like:
const AddonDevSetup = require('ember-cli/addon-dev-setup');
module.exports = new AddonDevSetup({
sampleApps: [
{
// the app we're loading
app: require('./sample-app/ember-cli-build.js'),
// where to mount the app in the ember development server. Could
// potentially allow seting to `null` if you don't want the app to start
// automatically when you do a top-level `ember s`.
rootURL: '/'
// whether to run this app's `ember test` when we do a top-level `ember test`
includeTests: true
}
]
});
Activity
kellyselden commentedon May 25, 2018
The first point has a PR ember-cli/ember-cli#7602
knownasilya commentedon Jun 13, 2018
Should these be split up and submitted as RFCs?
lennyburdette commentedon Jun 15, 2018
ember installornpm install --save-devinside the./sample-appdirectory?./sample-app/package.jsondoesn't include any packages not in the addon's package.json? Or would something like ember-cli-dependency-checker handle that for us?*for versions in the sample-app's package.json to suggest that the sample-app inherits its dependencies from the addon?Otherwise, 👍 ! I'm hoping that moving acceptance tests into the dummy app make engine tests easier. The sample-app application tests can run
setApplication(), while the engine's rendering/container tests usesetResolver(engineResolverFor(...)). Though I have no idea how that would work at runtime sincesetApplicationandsetResolverset global state ...ef4 commentedon Jun 15, 2018
Based on what I described, it would necessarily be possible to add dependencies directly to the dummy app if you really want to. I'm not sure we'd want to rule that out -- maybe you need to test your addon both with and without another dependency present. But if you do that, you will need to run
npm installin the dummy app.Sticking to a subset of the main package.json and using
*does seem like the sensible default behavior we should encourage.ef4 commentedon Aug 22, 2018
I edited the main post above to add another bad case I had forgotten about:
bravo-kernel commentedon Nov 2, 2018
From an end-user perspective I would really welcome the ability to create multiple dummy/sample apps.
ASH-Michael commentedon Nov 2, 2018
@bravo-kernel Isn't this already possible with routes in the dummy app?
bravo-kernel commentedon Nov 2, 2018
Not completely separated as far as I know. I think I need something like https://github.com/mansona/testing-mu to get what I'm after; completely isolating ember-addon-docs and my demo-app. Update: but I'm pretty new to Ember so I could be mistaken.
ASH-Michael commentedon Nov 2, 2018
@bravo-kernel I see what you are trying to accomplish now. Interesting.
rwjblue commentedon Jan 19, 2019
We are working on closing the ember-cli/rfcs repo in favor of using a single central RFC's repo for everything. This was laid out in https://emberjs.github.io/rfcs/0300-rfc-process-update.html.
Sorry for the troubles, but would you mind reviewing to see if this is still something we need, and if so migrating this over to emberjs/rfcs?