Skip to content

Commit

Permalink
Merge pull request #15 from trentmwillis/preload-assets
Browse files Browse the repository at this point in the history
Introduce preload-assets helper for testing
  • Loading branch information
trentmwillis committed Aug 25, 2016
2 parents 5c89b39 + ce07c01 commit ac7d743
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ var app = new EmberApp(defaults, {
});
```

## Pre-loading Assets During Testing

For test environments it is often useful to load all of the assets in a manifest upfront. You can do this by using the
`preloadAssets` helper, like so:

```js
// tests/test-helper.js
import preloadAssets from 'ember-asset-loader/test-support/preload-assets';
import manifest from 'app/asset-manifest';

preloadAssets(manifest);
```

## Installation

* `git clone https://github.com/trentmwillis/ember-asset-loader`
Expand Down
23 changes: 23 additions & 0 deletions addon-test-support/preload-assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Ember from 'ember';
import AssetLoader from 'ember-asset-loader/services/asset-loader';

const { Test, RSVP } = Ember;

/**
* Preloads all the bundles specified in an asset manifest
* to make sure all files are available for testing.
*
* Uses the Ember.Test.Promise class to make sure tests
* wait for the assets to load first.
*
* @return {Promise}
*/
export default function preloadAssets(manifest) {
const loader = AssetLoader.create();
loader.pushManifest(manifest);

const bundlePromises = Object.keys(manifest.bundles).map((bundle) => loader.loadBundle(bundle));
const allBundles = RSVP.all(bundlePromises);

return Test.resolve(allBundles);
}

0 comments on commit ac7d743

Please sign in to comment.