mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Updates types for nightmare.js (#18876)
This commit is contained in:
committed by
Mohamed Hegazy
parent
aa2183e844
commit
b992475758
88
types/nightmare/index.d.ts
vendored
88
types/nightmare/index.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
// Type definitions for Nightmare 1.6.5
|
||||
// Type definitions for Nightmare 1.6.6
|
||||
// Project: https://github.com/segmentio/nightmare
|
||||
// Definitions by: horiuchi <https://github.com/horiuchi/>
|
||||
// Sam Yang <https://github.com/samyang-au>
|
||||
@@ -11,14 +11,27 @@ declare class Nightmare {
|
||||
constructor(options?: Nightmare.IConstructorOptions);
|
||||
|
||||
// Interact
|
||||
userAgent(agent: string): Nightmare;
|
||||
end(): Nightmare;
|
||||
then<T, R>(fn: (value: T) => R): Promise<R>;
|
||||
halt(error: string, cb: () => void): Nightmare;
|
||||
goto(url: string): Nightmare;
|
||||
goto(url: string, headers: Object): Nightmare;
|
||||
back(): Nightmare;
|
||||
forward(): Nightmare;
|
||||
refresh(): Nightmare;
|
||||
click(selector: string): Nightmare;
|
||||
mousedown(selector: string): Nightmare;
|
||||
mouseup(selector: string): Nightmare;
|
||||
mouseover(selector: string): Nightmare;
|
||||
type(selector: string, text: string): Nightmare;
|
||||
insert(selector: string, text: string): Nightmare;
|
||||
check(seletor: string): Nightmare;
|
||||
uncheck(seletor: string): Nightmare;
|
||||
select(seletor: string, option: string): Nightmare;
|
||||
upload(selector: string, path: string): Nightmare;
|
||||
scrollTo(top: number, left: number): Nightmare;
|
||||
viewport(width: number, height: number): Nightmare;
|
||||
inject(type: string, file: string): Nightmare;
|
||||
evaluate<T1, T2, T3, R>(fn: (arg1: T1, arg2: T2, arg3: T3) => R, cb: (result: R) => void, arg1: T1, arg2: T2, arg3: T3): Nightmare;
|
||||
evaluate<T1, T2, R>(fn: (arg1: T1, arg2: T2) => R, cb: (result: R) => void, arg1: T1, arg2: T2): Nightmare;
|
||||
@@ -30,6 +43,7 @@ declare class Nightmare {
|
||||
wait(ms: number): Nightmare;
|
||||
wait(selector: string): Nightmare;
|
||||
wait(fn: () => any, value: any, delay?: number): Nightmare;
|
||||
header(header: string, value: string): Nightmare;
|
||||
use(plugin: (nightmare: Nightmare) => void): Nightmare;
|
||||
run(cb?: (err: any, nightmare: Nightmare) => void): Nightmare;
|
||||
|
||||
@@ -51,10 +65,50 @@ declare class Nightmare {
|
||||
on(event: 'prompt', cb: (msg: string, defaultValue?: string) => void): Nightmare;
|
||||
on(event: 'error', cb: (msg: string, trace?: Nightmare.IStackTrace[]) => void): Nightmare;
|
||||
on(event: 'timeout', cb: (msg: string) => void): Nightmare;
|
||||
once(event: string, cb: () => void): Nightmare;
|
||||
once(event: 'initialized', cb: () => void): Nightmare;
|
||||
once(event: 'loadStarted', cb: () => void): Nightmare;
|
||||
once(event: 'loadFinished', cb: (status: string) => void): Nightmare;
|
||||
once(event: 'urlChanged', cb: (targetUrl: string) => void): Nightmare;
|
||||
once(event: 'navigationRequested', cb: (url: string, type: string, willNavigate: boolean, main: boolean) => void): Nightmare;
|
||||
once(event: 'resourceRequested', cb: (requestData: Nightmare.IRequest, networkRequest: Nightmare.INetwordRequest) => void): Nightmare;
|
||||
once(event: 'resourceReceived', cb: (response: Nightmare.IResponse) => void): Nightmare;
|
||||
once(event: 'resourceError', cb: (resourceError: Nightmare.IResourceError) => void): Nightmare;
|
||||
once(event: 'consoleMessage', cb: (msg: string, lineNumber: number, sourceId: number) => void): Nightmare;
|
||||
once(event: 'alert', cb: (msg: string) => void): Nightmare;
|
||||
once(event: 'confirm', cb: (msg: string) => void): Nightmare;
|
||||
once(event: 'prompt', cb: (msg: string, defaultValue?: string) => void): Nightmare;
|
||||
once(event: 'error', cb: (msg: string, trace?: Nightmare.IStackTrace[]) => void): Nightmare;
|
||||
once(event: 'timeout', cb: (msg: string) => void): Nightmare;
|
||||
removeListener(event: string, cb: () => void): Nightmare;
|
||||
removeListener(event: 'initialized', cb: () => void): Nightmare;
|
||||
removeListener(event: 'loadStarted', cb: () => void): Nightmare;
|
||||
removeListener(event: 'loadFinished', cb: (status: string) => void): Nightmare;
|
||||
removeListener(event: 'urlChanged', cb: (targetUrl: string) => void): Nightmare;
|
||||
removeListener(event: 'navigationRequested', cb: (url: string, type: string, willNavigate: boolean, main: boolean) => void): Nightmare;
|
||||
removeListener(event: 'resourceRequested', cb: (requestData: Nightmare.IRequest, networkRequest: Nightmare.INetwordRequest) => void): Nightmare;
|
||||
removeListener(event: 'resourceReceived', cb: (response: Nightmare.IResponse) => void): Nightmare;
|
||||
removeListener(event: 'resourceError', cb: (resourceError: Nightmare.IResourceError) => void): Nightmare;
|
||||
removeListener(event: 'consoleMessage', cb: (msg: string, lineNumber: number, sourceId: number) => void): Nightmare;
|
||||
removeListener(event: 'alert', cb: (msg: string) => void): Nightmare;
|
||||
removeListener(event: 'confirm', cb: (msg: string) => void): Nightmare;
|
||||
removeListener(event: 'prompt', cb: (msg: string, defaultValue?: string) => void): Nightmare;
|
||||
removeListener(event: 'error', cb: (msg: string, trace?: Nightmare.IStackTrace[]) => void): Nightmare;
|
||||
removeListener(event: 'timeout', cb: (msg: string) => void): Nightmare;
|
||||
screenshot(path: string): Nightmare;
|
||||
html(path: string, saveType: string): Nightmare;
|
||||
html(path: string, saveType: 'HTMLOnly'): Nightmare;
|
||||
html(path: string, saveType: 'HTMLComplete'): Nightmare;
|
||||
html(path: string, saveType: 'MHTML'): Nightmare;
|
||||
pdf(path: string): Nightmare;
|
||||
pdf(path: string, options: Object): Nightmare;
|
||||
title(): string;
|
||||
title(cb: (title: string) => void): Nightmare;
|
||||
url(cb: (url: string) => void): Nightmare;
|
||||
url(): string;
|
||||
path(): string;
|
||||
|
||||
readonly cookies: Nightmare.Cookies;
|
||||
|
||||
// Settings
|
||||
authentication(user: string, password: string): Nightmare;
|
||||
@@ -117,6 +171,38 @@ declare namespace Nightmare {
|
||||
line: number;
|
||||
function?: string;
|
||||
}
|
||||
export class Cookies {
|
||||
get(): [Nightmare.ICookie];
|
||||
get(name: string): Nightmare.ICookie;
|
||||
get(query: Nightmare.ICookieQuery): [Nightmare.ICookie];
|
||||
set(name: string, value: string): Nightmare;
|
||||
set(cookie: Nightmare.ICookie): Nightmare;
|
||||
set(cookies: [Nightmare.ICookie]): Nightmare;
|
||||
clear(): Nightmare;
|
||||
clear(name: string): Nightmare;
|
||||
clearAll(): Nightmare;
|
||||
}
|
||||
export interface ICookieQuery {
|
||||
url?: string;
|
||||
name?: string;
|
||||
domain?: string;
|
||||
path?: string;
|
||||
secure?: boolean;
|
||||
session?: boolean;
|
||||
|
||||
}
|
||||
export interface ICookie {
|
||||
name: string;
|
||||
value: string;
|
||||
url?: string
|
||||
domain?: string;
|
||||
hostOnly?: boolean;
|
||||
path?: string;
|
||||
secure?: boolean;
|
||||
httpOnly?: boolean;
|
||||
session?: boolean;
|
||||
expirationDate?: number;
|
||||
}
|
||||
}
|
||||
|
||||
export = Nightmare;
|
||||
|
||||
@@ -318,4 +318,28 @@ new Nightmare()
|
||||
.use(testTitle('test term'))
|
||||
.run(done);
|
||||
|
||||
new Nightmare({show: true});
|
||||
new Nightmare({show: true});
|
||||
|
||||
new Nightmare()
|
||||
.goto('http://google.com', { bogus: 'foo' })
|
||||
.evaluate(() => document.body.textContent)
|
||||
.end()
|
||||
.then(body => console.log(body));
|
||||
|
||||
new Nightmare()
|
||||
.header('bogus', 'foo')
|
||||
.goto('http://google.com')
|
||||
.mouseup('body')
|
||||
.mousedown('body')
|
||||
.mouseover('body')
|
||||
.insert('input[name=q]', 'nightmare.js')
|
||||
.click('input[type=submit]');
|
||||
|
||||
new Nightmare()
|
||||
.goto('https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox')
|
||||
.check('#book')
|
||||
.uncheck('#book');
|
||||
|
||||
new Nightmare()
|
||||
.goto('https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select')
|
||||
.select('select[name=select]', 'value3');
|
||||
|
||||
Reference in New Issue
Block a user