forked from opallabs/castelet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
100 lines (91 loc) · 2.08 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
90
91
92
93
94
95
96
97
98
99
100
import test from 'ava'
import { createPool } from '.'
test('creates a pool', async t => {
const pool = await createPool()
t.is(pool.size, 0)
pool.close()
})
test('acquires a browser', async t => {
t.plan(1)
const pool = await createPool({ min: 1 })
await pool.acquire().then(() => {
t.pass()
})
pool.close()
})
test('cannot acquire another', async t => {
const pool = await createPool({ min: 1 })
const browser = await pool.acquire()
t.not(browser, undefined)
let flag = false
pool.acquire().then(() => {
flag = true
})
t.is(flag, false)
pool.close()
})
test('can release a browser ', async t => {
t.plan(3)
const pool = await createPool({ min: 1 })
const browser = await pool.acquire()
t.not(browser, undefined)
let flag = false
pool.acquire().then(() => {
flag = true
})
t.is(flag, false)
await pool.release(browser)
t.pass()
pool.close()
})
test('acquires after release', async t => {
t.plan(2)
const pool = await createPool({ min: 1 })
const browser = await pool.acquire()
t.not(browser, undefined)
pool.acquire().then(() => {
t.pass()
})
await pool.release(browser)
pool.close()
})
test('can use a browser', async t => {
t.plan(3)
const pool = await createPool({ min: 1 })
let theBrowser
await pool.use(browser => {
theBrowser = browser
t.not(browser, undefined)
t.is(pool.isAcquired(browser), true)
})
t.is(pool.isAcquired(theBrowser), false)
pool.close()
})
test('handles errors in use usage', async t => {
t.plan(2)
const pool = await createPool({ min: 1 })
try {
await pool.use(() => {
throw new Error('Noooooo!')
})
} catch (e) {
t.pass()
t.is(pool.acquired, 0)
}
pool.close()
})
test('terminates', async t => {
t.plan(1)
const pool = await createPool({ min: 1 })
pool.terminate(t.pass)
})
test('destroys browsers', async t => {
t.plan(2)
const pool = await createPool({ min: 1 })
const browser = await pool.acquire()
t.not(browser, undefined)
pool.destroy(browser)
const newBrowser = await pool.acquire()
t.not(browser, newBrowser)
pool.close()
})