Monday 15 November 2021

Lab 8 - Jest Enough

Step 1: Choosing Jest

Last week was rough and I had to fix code before doing Lab 8.  Basically, we are implementing Automated Testing to our existing ssg  I chose to use Jest because I am using Node.js as my main language.  I feel like this week I was completely burnt out and needed a few days to rest.

I use npm install to install jest and added the following two lines to package.json


Step 2: First Tests

My first set of tests involve file checking, whether a path is a file, folder and nothing related to the files I needed, which are ".md" and ".txt".

STEP 3: Test the Core of SSG

My next set of tests involve whether I utilized the correct input files.

Running my tests yielded the following results on Jest.


Step 4: Updating Documentation

I updated the CONTRIBUTION.md file

Step 6: Merging to Master

Conclusion

I learnt that writing test for existing code that does not have tests is much harder than writing tests from the start.  I feel like I have to refactor some of my code in order for my tests to run.  I believe the benefit of this open-source class and community is that you can ask questions and help each other out during harder labs and releases.  I have done testing before, but not with Jest, so it was a good experience.

My pull request

Live to code another day...

Wednesday 3 November 2021

[OSD600] Lab 7 - Static Analysis Tooling

Introduction 

From the lab we are working on the following this week,

  • an automatic source code formatter
  • a source code linter
  • command-line or project build scripts to run your static analysis tooling
  • editor/IDE integration of your static analysis tooling
  • write contributor documentation to setup and use your tools
I created a branch called lab7.

Moved related Documentation to CONTRIBUTING.md


As the title suggests, I moved all relevant documentation to CONTRIBUTING.md file.

I added a developer checks section as shown below as well.


Automatic source code Formatter

The obvious choice is Prettier because I am using a node.js project for cmd-ssg

I added using npm install --save-dev --save-exact prettier

# ignore artifacts:
build
dist
added to .prettierignore

Under package.json, I had scripts for prettier such as the following
"prettier-check": "npx prettier --check .",
"prettier": "npx prettier --write .",
You type and execute "npm run prettier-check" in terminal to check format.

Source Code Linter

Eslint seems the sensible choice for my project where you use the commands
$ npm install eslint --save-dev
eslint --init
I edited .eslintrc with
{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": "eslint:recommended",
  "parserOptions": {
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "rules": {
    "indent": ["error", 2],
    "linebreak-style": 0,
    "quotes": ["error", "double"],
    "semi": ["error", "always"]
  }
}

Editor Integration and VS Code Settings

For automatic formatting and linting i added the following to extensions.json
{
  "recommendations": [
    "editorconfig.editorconfig",
    "dbaeumer.vscode-eslint",
    "esbenp.prettier-vscode",
    "streetsidesoftware.code-spell-checker"
  ]
}
Under settings I added the following to settings.json in vs code
...
  "editor.insertSpaces": true,
  "editor.tabSize": 2,
  "editor.detectIndendations": false,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "files.eol": "\n",
  "files.insertFinalNewline": true
...

Pre-commit Hook

As the lab 7 suggests, I used Husky as my pre-commit hook

Issues

I did not have many major issues, except I had to ignore some of the checks done on the project because I had a helper javascript file that is separate from the index.js, the dependencies on the parent is not on child. I used what I learned in Web222 and integrated prettier and eslint ahead of time so there we not many issues.

My commit is here cc92dc8

Cheers,

Eugene

What I learned from Project 1 of Udacity's Data Science with Python bootcamp

Introduction As part of the project I completed successfully, I used SQL to explore a database related to movie rentals. SQL queries was ran...