forked from sindresorhus/open
/
test.js
61 lines (49 loc) · 1.8 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import test from 'ava';
import isWsl from 'is-wsl';
import open from '.';
let chromeName;
let firefoxName;
let chromeWslName;
let firefoxWslName;
if (process.platform === 'darwin') {
chromeName = 'google chrome canary';
firefoxName = 'firefox';
} else if (process.platform === 'win32' || isWsl) {
chromeName = 'Chrome';
firefoxName = 'C:\\Program Files\\Mozilla Firefox\\firefox.exe';
chromeWslName = '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe';
firefoxWslName = '/mnt/c/Program Files/Mozilla Firefox/firefox.exe';
} else if (process.platform === 'linux') {
chromeName = 'google-chrome';
firefoxName = 'firefox';
}
// Tests only checks that opening doesn't return an error
// it has no way make sure that it actually opened anything.
// These have to be manually verified.
test('open file in default app', async () => {
await open('index.js');
});
test('not wait for the app to close if wait: false', async () => {
await open('http://sindresorhus.com', {wait: false});
});
test('open url in default app', async () => {
await open('http://sindresorhus.com');
});
test('open url in specified app', async () => {
await open('http://sindresorhus.com', {app: firefoxName});
});
test('open url in specified app with arguments', async () => {
await open('http://sindresorhus.com', {app: [chromeName, '--incognito']});
});
test('return the child process when called', async t => {
const cp = await open('index.js');
t.true('stdout' in cp);
});
if (isWsl) {
test('open url in specified windows app given a wsl path to the app', async () => {
await open('http://sindresorhus.com', {app: firefoxWslName});
});
test('open url in specified windows app with arguments given a wsl path to the app', async () => {
await open('http://sindresorhus.com', {app: [chromeWslName, '--incognito']});
});
}