0.1.0 • Published 9 years ago
http-test-double v0.1.0
TypeScript
Starting a new project:
# Create a package.json file
npm init
Then:
# Install dev tools and add them to package.json
npm install typescript --save-dev
npm install tsd --save-dev
# Install dev dependencies, and add them to the package.json
npm install mocha --save-dev
npm install chai --save-dev
# Download type definitions for the dev dependencies above
# This creates a `tsd.json` file and `typed` directory
node_modules/.bin/tsd query chai --save --action install
node_modules/.bin/tsd query node --save --action install
node_modules/.bin/tsd query mocha --save --action install
# Set up some files for the VisualStudio Code editor (so you get intellisense help)
cat << EOF > tsconfig.json
{
"compilerOptions": {
"target": "ES3",
"module": "commonjs",
"sourceMap": true
}
}
EOF
mkdir .settings
cat << EOF > tasks.json
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
// A task runner that calls the Typescipt compiler (tsc) and
// Compiles a HelloWorld.ts program
{
"version": "0.1.0",
"command": "make",
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
"isShellCommand": true,
"args": ["test"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
EOF
cat << EOF > .settings/launch.json
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch make",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "main.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
]
}
EOF
# Create a main script
cat << EOF > main.ts
export function main() {
return "Hello world!";
};
EOF
# Create a test directory
mkdir test
cat << EOF > test/test.ts
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import chai = require('chai');
var expect = chai.expect;
import main = require('../main');
describe('User Model Unit Tests:', () => {
describe('2 + 4', () => {
it('should be 6', (done) => {
expect(2+4).to.equals(6);
done();
});
it('should not be 7', (done) => {
expect(2+4).to.not.equals(7);
done();
});
});
});
describe('Main', () => {
it('should return greeting', (done) => {
expect(main.main()).to.equals("Hello World!");
done();
});
});
EOF
# Set up some project files
cat << EOF > .gitignore
node_modules
./*.js
test/*.js
EOF
cat << EOF > README.md
TypeScript
==========
EOF
cat << EOF > Makefile
.PHONY: test
build:
node_modules/.bin/tsc --module commonjs test/test.ts
test: | build
mocha
EOF
At this point you can:
- Make a build with
make
- Run the tests with
make test
Making a Release
Install:
npm install
Build the .js files and run the tests:
make test
Update the package.json
file then publish to npm:
0.1.0
9 years ago