You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, thanks for this tool looks super helpful. So far is going well I manage to setup Polly.js and Vitest when testing a AWS Endpoint that is accessed using AWS JS SDK.
The problem is when I try to obfuscate headers for security reasons.
Shareable Source
This is the relevant part
// ./src/tests/polly.jsimport{Polly}from'@pollyjs/core'importNodeHttpAdapterfrom'@pollyjs/adapter-node-http'importFSPersisterfrom'@pollyjs/persister-fs'import{beforeAll,afterAll}from'vitest'Polly.register(NodeHttpAdapter)Polly.register(FSPersister)
let polly: PollyexportdefaultfunctionuseCassettes({
cassetteName,
excludedHeaders =[],}: {cassetteName: stringexcludedHeaders?: string[]}){beforeAll(()=>{polly=newPolly(cassetteName,{adapters: ['node-http'],persister: 'fs',persisterOptions: {fs: {recordingsDir: './tests/recordings',},},matchRequestsBy: {headers: false,order: false,},})polly.server.any().on('beforePersist',(req)=>{if(excludedHeaders.length>0){// IT FAILS HERE 💥💥💥req.removeHeaders(excludedHeaders)}})})afterAll(async()=>{awaitpolly.stop()})}
Then I use this useCassettes in my tests like this:
import{describe,it,expect}from'vitest'importcreateSecretfrom'./createSecret'importuseCassettesfrom'tests/polly'describe('createSecret',()=>{useCassettes({cassetteName: 'aws_secrets',excludedHeaders: ['authorization']})it.only('creates the secret in aws',async(ctx)=>{const{ workspace }=awaitctx.factories.createWorkspace({name: 'patata1'})constresult=awaitcreateSecret({app: 'myApp',
workspace,})expect(result?.successful).toBeTruthy()})})
Error Message & Stack Trace
I'm getting the error when trying to modify the headers beforePersits
Description
Hi, thanks for this tool looks super helpful. So far is going well I manage to setup Polly.js and Vitest when testing a AWS Endpoint that is accessed using AWS JS SDK.
The problem is when I try to obfuscate headers for security reasons.
Shareable Source
This is the relevant part
Then I use this
useCassettes
in my tests like this:Error Message & Stack Trace
I'm getting the error when trying to modify the headers
beforePersits
Dependencies
Environment
The text was updated successfully, but these errors were encountered: