Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://github.com/mikaelbr/node-notifier/issues/99 #118

Merged
merged 3 commits into from
May 11, 2016
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
10 changes: 8 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var cp = require('child_process'),
os = require('os'),
fs = require('fs'),
url = require('url'),
path = require('path'),
shellwords = require('shellwords'),
semver = require('semver'),
Expand Down Expand Up @@ -222,7 +223,12 @@ module.exports.mapToWin8 = function (options){
options = mapText(options);

if(options.icon){
options.p = options.icon;
if (/^file:\/+/.test(options.icon)) {
// should parse file protocol URL to path
options.p = url.parse(options.icon).pathname.replace(/^\/(\w\:\/)/, "$1").replace(/\//g, "\\");
} else {
options.p = options.icon;
}
delete options.icon;
}

Expand Down Expand Up @@ -331,4 +337,4 @@ function garanteeSemverFormat (version) {
version += '.0';
}
return version;
}
}
76 changes: 76 additions & 0 deletions test/toaster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var Notify = require('../notifiers/toaster')
, should = require('should')
, path = require('path')
, utils = require('../lib/utils')
, os = require('os')
, assert = require('assert');

describe('WindowsToaster', function(){

before(function () {
this.original = utils.fileCommand;
this.originalType = os.type;
this.originalArch = os.arch;
this.originalRelease = os.release;
os.release = function () {
return "6.2.9200";
};
os.type = function () {
return "Windows_NT";
};
});

after(function () {
utils.fileCommand = this.original;
os.type = this.originalType;
os.arch = this.originalArch;
os.release = this.originalRelease;
});

it('should parse file protocol URL of icon', function (done) {
utils.fileCommand = function (notifier, argsList, callback) {
argsList[1].should.eql('C:\\node-notifier\\test\\fixture\\coulson.jpg');
done();
};

var notifier = new Notify();

notifier.notify({
'title': 'Heya',
'message': 'foo bar',
'icon': 'file:///C:/node-notifier/test/fixture/coulson.jpg'
});
});

it('should not parse local path of icon', function (done) {
var icon = path.join(__dirname, 'fixture', 'coulson.jpg');
utils.fileCommand = function (notifier, argsList, callback) {
argsList[1].should.eql(icon);
done();
};

var notifier = new Notify();

notifier.notify({
'title': 'Heya',
'message': 'foo bar',
'icon': icon
});
});

it('should not parse normal URL of icon', function (done) {
var icon = 'http://csscomb.com/img/csscomb.jpg';
utils.fileCommand = function (notifier, argsList, callback) {
argsList[1].should.eql(icon);
done();
};

var notifier = new Notify();

notifier.notify({
'title': 'Heya',
'message': 'foo bar',
'icon': icon
});
});
});