Skip to content

Instantly share code, notes, and snippets.

@gregorriegler
Last active February 5, 2022 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregorriegler/5c578410a619188838d3c9c6c23e09ae to your computer and use it in GitHub Desktop.
Save gregorriegler/5c578410a619188838d3c9c6c23e09ae to your computer and use it in GitHub Desktop.
TDD bootstrap for typescript with mocha+chai. use 'curl <raw> | bash -is <folder>'
#!/usr/bin/env bash
# start tdd in one command 'curl <link-to-raw> | bash -s <folder>
if [ $# -ge 1 ]
then
# jump to folder
target="$1"
mkdir -p "$target"
cd "$target"
fi
# init
npm init -y
npm i -d typescript ts-node mocha chai nyc @types/node @types/mocha @types/chai
# create tsconfig.json
read -d '' tsconfig << EOF
{
"compileOnSave": true,
"compilerOptions": {
// see https://www.typescriptlang.org/docs/handbook/compiler-options.html
"target": "es5",
"lib": [
"esnext"
],
"module": "commonjs",
"sourceMap": true,
"outDir": "./dist/",
"noEmitOnError": true,
"strict": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": false,
"downlevelIteration": true,
"experimentalDecorators": true,
},
"include": [
"src/**/*",
"test/**/*.ts",
],
"exclude": [
"node_modules",
"dist",
]
}
EOF
echo "$tsconfig" > tsconfig.json
# create red test
mkdir test
read -d '' first_test << EOF
import {expect} from 'chai'
import 'mocha'
describe('World', () => {
it('is Red', () => {
expect('foo').to.equal('bar')
})
})
EOF
echo "$first_test" > test/test.ts
# point 'npm test' to mocha
npm i -g json
json -I -f package.json -e 'this.scripts.test="mocha -r ts-node/register \"test/**/*.ts\""'
json -I -f package.json -e 'this.scripts["test:watch"]="mocha -r ts-node/register -R min -w --watch-files . \"test/**/*.ts\""'
# init git
curl https://www.toptal.com/developers/gitignore/api/node,intellij+all,eclipse,visualstudiocode,windows,linux,macos --output .gitignore
git init
git add -A
# run test:watch
npm run test:watch
@gregorriegler
Copy link
Author

input von Peter: download and add default .gitignore, and run git init

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