Last active
February 19, 2021 18:44
-
-
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>'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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