forked from happo/happo.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessSnapsInBundle.js
More file actions
37 lines (33 loc) · 917 Bytes
/
processSnapsInBundle.js
File metadata and controls
37 lines (33 loc) · 917 Bytes
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
const { VERBOSE = 'false' } = process.env;
export default async function processSnapsInBundle(
webpackBundle,
{ viewport, DomProvider, targetName },
) {
const [width, height] = viewport.split('x').map((s) => parseInt(s, 10));
const domProvider = new DomProvider({
webpackBundle,
width,
height,
});
const result = {
snapPayloads: [],
};
try {
await domProvider.init({ targetName });
// Disabling eslint here because we actually want to run things serially.
/* eslint-disable no-await-in-loop */
while (await domProvider.next()) {
if (VERBOSE === 'true') {
console.log(`Viewport ${viewport}`);
}
const payload = await domProvider.processCurrent();
result.snapPayloads.push(payload);
}
result.css = await domProvider.extractCSS();
} catch (e) {
throw e;
} finally {
await domProvider.close();
}
return result;
}