Skip to content

Commit

Permalink
Merge 15162aa into 88a8a04
Browse files Browse the repository at this point in the history
  • Loading branch information
saintsebastian committed Dec 16, 2016
2 parents 88a8a04 + 15162aa commit f768dd4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -57,6 +57,7 @@
"minimatch": "3.0.3",
"mz": "2.6.0",
"node-firefox-connect": "1.2.0",
"node-notifier": "4.6.1",
"regenerator-runtime": "0.10.1",
"parse-json": "2.2.0",
"sign-addon": "0.2.0",
Expand Down
14 changes: 14 additions & 0 deletions src/cmd/run.js
Expand Up @@ -9,9 +9,13 @@ import {
import {createLogger} from '../util/logger';
import getValidatedManifest, {getManifestId} from '../util/manifest';
import defaultSourceWatcher from '../watcher';
import {NotificationCenter as NC} from 'node-notifier';


const log = createLogger(__filename);
const notifier = new NC({
withFallback: true,
});


// Import objects that are only used as Flow types.
Expand All @@ -36,6 +40,7 @@ export type WatcherCreatorParams = {
sourceDir: string,
artifactsDir: string,
onSourceChange?: OnSourceChangeFn,
messenger?: NC,
};

export type WatcherCreatorFn = (params: WatcherCreatorParams) => Watchpack;
Expand All @@ -44,16 +49,25 @@ export function defaultWatcherCreator(
{
addonId, client, sourceDir, artifactsDir,
onSourceChange = defaultSourceWatcher,
messenger = notifier,
}: WatcherCreatorParams
): Watchpack {
return onSourceChange({
sourceDir,
artifactsDir,
onChange: () => {
log.debug(`Reloading add-on ID ${addonId}`);
messenger.notify({
title: 'Started reloading',
message: `Reloading add-on ID ${addonId}`,
});
return client.reloadAddon(addonId)
.catch((error) => {
log.error(error.stack);
messenger.notify({
title: 'Error occured',
message: error.message,
});
throw error;
});
},
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/test-cmd/test.run.js
Expand Up @@ -15,6 +15,7 @@ import {RemoteFirefox} from '../../../src/firefox/remote';
import {TCPConnectError, fakeFirefoxClient, makeSureItFails, fake, fixturePath}
from '../helpers';
import {createLogger} from '../../../src/util/logger';
import {NotificationCenter as NC} from 'node-notifier';

const log = createLogger(__filename);
// Fake result for client.installTemporaryAddon().then(installResult => ...)
Expand Down Expand Up @@ -240,6 +241,9 @@ describe('run', () => {
sourceDir: '/path/to/extension/source/',
artifactsDir: '/path/to/web-ext-artifacts',
onSourceChange: sinon.spy(() => {}),
messenger: fake(NC.prototype, {
notify: () => Promise.resolve(),
}),
};
return {
config,
Expand Down Expand Up @@ -282,6 +286,36 @@ describe('run', () => {
});
});

it('notifies user on reload', () => {
const {config, createWatcher} = prepare();
createWatcher();

const callArgs = config.onSourceChange.firstCall.args[0];
assert.equal(config.onSourceChange.called, true);
return callArgs.onChange()
.then(() => {
assert.equal(config.messenger.notify.called, true);
assert.equal(config.messenger.notify.firstCall.args[0].title,
'Started reloading');
});
});

it('notifies user on error from source change handler', () => {
const {config, createWatcher} = prepare();
config.client.reloadAddon = () => Promise.reject(new Error('an error'));
createWatcher();

assert.equal(config.onSourceChange.called, true);
// Simulate executing the handler when a source file changes.
return config.onSourceChange.firstCall.args[0].onChange()
.then(makeSureItFails())
.catch((error) => {
assert.equal(config.messenger.notify.called, true);
assert.equal(config.messenger.notify.lastCall.args[0].message,
error.message);
});
});

it('throws errors from source change handler', () => {
const {createWatcher, config} = prepare();
config.client.reloadAddon = () => Promise.reject(new Error('an error'));
Expand Down

0 comments on commit f768dd4

Please sign in to comment.