-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.spec.ts
77 lines (65 loc) · 1.82 KB
/
index.spec.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
77
import puppeteerPool, { IBrowser } from './index';
import { Pool } from 'generic-pool';
const getState = ({size, available, pending, max, min}) => {
return {size, available, pending, max, min};
};
const inUse = ({size, available}) => size - available;
xdescribe('PuppeteerPool', () => {
let pool: Pool<IBrowser>;
beforeAll(async () => {
pool = await puppeteerPool();
});
describe('initialize', () => {
it('Should acquire new instance', async () => {
const instance = await pool.acquire();
const page = await instance.newPage();
const viewportSize = await page.viewport();
expect(viewportSize.width).toBe(800);
expect(viewportSize.height).toBe(600);
await pool.release(instance);
});
});
describe('availability', () => {
let instances;
let firstInstance;
let otherInstances;
beforeAll(async () => {
instances = await Promise.all([
pool.acquire(),
pool.acquire(),
pool.acquire(),
pool.acquire(),
]);
[firstInstance, ...otherInstances] = instances;
});
it('pool should have 0 available instances', async () => {
expect(getState(pool)).toEqual({
available: 0,
pending: 0,
max: 10,
min: 2,
size: 4
});
});
it('pool should have 1 available instances', async () => {
await pool.release(firstInstance);
expect(getState(pool)).toEqual({
available: 1,
pending: 0,
max: 10,
min: 2,
size: 4
});
});
it('pool should have 4 available instances', async () => {
await Promise.all(otherInstances.map(instance => pool.release(instance)));
expect(getState(pool)).toEqual({
available: 4,
pending: 0,
max: 10,
min: 2,
size: 4
});
});
});
});