Skip to content

Instantly share code, notes, and snippets.

@gregorriegler
Last active February 19, 2021 18:44
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/3e6f5d38f74fec9f2be0c66ddf16195d to your computer and use it in GitHub Desktop.
Save gregorriegler/3e6f5d38f74fec9f2be0c66ddf16195d to your computer and use it in GitHub Desktop.
TDD bootstrap for js with mocha+chai. use 'curl <raw> | bash -s <folder>'
#!/usr/bin/env bash
if [ $# -ge 1 ]
then
# jump to folder
target="$1"
mkdir -p "$target"
cd "$target"
fi
# init
npm init -y
npm i -d mocha chai
# create red test
mkdir test
read -d '' first_test << EOF
const expect = require('chai').expect;
describe('World', function() {
it('red', function() {
expect('foo').to.equal('bar')
})
});
EOF
echo "$first_test" > test/test.js
# point 'npm test' to mocha
npm i -g json
json -I -f package.json -e 'this.scripts.test="mocha"'
json -I -f package.json -e 'this.scripts["test:watch"]="mocha -R min -w"'
# 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 tests
npm run test:watch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment