Comments (6)
@kettanaito sorry to bother, but I'm having the same doubt here. I read the README file and saw that the presets are imported like:
import { interceptXMLHttpRequest } from 'node-request-interceptor/interceptors/XMLHttpRequest'
But the actual file is located at <node-modules>/node-request-interceptor/lib/interceptors/XMLHttpRequest
.
I'm using babel to transpile my ES6+ codes, and I have to use:
import { interceptXMLHttpRequest } from 'node-request-interceptor/lib/interceptors/XMLHttpRequest'
to make it work. So is it a mistake of the README document?
from interceptors.
Hey, @aprilandjan. Yes, that's a mistake in the README.
The presets are located at:
import withDefaultInterceptors from 'node-request-interceptor/lib/presets/default' import { interceptClientRequest } from 'node-request-interceptor/lib/interceptors/ClientRequest' import { interceptXMLHttpRequest } from 'node-request-interceptor/lib/interceptors/XMLHttpRequest'Please, would you be interested to submit a pull request with the fix to the README?
Thanks for the reply! I just opened #91 for this, please review.
from interceptors.
Hey, @zhaoxiaolei519109457.
You can use it according to the API docs.
const { RequestInterceptor } = require('node-request-interceptor')
const withDefaultInterceptors = require('node-request-interceptor/lib/presets/default')
const interceptor = new RequestInterceptor(withDefaultInterceptors)
interceptor.use((req) => {
// Provision your interception logic
})
Let me know if this helps.
Note that node-request-interceptor
is a low-level API interception library, which means that you'd have to write a considerable amount of boilerplate to use it for requests mocking. Consider using MSW that leverages node-request-interceptor
by wrapping it in a more user-friendly setupServer
API. It will work for Electron apps as well.
from interceptors.
Thank you for your reply, but it doesn't seem to be the correct answer. The following is the error reported in electro
[Window Title]
Error
[Main Instruction]
A JavaScript error occurred in the main process
[Content]
Uncaught Exception:
Error: Cannot find module 'node-request-interceptor/presets/default'
Require stack:
- D:\project\electron-test\main.js
- D:\project\electron-test\node_modules\electron\dist\resources\default_app.asar\main.js
- at Module._resolveFilename (internal/modules/cjs/loader.js:972:15)
at Function.n._resolveFilename (electron/js2c/browser_init.js:249:921)
at Module._load (internal/modules/cjs/loader.js:848:27)
at Function.f._load (electron/js2c/asar_bundle.js:5:12694)
at Module.require (internal/modules/cjs/loader.js:1032:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object. (D:\project\electron-test\main.js:20:33)
at Module._compile (internal/modules/cjs/loader.js:1152:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
at Module.load (internal/modules/cjs/loader.js:992:32)
from interceptors.
My bad, that's a mistake in the import path.
-node-request-interceptor/presets/default
+node-request-interceptor/lib/presets/default
from interceptors.
Hey, @aprilandjan. Yes, that's a mistake in the README.
The presets are located at:
import withDefaultInterceptors from 'node-request-interceptor/lib/presets/default'
import { interceptClientRequest } from 'node-request-interceptor/lib/interceptors/ClientRequest'
import { interceptXMLHttpRequest } from 'node-request-interceptor/lib/interceptors/XMLHttpRequest'
Please, would you be interested to submit a pull request with the fix to the README?
from interceptors.
Related Issues (20)
- Header keys for requests are being converted to lowercase
- ReferenceError: TextEncoder is not defined when running (jest) tests HOT 4
- Treat exceptions as 500 responses instead of a "Failed to fetch" error HOT 7
- XMLHttpRequestController creates bad URL when location exists but href not set HOT 4
- Support aborting intercepted requests HOT 6
- WebSocket: Outgoing client events have the wrong "currentTarget" HOT 2
- WebSocket: Decide how to handle actual server errors
- Flaky: `modules/http/response/readable-stream.test.ts`
- ClientRequestInterceptor incorrectly encodes basic authentication header HOT 15
- Abstract request emitting logic HOT 1
- Await all "response" listeners to finish HOT 6
- Protocol "https:" not supported. Expected "http:" when using "proxy-agent" HOT 1
- Simplify the npm package files HOT 2
- XMLHttpRequest upload (upload.onprogress) event is not supported
- Issue with native fetch introduce after 0.25.1? HOT 3
- Nock compatibility HOT 2
- Unclear how to throw an actual error HOT 3
- Proper documentation on how to use it HOT 1
- RemoteHttpResolver example in README is missing the ".apply()" call HOT 2
- `@mswjs/[email protected]` breaks `URL` as fetch argument
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from interceptors.