assaf / node-replay

When API testing slows you down: record and replay HTTP responses like a boss
http://documentup.com/assaf/node-replay
MIT License
522 stars 107 forks source link

feat: allow to manually remove unused fixtures #156

Open mweibel opened 6 years ago

mweibel commented 6 years ago

This is a work in progress as to ask for comments and also there's no convenient way to remove the fixtures afterwards, only a way to find which matchers haven't been called. Maybe that's even enough, writing the removal is simple, e.g.:

const unlink = util.promisify(fs.unlink)

afterAll(async () => {
  const unlinkPromises = []
  replay.notMatchedFixtures.map(matcher => {
    unlinkPromises.push(unlink(matcher.fixturePath))
  })
  await Promise.all(unlinkPromises)
  console.log(`Removed ${unlinkPromises.length} unused fixtures.`)
})

This fixes #123

@assaf what's your opinion on this change? a) would you provide mode or a separate function or nothing at all to actually remove the unused fixtures? b) what's required to make you merge this PR?

pstadler commented 6 years ago

This is a very useful feature. I'd suggest to enable it either with something like Replay.unused = 'drop' or env variable e.g. REPLAY_UNUSED=drop, similar to mode.

mweibel commented 6 years ago

Ping? @assaf

mweibel commented 5 years ago

ping again.. @djanowski this time, maybe? :)

djanowski commented 5 years ago

Hi @mweibel thanks for submitting a PR!

I'm not too keen on deleting files automatically, especially after some action did not happen. For example, think of accidentally leaving the flag on and running a subset of your test suite...

But we can add reporting for sure.

Maybe report automatically when debugging is on?

mweibel commented 5 years ago

I'm not too keen on deleting files automatically, especially after some action did not happen. For example, think of accidentally leaving the flag on and running a subset of your test suite...

Fair point, though hopefully people know what they do when they enable that flag. Also: people usually use version control systems.. If something gets deleted accidentally it can always be retrieved back. But yeah, I think we can also do just reporting and write in the README how deletion could be added. Or we add it ourselves but behind another flag?

mweibel commented 5 years ago

I added now a README entry with the example code for removing fixtures.

mweibel commented 5 years ago

ping @djanowski

mehdibeldjilali commented 5 years ago

ping @djanowski 😄

mehdibeldjilali commented 5 years ago

A function like that is very helpful... I have Node-Replay with a GraphQL API with a lot of mocks and it's a headcache to remove unused mocks ...

+1 for you @mweibel ! 👍

mweibel commented 5 years ago

@assaf @djanowski is there any chance this is going to get merged in? I see there are conflicts now because of a recent PR merge. I don't want to put more work into this if you won't merge it.

mehdibeldjilali commented 4 years ago

Hello,

@assaf @djanowski can you think about this feature please ? I've test the fork and it's ok for me. It's the only missing thing of this package.

Thanks !