diff --git a/addon/initializers/nprogress.js b/addon/initializers/nprogress.js new file mode 100644 index 0000000..4965acc --- /dev/null +++ b/addon/initializers/nprogress.js @@ -0,0 +1,15 @@ +import Ember from 'ember'; +import nprogress from 'ember-cli-nprogress'; + +const { run } = Ember; + +export const scheduler = run.later.bind(undefined, undefined); + +export function initialize() { + nprogress.configure({ scheduler }); +} + +export default { + name: 'nprogress', + initialize +}; diff --git a/app/initializers/nprogress.js b/app/initializers/nprogress.js new file mode 100644 index 0000000..f413475 --- /dev/null +++ b/app/initializers/nprogress.js @@ -0,0 +1 @@ +export { default, initialize } from 'ember-cli-nprogress/initializers/nprogress'; diff --git a/blueprints/ember-cli-nprogress/index.js b/blueprints/ember-cli-nprogress/index.js index 8a5b589..a0d0352 100644 --- a/blueprints/ember-cli-nprogress/index.js +++ b/blueprints/ember-cli-nprogress/index.js @@ -2,6 +2,6 @@ module.exports = { normalizeEntityName: function() {}, // no-op since we're just adding dependencies afterInstall: function() { - return this.addBowerPackageToProject('nprogress', '^0.2.0'); + return this.addBowerPackageToProject('nprogress', 'alexlafroscia/nprogress#allow-alternate-scheduler'); } }; diff --git a/bower.json b/bower.json index 1e620ee..409021a 100644 --- a/bower.json +++ b/bower.json @@ -3,6 +3,6 @@ "dependencies": { "ember": "~2.10.0", "ember-cli-shims": "0.1.3", - "nprogress": "^0.2.0" + "nprogress": "alexlafroscia/nprogress#allow-alternate-scheduler" } } diff --git a/tests/acceptance/run-loop-test.js b/tests/acceptance/run-loop-test.js new file mode 100644 index 0000000..8979d80 --- /dev/null +++ b/tests/acceptance/run-loop-test.js @@ -0,0 +1,33 @@ +import { test } from 'qunit'; +import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; + +import nprogress from 'ember-cli-nprogress'; + +// Note: This somewhat unorthidox test setup will throw an error when running the tests in Chrome, +// if `nprogress` isn't configured to run within the Ember run loop +moduleForAcceptance('Acceptance | run loop', { + beforeEach() { + nprogress.configure({ + parent: '#nprogress-parent' + }); + } +}); + +// This is required to get the app set up +test('loading an initial route', function(assert) { + assert.expect(0); + + visit('/'); +}); + +// This test just verifies that an error is not produced in cases where `nprogress` +// is running while the app is being torn down +test('it fires the `start` event within the run loop', function(assert) { + visit('/'); + + click('a'); + + andThen(function() { + assert.equal(currentURL(), '/some-other-route'); + }); +}); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index cdc2578..26d757a 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -7,6 +7,7 @@ const Router = Ember.Router.extend({ }); Router.map(function() { + this.route('some-other-route'); }); export default Router; diff --git a/tests/dummy/app/routes/application.js b/tests/dummy/app/routes/application.js new file mode 100644 index 0000000..fd9d00f --- /dev/null +++ b/tests/dummy/app/routes/application.js @@ -0,0 +1,16 @@ +import Ember from 'ember'; +import nprogress from 'ember-cli-nprogress'; + +const { Route } = Ember; + +export default Route.extend({ + actions: { + willTransition() { + nprogress.start(); + }, + + didTransition() { + nprogress.done(); + } + } +}); diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index f8bc38e..1a41fa0 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1,3 +1,3 @@ -

Welcome to Ember

+
{{outlet}} diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs new file mode 100644 index 0000000..1be8b17 --- /dev/null +++ b/tests/dummy/app/templates/index.hbs @@ -0,0 +1,3 @@ +

Hello, world!

+ +{{link-to 'Some other route' 'some-other-route'}} diff --git a/tests/dummy/app/templates/some-other-route.hbs b/tests/dummy/app/templates/some-other-route.hbs new file mode 100644 index 0000000..557c7ab --- /dev/null +++ b/tests/dummy/app/templates/some-other-route.hbs @@ -0,0 +1,2 @@ +

Some Other Route

+ diff --git a/tests/unit/initializers/nprogress-test.js b/tests/unit/initializers/nprogress-test.js new file mode 100644 index 0000000..664fb12 --- /dev/null +++ b/tests/unit/initializers/nprogress-test.js @@ -0,0 +1,23 @@ +import Ember from 'ember'; +import { module, test } from 'qunit'; + +import NprogressInitializer from 'dummy/initializers/nprogress'; +import { scheduler } from 'ember-cli-nprogress/initializers/nprogress'; +import nprogress from 'ember-cli-nprogress'; + +let application; + +module('Unit | Initializer | nprogress', { + beforeEach() { + Ember.run(function() { + application = Ember.Application.create(); + application.deferReadiness(); + }); + } +}); + +test('it sets up an Ember-friendly scheduler function', function(assert) { + NprogressInitializer.initialize(application); + + assert.equal(nprogress.settings.scheduler, scheduler); +});