New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use variant for ignoreDefaultArgs launch option #88

Merged
merged 3 commits into from Sep 10, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+161 −62
Diff settings

Always

Just for now

Next

Use variant for ignoreDefaultArgs launch option

Enable passing either a bool or array(string) as ignoreDefaultArgs.
  • Loading branch information...
zploskey committed Sep 10, 2018
commit cadd87b30a01a415827f94f1e8454cf10d639332
Copy path View file
@@ -56,6 +56,21 @@ describe("Puppeteer", () => {
let args = defaultArgs(~options, ());
args |> Array.length |> expect |> toBeGreaterThan(0);
});

testPromise("should launch with ignoreDefaultArgs array of args", () => {
let ignoreDefaultArgs = IgnoreDefaultArgs.Args([|"--mute-audio"|]);
let options = makeLaunchOptions(~ignoreDefaultArgs, ());
Js.Promise.(
launch(~options, ())
|> then_(b =>
Js.Promise.all2((
Browser.close(b),
expect(b) |> ExpectJs.toBeTruthy |> resolve,
))
)
|> Js.Promise.then_(((_, res)) => resolve(res))
);
});
});

describe("BrowserFetcher", () => {

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Copy path View file

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Copy path View file

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Copy path View file
@@ -29,6 +29,20 @@ external connect:
[@bs.val] [@bs.module "puppeteer"]
external executablePath: unit => string = "";

module IgnoreDefaultArgs = {
type t;
type arg =
| Bool(bool)
| Args(array(string));

let encode: arg => t =
fun
| Bool(b) => Obj.magic(b)
| Args(args) => Obj.magic(args);

let encodeOpt = Belt.Option.map(_, encode);
};

type launchOptions = {
.
"ignoreHTTPSErrors": Js.undefined(bool),
@@ -37,7 +51,7 @@ type launchOptions = {
"slowMo": Js.undefined(float),
"defaultViewport": Js.nullable(Viewport.t),
"args": Js.undefined(array(string)),
"ignoreDefaultArgs": Js.undefined(bool),
"ignoreDefaultArgs": Js.undefined(IgnoreDefaultArgs.t),
"handleSIGINT": Js.undefined(bool),
"handleSIGTERM": Js.undefined(bool),
"handleSIGHUP": Js.undefined(bool),
@@ -58,7 +72,7 @@ external makeLaunchOptions:
~slowMo: float=?,
~defaultViewport: Viewport.t=?,
~args: array(string)=?,
~ignoreDefaultArgs: bool=?,
~ignoreDefaultArgs: IgnoreDefaultArgs.t=?,
~handleSIGINT: bool=?,
~handleSIGTERM: bool=?,
~handleSIGHUP: bool=?,
@@ -73,6 +87,46 @@ external makeLaunchOptions:
launchOptions =
"";

let makeLaunchOptions =
(
~ignoreHTTPSErrors=?,
~headless=?,
~executablePath=?,
~slowMo=?,
~defaultViewport=?,
~args=?,
~ignoreDefaultArgs=?,
~handleSIGINT=?,
~handleSIGTERM=?,
~handleSIGHUP=?,
~timeout=?,
~dumpio=?,
~userDataDir=?,
~env=?,
~devtools=?,
~pipe=?,
(),
) =>
makeLaunchOptions(
~ignoreHTTPSErrors?,
~headless?,
~executablePath?,
~slowMo?,
~defaultViewport?,
~args?,
~ignoreDefaultArgs=?IgnoreDefaultArgs.encodeOpt(ignoreDefaultArgs),
~handleSIGINT?,
~handleSIGTERM?,
~handleSIGHUP?,
~timeout?,
~dumpio?,
~userDataDir?,
~env?,
~devtools?,
~pipe?,
(),
);

/** Launch a browser instance. */
[@bs.val] [@bs.module "puppeteer"]
external launch: (~options: launchOptions=?, unit) => Js.Promise.t(Browser.t) =
ProTip! Use n and p to navigate between commits in a pull request.