Hi.
All Articles ›
2 Aug 2020
Today I Got Confused: By creating a simple JS file!

Today I Got Confused: By creating a simple JS file!

I didn't think I'd be writing about a simple debugging experience. However, with my recent problems I thought I should share! Today I have spent near enough two hours banging my head against the wall, searching around the web and doubting my existence...

You're probably going to have a little giggle, but if this helps just one person, then it was definitely worth it!

So there I was just working on my little Node project, then I had an idea! It was that idea that cost me two hours and a headache. That little project was a Lambda function that called an endpoint to send an email; super simple! The current implementation was working spot on and had great test coverage. After working through the codebase and adding my feature, I noticed a relatively quick win that would improve the performance of the code (quick wins are always good).

Now, before I started to refactor my code, I just wanted to validate my idea. What's the point of this? Sure, because it's only a simple function, it would be easy to just replace what's currently there, but I wanted something a bit more. I wanted to validate not only the implementation but my understanding of how the receiving API was working.

Ten minutes later, I had a local JS file that I could run and then receive an email! Yay!

But wait, I received another email‽

Undoubtedly just a one-time thing, so just to double-check, I added a simple log and ran it. 2 emails again...

How was this even possible?

I won't bore you with the steps I went through but here's just a couple of things I tried.

  • Making a cup of tea, and trying again - Still Broken
  • Checking logs to establish if 2 API calls were being received - Yep they sure were
  • Reverting my changes and running the old project - STILL BROKEN
  • Surely it's a provider issue? Let's check production - Production Works (Phew!)
  • Check with other Devs - Well Theirs Works
  • Thinking Time...

Then it hit me!

I LEFT JEST WATCH RUNNING!!!

Yep, it was really that simple!

Hold up, Hold up - So what? How does this affect anything at all? Why would Jest running in watch mode cause those symptoms?

Because Kyran, you called that 'local JS file' test.js. 😱

Yep, yep you did!

The moral of the story... don't create a quick scrap file called test and leave Jest running in the background!