|
1 | | -const puppeteer = require("puppeteer"); |
2 | | -const filterConsole = require("filter-console"); |
3 | | -const tracealyzer = require("tracealyzer"); |
4 | | -const { getPerformanceModel } = require("headless-devtools"); |
| 1 | +import P from 'puppeteer' |
| 2 | +import filterConsole from 'filter-console' |
| 3 | +import tracealyzer from 'tracealyzer' |
| 4 | +import { getPerformanceModel } from 'headless-devtools' |
5 | 5 |
|
6 | | -exports.filterConsole = function () { |
7 | | - filterConsole(["Failed to parse CPU profile."]); |
8 | | -}; |
| 6 | +export function filterConsoleImpl () { |
| 7 | + filterConsole(['Failed to parse CPU profile.']) |
| 8 | +} |
9 | 9 |
|
10 | | -exports.launchImpl = function (args) { |
| 10 | +export function launchImpl (args) { |
11 | 11 | return function () { |
12 | | - return puppeteer.launch(args); |
13 | | - }; |
14 | | -}; |
| 12 | + return P.launch(args) |
| 13 | + } |
| 14 | +} |
15 | 15 |
|
16 | | -exports.newPageImpl = function (browser) { |
17 | | - return browser.newPage(); |
18 | | -}; |
| 16 | +export function newPageImpl (browser) { |
| 17 | + return browser.newPage() |
| 18 | +} |
19 | 19 |
|
20 | | -exports.debugImpl = function (page) { |
21 | | - page.on("console", (msg) => console.log("PAGE LOG:", msg.text())); |
22 | | - page.on("pageerror", (err) => console.log("ERROR LOG:", err.message)); |
23 | | -}; |
| 20 | +export function debugImpl (page) { |
| 21 | + page.on('console', msg => console.log('PAGE LOG:', msg.text())) |
| 22 | + page.on('pageerror', err => console.log('ERROR LOG:', err.message)) |
| 23 | +} |
24 | 24 |
|
25 | | -exports.clickImpl = function (elem) { |
26 | | - return elem.click(); |
27 | | -}; |
| 25 | +export function clickImpl (elem) { |
| 26 | + return elem.click() |
| 27 | +} |
28 | 28 |
|
29 | | -exports.waitForSelectorImpl = function (page, selector) { |
30 | | - return page.waitForSelector(selector); |
31 | | -}; |
| 29 | +export function waitForSelectorImpl (page, selector) { |
| 30 | + return page.waitForSelector(selector) |
| 31 | +} |
32 | 32 |
|
33 | | -exports.focusImpl = function (page, selector) { |
34 | | - return page.focus(selector); |
35 | | -}; |
| 33 | +export function focusImpl (page, selector) { |
| 34 | + return page.focus(selector) |
| 35 | +} |
36 | 36 |
|
37 | | -exports.typeWithKeybordImpl = function (page, string) { |
38 | | - return page.keyboard.type(string); |
39 | | -}; |
| 37 | +export function typeWithKeybordImpl (page, string) { |
| 38 | + return page.keyboard.type(string) |
| 39 | +} |
40 | 40 |
|
41 | | -exports.gotoImpl = function (page, path) { |
42 | | - return page.goto(path); |
43 | | -}; |
| 41 | +export function gotoImpl (page, path) { |
| 42 | + return page.goto(path) |
| 43 | +} |
44 | 44 |
|
45 | | -exports.closePageImpl = function (page) { |
46 | | - return page.close(); |
47 | | -}; |
| 45 | +export function closePageImpl (page) { |
| 46 | + return page.close() |
| 47 | +} |
48 | 48 |
|
49 | | -exports.closeBrowserImpl = function (browser) { |
50 | | - return browser.close(); |
51 | | -}; |
| 49 | +export function closeBrowserImpl (browser) { |
| 50 | + return browser.close() |
| 51 | +} |
52 | 52 |
|
53 | | -exports.enableHeapProfilerImpl = function (page) { |
54 | | - return page._client.send("HeapProfiler.enable"); |
55 | | -}; |
| 53 | +export function enableHeapProfilerImpl (page) { |
| 54 | + return page._client.send('HeapProfiler.enable') |
| 55 | +} |
56 | 56 |
|
57 | | -exports.collectGarbageImpl = function (page) { |
58 | | - return page._client.send("HeapProfiler.collectGarbage"); |
59 | | -}; |
| 57 | +export function collectGarbageImpl (page) { |
| 58 | + return page._client.send('HeapProfiler.collectGarbage') |
| 59 | +} |
60 | 60 |
|
61 | | -exports.startTraceImpl = function (page, path) { |
62 | | - return page.tracing.start({ path }); |
63 | | -}; |
| 61 | +export function startTraceImpl (page, path) { |
| 62 | + return page.tracing.start({ path }) |
| 63 | +} |
64 | 64 |
|
65 | | -exports.stopTraceImpl = function (page) { |
66 | | - return page.tracing.stop(); |
67 | | -}; |
| 65 | +export function stopTraceImpl (page) { |
| 66 | + return page.tracing.stop() |
| 67 | +} |
68 | 68 |
|
69 | 69 | // Should be used on the trace produced by `page.tracing.stop()` |
70 | | -exports.getPerformanceModelImpl = function (trace) { |
| 70 | +export function getPerformanceModelImpl (trace) { |
71 | 71 | try { |
72 | | - const traceJSON = JSON.parse(trace.toString()); |
73 | | - return getPerformanceModel(traceJSON); |
| 72 | + const traceJSON = JSON.parse(trace.toString()) |
| 73 | + return getPerformanceModel(traceJSON) |
74 | 74 | } catch (e) { |
75 | | - return null; |
| 75 | + return null |
76 | 76 | } |
77 | | -}; |
| 77 | +} |
78 | 78 |
|
79 | 79 | // Should be used on the model returned by `getPeformanceModel` |
80 | | -exports.getAverageFPS = function (model) { |
81 | | - const frames = model.frames(); |
82 | | - const durations = frames.map((x) => x.duration); |
83 | | - const avg = durations.reduce((acc, item) => acc + item, 0) / durations.length; |
84 | | - return Math.round(1000 / avg); |
85 | | -}; |
86 | | - |
87 | | -exports.pageMetricsImpl = function (page) { |
88 | | - return page.metrics(); |
89 | | -}; |
90 | | - |
91 | | -exports.tracealyzer = function (filename) { |
| 80 | +export function getAverageFPS (model) { |
| 81 | + const frames = model.frames() |
| 82 | + const durations = frames.map(x => x.duration) |
| 83 | + const avg = durations.reduce((acc, item) => acc + item, 0) / durations.length |
| 84 | + return Math.round(1000 / avg) |
| 85 | +} |
| 86 | + |
| 87 | +export function pageMetricsImpl (page) { |
| 88 | + return page.metrics() |
| 89 | +} |
| 90 | + |
| 91 | +export function tracealyzerImpl (filename) { |
92 | 92 | return function () { |
93 | | - return tracealyzer(filename); |
94 | | - }; |
95 | | -}; |
| 93 | + return tracealyzer(filename) |
| 94 | + } |
| 95 | +} |
0 commit comments