Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions addon/initializers/nprogress.js
Original file line number Diff line number Diff line change
@@ -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
};
1 change: 1 addition & 0 deletions app/initializers/nprogress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, initialize } from 'ember-cli-nprogress/initializers/nprogress';
2 changes: 1 addition & 1 deletion blueprints/ember-cli-nprogress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
};
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
33 changes: 33 additions & 0 deletions tests/acceptance/run-loop-test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Router = Ember.Router.extend({
});

Router.map(function() {
this.route('some-other-route');
});

export default Router;
16 changes: 16 additions & 0 deletions tests/dummy/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -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();
}
}
});
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h2 id="title">Welcome to Ember</h2>
<div id='nprogress-parent'></div>

{{outlet}}
3 changes: 3 additions & 0 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Hello, world!</h1>

{{link-to 'Some other route' 'some-other-route'}}
2 changes: 2 additions & 0 deletions tests/dummy/app/templates/some-other-route.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Some Other Route</h1>

23 changes: 23 additions & 0 deletions tests/unit/initializers/nprogress-test.js
Original file line number Diff line number Diff line change
@@ -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);
});