Skip to content

Commit cceaf1e

Browse files
committed
test: add test for options/flags
1 parent 81c91d0 commit cceaf1e

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ function open(options, fileName) {
1414
plugin.error('Unable to locate file: ' + fileName);
1515
}
1616

17-
if (process.platform.match(/^win/)) {
18-
// a shell call using only the filename
19-
child.exec('start ' + fileName);
20-
} else if (process.platform.match(/^linux/)) {
21-
// xdg-open is fairly reliable
22-
child.exec('xdg-open ' + JSON.stringify(fileName));
23-
} else {
24-
// assume it's Mac OS X, which uses `open()`
25-
child.exec('open ' + JSON.stringify(fileName));
26-
}
17+
var cmd;
18+
if (process.platform.match(/^win/))
19+
cmd = 'start';
20+
else if (process.platform.match(/^linux/))
21+
cmd = 'xdg-open';
22+
else // assume it's Mac OS X, which uses `open`
23+
cmd = 'open';
24+
25+
child.exec(cmd + ' ' + JSON.stringify(fileName));
2726
return '';
2827
}
2928

test/test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,35 @@ describe('plugin-open', function () {
7575
(typeof pluginOpen.open).should.equal('function');
7676
});
7777

78+
it('does not accept options/flags', function () {
79+
/*
80+
* Plugins are an easy way of specifying what options/flags your command
81+
* supports
82+
*/
83+
var ret = shell.open('-f', 'test');
84+
ret.code.should.equal(1);
85+
ret.stdout.should.equal('');
86+
var errorMsg = 'open: option not recognized: f';
87+
ret.stderr.should.equal(errorMsg);
88+
// TODO(nate): refactor ShellJS to support this
89+
// shell.error().should.equal(errorMsg);
90+
});
91+
7892
it('cannot open files that are missing', function () {
7993
var ret = shell.open('missingFile.txt');
8094
ret.code.should.equal(1);
8195
ret.stdout.should.equal('');
82-
ret.stderr.should.equal('open: Unable to locate file: missingFile.txt');
96+
var errorMsg = 'open: Unable to locate file: missingFile.txt';
97+
ret.stderr.should.equal(errorMsg);
98+
// TODO(nate): refactor ShellJS to support this
99+
// shell.error().should.equal(errorMsg);
83100
});
84101

85102
it('opens URLs', function () {
86103
var ret = shell.open('https://www.google.com');
87104
ret.code.should.equal(0);
88105
assert.ok(!ret.stderr);
106+
assert.ok(!shell.error());
89107
});
90108

91109
it('opens files asynchronously', function () {
@@ -95,6 +113,7 @@ describe('plugin-open', function () {
95113
ret.code.should.equal(0);
96114
ret.stdout.should.equal('');
97115
assert.ok(!ret.stderr);
116+
assert.ok(!shell.error());
98117
});
99118

100119
it('handles glob characters', function () {
@@ -106,5 +125,6 @@ describe('plugin-open', function () {
106125
ret.code.should.equal(0);
107126
ret.stdout.should.equal('');
108127
assert.ok(!ret.stderr);
128+
assert.ok(!shell.error());
109129
});
110130
});

0 commit comments

Comments
 (0)