Week 9: Minesweeper Quiz IV

This week, I continued on in learning how to test JavaScript using Jest. So there was a bit of uncertainty how to make the website code run, and also allow it to be testable at the same time. This was quite a simple fix of adding type=”module” when importing it as html.

Then there was the problem of my module having all this high-level code, which was being run when testing with Jest. To fix this I wrapped it up in a function. So then I was a bit unsure, how to proceed, i.e. how would the website know which functions to run. In Python, I would use a if __name__ == ‘__main__’, which I don’t believe is available in JavaScript. I could either put that logic into the html code, which means JavaScript is mixed in two areas. Instead I opted for an index.js entry point that would import the modules.

I tried testing in PROD, but it would keep crashing the webserver, which I would constant restart. I decided to start testing on my local machine. Unfortunately there was a issue with the paths as my local machine is a windows machine. I believe when I ran npm test, it was trying to run a bash script which doesn’t run in Windows. I tried to set this up in WSL instead to fix the pathing issue. This involved setting up all the github and webserver SSH, which took me some time. When setting up the SSH for webserver, I learnt you can find the digital fingerprint in the webserver, which is interesting.

Once I had all that set up, I tried to run npm test in WSL, but was hit by a different path issue. Then I realised I should be using a different entry point on my windows machine that would directly call the jest.js file. This worked, so next week I’m hoping to do some actual testing, maybe move into JSDOM as well.

Also I had an issue where I would spend too much time on webdev. Going forwards I'll set a fixed-schedule which will limit webdev on saturday from 6-9am. I've had times where I've run over even into sunday. I think i've become more comfortable not finishing things and leaving it for later.

Learnings

  • Testing is hard
  • I don't remember very well how to set up SSH keys
  • You can find digital fingerprint in VM
  • Testing in PROD is bad
  • Fixed schedule is good