-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
test.js
89 lines (70 loc) · 2.68 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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('wait for the app to close if wait: true', async () => {
await open('https://sindresorhus.com', {wait: true});
});
test('encode URL if url: true', async () => {
await open('https://sindresorhus.com', {url: true});
});
test('open URL in default app', async () => {
await open('https://sindresorhus.com');
});
test('open URL in specified app', async () => {
await open('https://sindresorhus.com', {app: firefoxName});
});
test('open URL in specified app with arguments', async () => {
await open('https://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);
});
test('open URL with query strings', async () => {
await open('https://sindresorhus.com/?abc=123&def=456');
});
test('open URL with a fragment', async () => {
await open('https://sindresorhus.com#projects');
});
test('open URL with query strings and spaces', async () => {
await open('https://sindresorhus.com/?abc=123&def=456&ghi=with spaces');
});
test('open URL with query strings and a fragment', async () => {
await open('https://sindresorhus.com/?abc=123&def=456#projects');
});
test('open URL with query strings and pipes', async () => {
await open('https://sindresorhus.com/?abc=123&def=456&ghi=w|i|t|h');
});
test('open URL with query strings, spaces, pipes and a fragment', async () => {
await open('https://sindresorhus.com/?abc=123&def=456&ghi=w|i|t|h spaces#projects');
});
if (isWsl) {
test('open URL in specified windows app given a wsl path to the app', async () => {
await open('https://sindresorhus.com', {app: firefoxWslName});
});
test('open URL in specified windows app with arguments given a wsl path to the app', async () => {
await open('https://sindresorhus.com', {app: [chromeWslName, '--incognito']});
});
}