tradie-template-node-package
A tradie
template for creating NodeJS packages.
Featuring:
- linting with
eslint
- type checking with
flow
- transpilation with
babel
- testing with
jest
Installation
npm install --save-dev tradie-template-node-package
Usage
Take a look at an example project.
-
Create some files:
package.json
src/index.js
{return true;}src/index.test.js
;; -
Build the files:
yarn run build
-
Run the tests:
yarn run test
-
Publish the package:
yarn publish
Commands
tradie create
Create the project files.
tradie clean
Remove generated files.
Will remove files matching lib/**
and coverage/**
.
tradie lint
Lint source and test files.
tradie build [--watch]
Lint and transpile source files.
Will lint and transpile source files matching src/**/*.{js,jsx}
and write the result to lib/
. Will copy Flow types to lib/
.
Will ignore test files, fixtures and mocks matching {src,test}/**/*.test.{js,jsx}
, {src/test}/**/__mocks__/
or {src/test}/**/__fixtures__/
.
tradie test [--watch] [--coverage]
Run test files.
Will run test files matching {src,test}/**/*.test.{js,jsx}
.
How To
Set up Flow
-
Create the config file:
.flowconfig
[ignore] # ignore transpiled code <PROJECT_ROOT>/lib
You can learn more about configuring Flow here.
-
Install the types for
jest
:flow-typed install jest@^20 --flowVersion 0.48.0
You can learn more about installing Flow types here.
-
Annotate your files:
src/index.js
// @flow...src/index.test.js
// @flow...You can learn more about writing code for Flow here.
Writing tests
-
Create a test file and write some assertions
src/index.test.js
;You can learn more about writing assertions with Jest here.
Jest provides mock functions and manual mock functions which are worth learning!
Customising the test environment
Occasionally you'll need to run some code to setup your test environment before running your tests. Jest will try running src/_.test.js
and test/_.test.js
before it runs your tests. You can place any necessary test setup in here.
e.g.
; //allow global access to `shallow()` in test files// to avoid `import`ing it in every fileglobalshallow = shallow;