-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
68 lines (64 loc) · 2.53 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
import test from 'ava';
import windows, {UnknownBrowserError} from './windows.js';
import defaultBrowser from './index.js';
test('sane', async t => {
const {id} = await defaultBrowser();
console.log('Default browser', id);
t.regex(id, /^(com|org)\./);
});
test('windows parsing', async t => {
const cases = [
{
output: '\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice\r\n ProgId REG_SZ AppXq0fevzme2pys62n3e0fbqa7peapykr8v\r\n\r\n',
expected: 'com.microsoft.edge.old',
},
{
output: '\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice\r\n ProgId REG_SZ MSEdgeDHTML\r\n\r\n',
expected: 'com.microsoft.edge',
},
{
output: '\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice\r\n ProgId REG_SZ ChromeHTML\r\n\r\n',
expected: 'com.google.chrome',
},
{
output: '\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice\r\n ProgId REG_SZ IE.HTTP\r\n\r\n',
expected: 'com.microsoft.ie',
},
{
output: '\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice\r\n ProgId REG_SZ FirefoxURL\r\n\r\n',
expected: 'org.mozilla.firefox',
},
{
output: '\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice\r\n ProgId REG_SZ BraveHTML\r\n\r\n',
expected: 'com.brave.Browser',
},
{
output: '\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice\r\n ProgId REG_SZ BraveSSHTM\r\n\r\n',
expected: 'com.brave.Browser.nightly',
},
{
output: '\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice\r\n ProgId REG_SZ BraveBHTML\r\n\r\n',
expected: 'com.brave.Browser.beta',
},
{
output: '\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice\r\n ProgId REG_SZ Potato\r\n\r\n',
expected: undefined,
},
{
output:
'',
expected: undefined,
},
];
await Promise.all(cases.map(async testCase => {
let actual;
try {
actual = await windows(async () => ({stdout: testCase.output}));
} catch (error) {
if (!(error instanceof UnknownBrowserError)) {
throw error;
}
}
t.is(actual && actual.id, testCase.expected);
}));
});