This repository has been archived by the owner on Apr 25, 2021. It is now read-only.
forked from codemanki/cloudscraper
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.test-d.ts
86 lines (73 loc) · 2.89 KB
/
index.test-d.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expectType } from 'tsd';
import { URL } from 'url';
import {
Options, Cloudscraper, CaptchaHandler, CoreOptions, DefaultOptions,
CaptchaResponse, Captcha
} from './index';
import Promise = require('bluebird');
import request = require('request');
import rp = require('request-promise');
import cloudscraper = require('./index');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import errors = require('./errors');
const noop = (): void => {};
expectType<Options>({ uri: '' });
expectType<Options>({ url: '' });
expectType<Options>({ uri: '', requester: request });
expectType<Options>({ uri: '', requester: rp });
expectType<Cloudscraper>(cloudscraper({ uri: '' }));
expectType<Cloudscraper>(cloudscraper.get({ uri: '' }));
expectType<Cloudscraper>(cloudscraper.post({ uri: '' }));
expectType<Cloudscraper>(cloudscraper.put({ uri: '' }));
expectType<Cloudscraper>(cloudscraper.delete({ uri: '' }));
expectType<Cloudscraper>(cloudscraper.del({ uri: '' }));
expectType<Cloudscraper>(cloudscraper.head({ uri: '' }));
expectType<Cloudscraper>(cloudscraper.patch({ uri: '' }));
expectType<Cloudscraper>(cloudscraper(''));
expectType<Cloudscraper>(cloudscraper.get(''));
expectType<Cloudscraper>(cloudscraper.post(''));
expectType<Cloudscraper>(cloudscraper.put(''));
expectType<Cloudscraper>(cloudscraper.delete(''));
expectType<Cloudscraper>(cloudscraper.del(''));
expectType<Cloudscraper>(cloudscraper.head(''));
expectType<Cloudscraper>(cloudscraper.patch(''));
// eslint-disable-next-line promise/always-return
expectType<Promise<any>>(cloudscraper.get({ uri: '' }).then(noop));
expectType<Promise<any>>(cloudscraper.get({ uri: '' }).catch(noop));
expectType<Promise<any>>(cloudscraper.get({ uri: '' }).finally(noop));
expectType<Promise<any>>(cloudscraper.get({ uri: '' }).promise());
expectType<void>(cloudscraper.get({ uri: '' }).cancel());
expectType<CaptchaHandler>((options: Options, response: CaptchaResponse) => {
expectType<Options>(options);
expectType<CaptchaResponse>(response);
const { captcha, isCaptcha } = response;
expectType<Captcha>(captcha);
expectType<true>(isCaptcha);
expectType<Captcha>({
url: '', // <- deprecated
uri: new URL(''),
siteKey: '',
submit: captcha.submit,
form: { s: '' }
});
captcha.submit();
});
expectType<DefaultOptions>(cloudscraper.defaultParams);
expectType<DefaultOptions>({
requester: request,
cloudflareMaxTimeout: 0,
challengesToSolve: 0,
decodeEmails: false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onCaptcha: (options: Options, response: CaptchaResponse) => {}
});
expectType<CoreOptions>({
requester: request,
cloudflareMaxTimeout: 0,
challengesToSolve: 0,
decodeEmails: false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onCaptcha: (options: Options, response: CaptchaResponse) => {},
realEncoding: 'utf-8'
});