Skip to content

Commit

Permalink
add test for the case where Electron binary is directly executed
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Nov 3, 2017
1 parent 874f827 commit 57e116b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions test/main/initial_path_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,43 @@ describe('#initial_path()', () => {
});

it('returns cwd when no argument is specified in general platform', () => {
process.argv = [];
assert(initial_path('') === process.cwd());
process.argv = argv();
assert.equal(initial_path(''), process.cwd());
});

it('returns document directory if started with Shiba.app in darwin', () => {
if (process.platform === 'darwin') {
process.argv = [];
process.argv = argv();
process.chdir('/');
assert(/Documents$/.test(initial_path('')));
}
});

it('returns the specified path if it exists', () => {
process.argv = argv('./README.md');
assert(initial_path('') === path.resolve('./README.md'));
assert.equal(initial_path(''), path.resolve('./README.md'));
});

it('returns default path if specified path does not exist', () => {
process.argv = argv('/this/file/does/not/exist');
assert(initial_path('') === process.cwd());
assert.equal(initial_path(''), process.cwd());
});

it('returns the last argument of argv if multiple argument specified', () => {
process.argv = argv('foo', 'bar', './README.md');
assert(initial_path('') === path.resolve('./README.md'));
assert.equal(initial_path(''), path.resolve('./README.md'));
});

it('considers the case where the Electron binary is directly executed', () => {
let exe = '/path/to/Shiba';
if (process.platform === 'win32') {
exe = 'C:\\path\\to\\Shiba.exe';
}

process.argv = [exe];
assert.equal(initial_path(''), process.cwd());

process.argv = [exe, './README.md'];
assert.equal(initial_path(''), path.resolve('./README.md'));
});
});

0 comments on commit 57e116b

Please sign in to comment.