-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.ts
76 lines (66 loc) · 1.87 KB
/
test.ts
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
import { assert, assertEquals } from 'https://deno.land/std@0.122.0/testing/asserts.ts';
import { isAbsolute } from 'https://deno.land/std@0.122.0/path/posix.ts';
import { getDir, open } from './index.ts';
const { os } = Deno.build;
// Tests for open Deno package
let chromeName: string;
let firefoxName: string;
if (os === 'darwin') {
chromeName = '/Applications/Google\ Chrome.app';
firefoxName = 'firefox';
} else if (os === 'windows') {
chromeName = 'Chrome';
firefoxName = 'C:\\Program Files\\Mozilla Firefox\\firefox.exe';
} else if (os === 'linux') {
chromeName = 'google-chrome';
firefoxName = 'firefox';
}
function closeResourceHandles () {
const resourceIds = Object.keys(Deno.resources()).map(strId => parseInt(strId)).slice(3,)
resourceIds.forEach(id => Deno.close(id))
}
Deno.test({
name: 'getDir works',
fn(): void {
const currentDir = getDir(import.meta.url);
assert(isAbsolute(currentDir));
assertEquals(currentDir.substr(currentDir.length - 4, currentDir.length), 'open');
}
});
Deno.test({
name: 'open works without options',
async fn(): Promise<void> {
await open('index.ts');
closeResourceHandles()
}
});
Deno.test({
name: 'open waits',
async fn(): Promise<void> {
await open('test.png', { wait: true });
closeResourceHandles()
}
});
Deno.test({
name: 'url gets encoded',
async fn(): Promise<void> {
await open('https://google.com', { url: true });
closeResourceHandles()
}
});
Deno.test({
name: 'open works with arguments',
async fn(): Promise<void> {
await open('https://google.com', { app: [chromeName, '-incognito'] });
closeResourceHandles()
}
});
Deno.test({
name: 'returns process',
async fn(): Promise<void> {
const process: Deno.Process = await open('https://google.com');
assert(typeof process.pid === 'number');
assert(process.pid !== 0);
closeResourceHandles()
}
});