Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Learning TDD in JavaScript by following the tutorials of 'dwyl'

Notifications You must be signed in to change notification settings

codingEzio/dwyltutorial_tdd_in_js_basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Why

Basics

  • 3-step process
    1. write a failing test

      understand the requirements/story well enough to write a est for what you expect

    2. make the test pass

      write only the code you need to make the (failing)test pass
      while ensuring your existing/previous test all still pass

    3. refactor the code you wrote

      tidy up the code you wrote to make it simpler for yourself and colleagues to understand

Preparation

  • We almost do not need to install anything.
  • For a live server, you can install and use it by:
    1. don't need live-reload: python -m http.server 9000 --bind 0.0.0.0
    2. do need it: npm install live-server --save-dev && ./node_modules/.bin/live-server --port=8000
  • For the code coverage part, a short HOWTO on blanket lib
    1. see Getting Started (blanket)
    2. add attr to the script you wanna run coverage on: <script src="sourceScript.js" data-cover></script>
  • For the Node.js (server-side) tests
    1. install libraries: npm install qunitjs qunit-tap istanbul --save-dev
      • qunitjs: core library
      • qunit-tap: for command-line output
      • istanbul: code coverage (server-side) (better than blanket lib)
    2. actually running them
      • testing only: npm test
      • test coverage included
      • ./node_modules/.bin/istanbul cover TEST_FILE.js OR npx istanbul cover test_feauture.js
      • after running the cmd you could see the detailed coverage report at ./coverage/../index.html
  • For the JSDoc part
    1. install library: npm install jsdoc --save-dev
    2. run it: ./node_modules/.bin/jsdoc YOUR_MAIN_SCRIPT.js OR npx jsdoc YOUR_MAIN_SCRIPT.js
    3. check the result: open ./out/global.html#getChange

Issues you might encounter

  • Caveats when you use blanket test coverage library
    • It cannot identify the bad code if it was written in one line (e.g. if (..) { bad stuff })

Actual notes

  • The TDD partly mostly happen in the two .js files (and the index.html).
  • Add code coverage badge at Codecov.io, here's something you need to know
    1. Available on Github, BitBucket, Gitlab
    2. It supports public repo by default, requires additional perms for private repo

More

References

About

Learning TDD in JavaScript by following the tutorials of 'dwyl'

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published