This is the repository of basic skeleton for the start in Typescript.
Create a new repository and clone on local
Navigate to the repo
cd <directory_name>
Initialize npm
npm init
This will generate basic package.json
file having project basic information and ask for some value, provide value as per your config.
Create empty directory and install modules required for running test cases
npm install @types/chai @types/mocha chai mocha ts-node typescript --save
Following is the description for these packages:
@types/chai:
@types/mocha
chai:
mocha
ts-node:
typescript:
Create these basic directories for the code and specs
src
spec
src: Where we'll have our code spec: Where we'll have our test cases
Create a file: spec/first.spec.ts
Use this code and put in your first spec file:
import {expect} from 'chai';
describe('First spec', () => {
it('passes', () => {
expect(1).to.equal(1);
})
});
Create file with name .mocharc.json
in root of directory of your project
{
"diff": true,
"extension": ["ts"],
"require": ["ts-node/register"],
"package": "./package.json",
"reporter": "spec",
"slow": 75,
"timeout": 2000,
"ui": "bdd",
"watch-files": ["**/*.ts"],
"watch-ignore": ["node_modules"],
"spec": "**/*.spec.ts"
}
Make sure we have this command in the package.json
"test": "mocha"
Then run following command in the terminal:
npm test
You will see following output then you are all set.
> [email protected] test <your-project-directory-path>
> mocha
First spec
✓ passes
1 passing (11ms)
npm test -- --watch
This way if you change in your any file and save it test will automatically run.