Skip to content

A collection of dev tools configured to jumpstart Typescript development

Notifications You must be signed in to change notification settings

SkyAlert/xUnit-example

 
 

Repository files navigation

Skyalert Typescript Scaffolding

Clone this project to jump-start a TS project. It contains tools and configurations for TDD best practices, so that your environment can give you instant feedback on your work.

Included in the box

  • typescript: used to transpile your code into JS.
  • ts-node: typeScript execution engine and REPL for Node.js.
  • jest: unit testing
  • eslint: code style enforcement
  • prettier: code formatting enforcement
  • typedoc: automatic doc generation
  • husky: git hooks

Available scripts

  • yarn start - run your application and watch for changes
  • test - run all tests
  • test-watch - jest interactive terminal
  • lint - check for style errors and warnings
  • clean - delete ./dist folder
  • build - transpile into ./dist folder
  • build-watch - watch for changes and transpile into ./dist folder
  • build-all - check for style errors, delete ./dist and build

Installation

  1. Download/clone this repo
  2. yarn
  3. yarn prepare
  4. Go to package.json and fill out the name, description and author
  5. git init
  6. git add .
  7. git commit -m "Scaffolding complete"
  8. Add a remote repository

How to use

This is a walkthrough of the available tools.

test-watch

  1. Open a terminal window and run yarn test-watch.
  2. All green? Good.
  3. Open src/index.test.ts
  4. At the end, write the following test:
describe('When multiplying two numbers', () => {
  it('should return the product', () => {
    expect(multiply(3, 5)).toBe(15);
  });
});
  1. You can immediately see that multiply(3,5) is hightlighted as an error.
  2. Save the file anyway.
  3. Now your test fail with:

src/index.test.ts:11:12 - error TS2304: Cannot find name 'multiply'.

  1. Now open src/index.ts and write an implementation:
export const multiply = (a: number, b: number): number => a * b;
  1. Import your new function into the .test file
- import { sum } from './index';
+ import { sum, multiply } from './index';
  1. Save both files and watch the test pass.

eslint + prettier

  1. Run yarn lint in your terminal. If nothing happens, you are good.
  2. Run
echo "crappyCode(a, b) => a /b" >> src/index.ts
  1. Run yarn lint. You'll see at least an error. (also in the test-watch terminal)
  2. Fix it like so:
export const divide = (a: any, b: any) => a / b;
  1. Run yarn lint again. You'll see it complains with a warning. Let's fix it:
export const divide = (a: number, b: number) => a / b;

husky

  1. Run
echo "export const subtract = (a: number, b: number) => { return a - b };
" >> src/index.ts
  1. Try to commit this to the repo. If you followed the "Installation" section, it should fail.

  2. Replace with:

export const subtract = (a: number, b: number) => a - b;
  1. Commit (if you want, if not just run yarn lint). It should not produce an error.

start

  1. Run yarn start
  2. Write:
const a = 6;
const b = 3;

console.log(sum(a, b));
  1. Save and watch the terminal output. It should print 9
  2. Make a small change:
-console.log(sum(a, b));
+console.log(multiply(a, b));
  1. Save and watch the terminal output. It should print 18

docs

  1. Run yarn docs
  2. Open docs/index.html in a web browser. Explore your new documentation.
  3. In src/index.ts add:
/**
 * Calculates the square root of a number.
 *
 * @param x the number to calculate the root of.
 * @returns the square root if `x` is non-negative or `NaN` if `x` is negative.
 */
export const sqrt = (x: number): number => Math.sqrt(x);
  1. Run yarn docs and reload your web browser. Explore the new function.

develop

  1. Just replace index.ts and index.test.ts and do as you please.

About

A collection of dev tools configured to jumpstart Typescript development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 77.7%
  • JavaScript 20.5%
  • Shell 1.8%