Skip to content

Instantly share code, notes, and snippets.

@sroccaserra
Last active January 19, 2022 07:51
Show Gist options
  • Save sroccaserra/b2697f0c7bcbd0612f7c7f571cc0ab51 to your computer and use it in GitHub Desktop.
Save sroccaserra/b2697f0c7bcbd0612f7c7f571cc0ab51 to your computer and use it in GitHub Desktop.
Start a Node.js kata

It should take less that 3 mn (you can practice to go even faster than that), and give you a shareable public repository ready to write tests and have a linter ready for fast feedback. Now we can move on to the kata.

Project start:

$ mkdir bowling-kata
$ cd bowling-kata

Npm setup (pulled from shell history, Ctrl-R):

$ npm init -y; npm install -D mocha chai eslint eslint-plugin-mocha

ESLint setup (pulled from shell history, edit with Ctrl-X Ctrl-E if needed):

$ echo "\
  {
      \"env\": {
          \"commonjs\": true,
          \"es2021\": true,
          \"node\": true
      },
      \"extends\": [\"eslint:recommended\", \"plugin:mocha/recommended\"],
      \"parserOptions\": {
          \"ecmaVersion\": \"latest\"
      },
      \"rules\": {
      }
  }
  " > .eslintrc.json

Write the shortest possible failing test in your favorite editor in "bowling_test.js", for example:

const {expect} = require('chai');

it('fails', function() {
  expect(1).to.equal(0);
});

Setup the npm test script in the "package.json" file (for example, mocha .)

Git setup:

$ echo node_modules/ > .gitignore
$ git init
$ git add .
$ git commit -m first

Create a new repo on github or gitlab or ..., then copy / paste the provided snipet to setup the remote and push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment