Open sparrovv opened 1 year ago
try this example and see if it works?
import { fetchQuote, sendMessage } from "../../javascript/api";
import { pollyConfig } from "../polly-config";
test("fetchQuote should fetch a random quote", async () => {
const polly = await pollyConfig("FetchQuotes");
const data = await fetchQuote();
expect(data).toBeDefined();
await polly.stop();
});
test("send text message", async () => {
const polly = await pollyConfig("SendMessage");
const data = await sendMessage("INSERT-TEST-NUMBER", "Hello!");
expect(data).toBeDefined();
await polly.stop();
});
import { Polly } from "@pollyjs/core";
import LocalStoragePersister from "@pollyjs/persister-local-storage";
import NodeHttpAdapter from "@pollyjs/adapter-node-http";
import FSPersister from "@pollyjs/persister-fs";
import FetchAdapter from "@pollyjs/adapter-fetch";
Polly.register(NodeHttpAdapter);
Polly.register(FSPersister);
Polly.register(LocalStoragePersister);
Polly.register(FetchAdapter);
const config = {
adapters: ["fetch"],
persister: "fs",
logLevel: "info",
recordFailedRequests: true,
recordIfMissing: true,
recordFailedRequests: true,
mode: "replay",
persisterOptions: {
fs: "__recordings__",
},
};
export function pollyConfig(name) {
const polly = new Polly(name, config);
polly.server
.any()
.on("response", (req) =>
console.log(JSON.stringify({ result: req }, null, 2)),
);
return polly;
}
For me using adapter-fetch
and node 20.11.0
works, but I get this message: [Polly] [adapter:fetch] Using the fetch adapter in Node has been deprecated. Please use the node-http adapter instead.
Nice. Library deprecation message on a 'new' node feature. Btw node-http adapter does not work at all, obviously. All latest versions.
Description
This might be a known bug, but I couldn't find any reference.
I want to use node native fetch to make requests, but when configuring polly with fetch-adapter, it doesn't seem to work.
Is there any workaround for that?
Shareable Source
Error Message & Stack Trace
Dependencies
Environment