Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions bin/phantomas.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const { getProgram, parseArgv } = require("./program"),
phantomas = require(".."),
debug = require("debug")("phantomas:cli");

var url = "";

// parse command line arguments
let options = parseArgv(process.argv);

Expand All @@ -25,7 +23,7 @@ if (typeof options.url !== "string" && typeof options.config === "undefined") {
process.exit(1);
}

url = options.url;
const url = options.url;
debug("url: %s", url);

delete options.url;
Expand Down
50 changes: 25 additions & 25 deletions bin/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function getProgram() {
program
.name("phantomas")
.description(
"Headless Chromium-based web performance metrics collector and monitoring tool"
"Headless Chromium-based web performance metrics collector and monitoring tool",
)
.version(phantomas.version)
.usage("--url <url> [options]")
Expand All @@ -27,15 +27,15 @@ function getProgram() {
.option("-d, --debug", "run phantomas in debug mode")
.option(
"--modules <modules>",
"run selected modules only [moduleOne],[moduleTwo],..."
"run selected modules only [moduleOne],[moduleTwo],...",
)
.option(
"--include-dirs <dirs>",
"load modules from specified directories [dirOne],[dirTwo],..."
"load modules from specified directories [dirOne],[dirTwo],...",
)
.option(
"--skip-modules <modules>",
"skip selected modules [moduleOne],[moduleTwo],..."
"skip selected modules [moduleOne],[moduleTwo],...",
)

// .option(
Expand All @@ -54,78 +54,78 @@ function getProgram() {
// HTTP options
.option(
"--auth-user <user>",
"sets the user name used for HTTP authentication"
"sets the user name used for HTTP authentication",
)
.option(
"--auth-pass <password>",
"sets the password used for HTTP authentication"
"sets the password used for HTTP authentication",
)
.option(
"--cookie <cookies>",
'document.cookie formatted string for setting a single cookie (e.g. "bar=foo;domain=url")'
'document.cookie formatted string for setting a single cookie (e.g. "bar=foo;domain=url")',
)
.option(
"--cookies-file <file>",
"specifies the file name to store the persistent Cookies"
"specifies the file name to store the persistent Cookies",
)
.option(
"--local-storage <values>",
'ability to set a local storage, key-value pairs (e.g. "bar=foo;domain=url")'
'ability to set a local storage, key-value pairs (e.g. "bar=foo;domain=url")',
)
.option(
"--session-storage <values>",
'ability to set a session storage, key-value pairs (e.g. "bar=foo;domain=url")'
'ability to set a session storage, key-value pairs (e.g. "bar=foo;domain=url")',
)
.option(
"--ignore-ssl-errors",
"ignores SSL errors, such as expired or self-signed certificate errors"
"ignores SSL errors, such as expired or self-signed certificate errors",
)
.option(
"--proxy <host:port>",
"specifies the proxy server to use (e.g. --proxy=192.168.1.42:8080)"
"specifies the proxy server to use (e.g. --proxy=192.168.1.42:8080)",
)
.option(
"--proxy-auth <username:password>",
"specifies the authentication information for the proxy"
"specifies the authentication information for the proxy",
)
.option(
"--proxy-type <type>",
"specifies the type of the proxy server [http|socks5|none]"
"specifies the type of the proxy server [http|socks5|none]",
)
.option(
"--ssl-protocol <protocol>",
"sets the SSL protocol for secure connections [sslv3|sslv2|tlsv1|any]"
"sets the SSL protocol for secure connections [sslv3|sslv2|tlsv1|any]",
)

// Runtime options
.option(
"--allow-domain <domain>",
"allow requests to given domain(s) - aka whitelist [domain],[domain],..."
"allow requests to given domain(s) - aka whitelist [domain],[domain],...",
)
.option(
"--block-domain <domain>",
"disallow requests to given domain(s) - aka blacklist [domain],[domain],..."
"disallow requests to given domain(s) - aka blacklist [domain],[domain],...",
)
.option(
"--disable-js",
"disable JavaScript on the page that will be loaded"
"disable JavaScript on the page that will be loaded",
)
.option("--no-externals", "block requests to 3rd party domains")
.option(
"--post-load-delay <N>",
"wait X seconds before generating a report"
"wait X seconds before generating a report",
)
.option("--scroll", "scroll down the page when it's loaded")
.option("--spy-eval", "report calls to eval()")
.option("--stop-at-onload", "stop phantomas immediately after onload event")
.option("--timeout <seconds>", "timeout for phantomas run", 15)
.option(
"--wait-for-event <event>",
"wait for a given phantomas event before generating a report"
"wait for a given phantomas event before generating a report",
)
.option(
"--wait-for-selector <selector>",
"wait for an element matching given CSS selector before generating a report"
"wait for an element matching given CSS selector before generating a report",
)
.option("--scroll", "scroll down the page when it's loaded")

Expand All @@ -135,23 +135,23 @@ function getProgram() {
.option("--colors", "forces ANSI colors even when output is piped")
.option(
"--film-strip",
"register film strip when page is loading (a comma separated list of milliseconds can be passed)"
"register film strip when page is loading (a comma separated list of milliseconds can be passed)",
)
.option(
"--film-strip-dir <dir>",
"folder path to output film strip (default is ./filmstrip directory)"
"folder path to output film strip (default is ./filmstrip directory)",
)
.option("--har <file>", "save HAR to a given file")
.option("--log <file>", "log to a given file")
.option("--page-source", "save page source to file")
.option(
"--page-source-dir <dir>",
"folder path to output page source (default is ./html directory)"
"folder path to output page source (default is ./html directory)",
)
.option("--pretty", "render formatted JSON")
.option(
"--screenshot <file>",
"render the viewport to a given file once fully loaded"
"render the viewport to a given file once fully loaded",
)
.option("--full-page-screenshot", "enlarge the screenshot to full page")
.option("-s, --silent", "don't write anything to the console");
Expand Down
3 changes: 2 additions & 1 deletion bin/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const decamelize = require("decamelize");
// @ts-check
const decamelize = require("decamelize").default;

function decamelizeOptions(options) {
// decamelize option names as returned by commander (see issue #863)
Expand Down
18 changes: 9 additions & 9 deletions core/modules/requestsMonitor/requestsMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function addContentType(headerValue, entry) {

default:
debug(
"Unknown content type found: " + value + " for <" + entry.url + ">"
"Unknown content type found: " + value + " for <" + entry.url + ">",
);
}

Expand Down Expand Up @@ -185,7 +185,7 @@ module.exports = function (phantomas) {
// request data
// https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#class-request
phantomas.emit("send", request); // @desc request has been sent
}
},
);

phantomas.on(
Expand Down Expand Up @@ -213,7 +213,7 @@ module.exports = function (phantomas) {
if (entry.transferedSize == 0) {
entry.transferedSize = parseInt(
entry.headers["content-length"] || "0",
10
10,
);
}

Expand All @@ -240,7 +240,7 @@ module.exports = function (phantomas) {
// resp.timing is empty when handling data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D
assert(
typeof resp.timing !== "undefined",
"resp.timing is empty when handling " + resp.url
"resp.timing is empty when handling " + resp.url,
);

// how long a given request stalled waiting for DNS, proxy, connection, SSL negotation, etc.
Expand Down Expand Up @@ -290,7 +290,7 @@ module.exports = function (phantomas) {
headerValue,
entry.bodySize / 1024,
entry.transferedSize / 1024,
entry.bodySize / entry.transferedSize
entry.bodySize / entry.transferedSize,
);
}

Expand Down Expand Up @@ -366,13 +366,13 @@ module.exports = function (phantomas) {
"recv: HTTP %d <%s> [%s]",
entry.status,
entry.url,
entry.contentType
entry.contentType,
);
phantomas.emit("recv", entry, resp); // @desc response has been received
}

phantomas.log("Response metadata: %j", entry);
}
},
);

// completion of the last HTTP request
Expand All @@ -382,7 +382,7 @@ module.exports = function (phantomas) {
phantomas.on("recv", (entry) =>
phantomas.setMetric(
"httpTrafficCompleted",
entry.recvEndTime - loadStartedTime
)
entry.recvEndTime - loadStartedTime,
),
);
};
2 changes: 1 addition & 1 deletion core/modules/timeToFirstByte/timeToFirstByte.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = function (phantomas) {
"Time to first byte: set to %d ms for request to <%s> (HTTP %d)",
entry.timeToFirstByte,
entry.url,
entry.status
entry.status,
);
phantomas.log("Time to last byte: set to %d ms", entry.timeToLastByte);

Expand Down
22 changes: 11 additions & 11 deletions core/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}

function getBacktrace() {
var stack = [];
let stack;

try {
throw new Error("backtrace");
Expand All @@ -81,7 +81,7 @@
}

function getCaller(stepBack) {
var caller = false;
let caller;

stepBack = stepBack || 0;

Expand Down Expand Up @@ -112,7 +112,7 @@
try {
origConsoleLog.call(
console,
"log:" + stringify(Array.prototype.slice.call(arguments))
"log:" + stringify(Array.prototype.slice.call(arguments)),
);
// eslint-disable-next-line no-empty
} catch (e) {}
Expand Down Expand Up @@ -192,7 +192,7 @@
phantomas.log(
"Spying " +
(enabled ? "enabled" : "disabled") +
(reason ? " - " + reason : "")
(reason ? " - " + reason : ""),
);
}

Expand All @@ -208,7 +208,7 @@
phantomas.log(
'spy: attaching to "%s" function%s',
fn,
reportResults ? " with results reporting" : ""
reportResults ? " with results reporting" : "",
);

obj[fn] = function () {
Expand All @@ -218,7 +218,7 @@
if (enabled && typeof callback === "function") {
callback.apply(
this,
reportResults === true ? [results].concat(args) : args
reportResults === true ? [results].concat(args) : args,
);
}

Expand Down Expand Up @@ -266,8 +266,8 @@
* Example: body.logged_out.vis-public.env-production > div > div
*/
function getDOMPath(node, dontGoUpTheDom /* = false */) {
var path = [],
entry = "";
let path = [],
entry;

if (node === window) {
return "window";
Expand Down Expand Up @@ -303,8 +303,8 @@
0,
Array.prototype.indexOf.call(
node.parentNode.children || node.parentNode.childNodes,
node
)
node,
),
) +
"]";
}
Expand All @@ -329,6 +329,6 @@
phantomas.log(
"phantomas page scope initialized for <%s> (is an iframe: %s)",
window.location.toString(),
window.parent !== window
window.parent !== window,
);
})(window);
44 changes: 22 additions & 22 deletions examples/config.json.example
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"url": "http://phantomjs.org",
"verbose": true,
"reporter": "tap:no-skip",
"block-domain": "google-analytics.com, amazonaws.com",
"cookies": [
{
"name": "mobile",
"value": "on",
"domain": ".phantomjs.org"
},
{
"name": "foo",
"value": "bar"
}
],
"asserts": {
"requests": 12,
"redirects": 0,
"domains": 2,
"timeToFirstByte": 600,
"httpTrafficCompleted": 1000
}
"url": "http://phantomjs.org",
"verbose": true,
"reporter": "tap:no-skip",
"block-domain": "google-analytics.com, amazonaws.com",
"cookies": [
{
"name": "mobile",
"value": "on",
"domain": ".phantomjs.org"
},
{
"name": "foo",
"value": "bar"
}
],
"asserts": {
"requests": 12,
"redirects": 0,
"domains": 2,
"timeToFirstByte": 600,
"httpTrafficCompleted": 1000
}
}
2 changes: 1 addition & 1 deletion examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ promise.on("recv", (response) => {
response.method,
response.url,
response.contentType,
response.httpVersion
response.httpVersion,
);
});

Expand Down
Loading
Loading