How to record only external requests?
See original GitHub issueI’m trying to use pollyjs to test express js endpoint. It works fine until record is persisted to file. After that it just skips actual app code, so that test becomes always green. I assume this is because localhost(127.0.0.1) request/response is being intercepted by polly. Is it possible to record only external requests to prevent this?
app.js:
router.get('/widgets', async (req, res) => {
//some external remote calls
}
polly_config.js:
module.exports = {
adapters: ['node-http'],
persister: 'fs',
persisterOptions: {
fs: {
recordingsDir: `${__dirname}/http_recordings`,
},
},
recordFailedRequests: true,
recordIfMissing: false,
matchRequestsBy: {
headers: false,
},
};
app.spec.js:
const chai = require('chai');
const { expect } = chai;
const chaiHttp = require('chai-http');
chai.use(chaiHttp);
const { Polly } = require('@pollyjs/core');
const NodeHttpAdapter = require('@pollyjs/adapter-node-http');
const FSPersister = require('@pollyjs/persister-fs');
const pollyConfig = require('./polly_config');
Polly.register(NodeHttpAdapter);
Polly.register(FSPersister);
describe('app', () => {
const testPort = 3001;
before(() => {
app.listen(testPort);
});
describe('GET widgets', () => {
it('returns widgets requested', async () => {
const polly = new Polly('get_widgets', pollyConfig);
const response = await chai.request(`http://127.0.0.1:${testPort}`)
.get(`/widgets`)
expect(response).to.have.status(200);
await polly.stop();
});
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
Record and Playback an API to Create a Mock
Enter the URL you wish to record from in the target URL field and click the Record button. You can use http://example.mocklab.io to...
Read more >Enabling external customers to view problem, change, and ...
External customers can view the problem, change, and request records associated with their customer service cases from the Customer and Consumer Service Portals ......
Read more >How to Stub External Services in Tests
Disable all remote connections. We'll use Webmock, a gem which helps to stub out external HTTP requests. In this example we'll search the...
Read more >External Research Data Requests
(Please read carefully before requesting an External Research Application.) ... to protect the confidentiality of education records, and the data may only be ......
Read more >Share Microsoft Teams Meeting Recordings with External ...
After a Microsoft Teams meeting is recorded, you will automatically receive an email from Microsoft Stream alerting you that the video is ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you’re using mocha, I highly recommend using the
setupMocha
test helper.Correct. I’m gonna go ahead and close this issue. Feel free to reopen or create a new one if you have any more questions.