Skip to content

Instantly share code, notes, and snippets.

View pimterry's full-sized avatar

Tim Perry pimterry

View GitHub Profile
@pimterry
pimterry / .travis.yml
Created December 3, 2016 18:18
Travis config for running Bats tests
language: bash
script:
- ./test.sh
@pimterry
pimterry / notes-find-test.sh
Created December 3, 2016 18:14
A simple real bats test, using `run` to assert on status and output
@test "Should show matching notes only if a pattern is provided to find" {
touch $NOTES_DIRECTORY/match-note1.md
touch $NOTES_DIRECTORY/hide-note2.md
run $notes find "match"
assert_success
assert_line "match-note1.md"
refute_line "hide-note2.md"
}
git clone <your repo>
git submodule update --init --recursive
./test.sh
@pimterry
pimterry / dev.sh
Created December 3, 2016 18:02
Rerun all bats test automatically on change for quick dev feedback
# Run this file (with 'entr' installed) to watch all files and rerun tests on changes
ls -d **/* | entr ./test.sh
@pimterry
pimterry / test.sh
Last active December 3, 2016 17:56
Run all bats tests
# Run this file to run all the tests, once
./test/libs/bats/bin/bats test/*.bats
@pimterry
pimterry / addition-test.bats
Created December 3, 2016 17:41
Demo bats test
#!./test/libs/bats/bin/bats
load 'libs/bats-support/load'
load 'libs/bats-assert/load'
@test "Should add numbers together" {
assert_equal $(echo 1+1 | bc) 2
}
@pimterry
pimterry / install-bats-libs.sh
Created December 3, 2016 17:34
Set up bats libraries for testing as git submodules in test/libs
mkdir -p test/libs
git submodule add https://github.com/sstephenson/bats test/libs/bats
git submodule add https://github.com/ztombol/bats-support test/libs/bats-support
git submodule add https://github.com/ztombol/bats-assert test/libs/bats-assert
async function getThread(github: any, url: string): Promise<Thread> {
let issueMatch = /api.github.com\/repos\/([\-\w]+)\/([\-\w]+)\/issues\/(\d+)/.exec(url);
if (!issueMatch) {
throw new Error(`Received issue notification that didn't match regex: ${url}`);
}
let repo = new Repo(issueMatch[1], issueMatch[2]);
let id = parseInt(issueMatch[3], 10);
let comments = await github.issues.getComments({
class Thread {
constructor (private github: any, private url: string) /* : Promise<Thread> */ {
let issueMatch = /api.github.com\/repos\/([\-\w]+)\/([\-\w]+)\/issues\/(\d+)/.exec(url);
if (!issueMatch) {
throw new Error(`Received issue notification that didn't match regex: ${url}`);
}
this.repo = new Repo(issueMatch[1], issueMatch[2]);
this.id = parseInt(issueMatch[3], 10);
<!DOCTYPE html>
<html>
<head>
<style>
div:not(:target) {
display: none;
}
div:target {
display: block;