I came across this issue while I was working on a functional test for JAMLive!, a Play! application I'm currently working on obsessing over in my free time. I have a controller with a connect
method that looks like this:
After scouring the internet and piece-mealing together the correct way to do this, here is a step-by-step, all-in-one-place guide to making logback STFU when running your unit tests.
Save the following as logback-test.xml
under src/test/resources
:
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%msg%n</pattern>
On the Refinery29 Mobile Web Team, codenamed "Bicycle", all of our unit tests are written using Jasmine, an awesome BDD library written by Pivotal Labs. We recently switched how we set up data for tests from declaring and assigning to closures, to assigning properties to each test case's this
object, and we've seen some awesome benefits from doing such.
Up until recently, a typical unit test for us looked something like this:
describe('views.Card', function() {
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
// See: http://www.programcreek.com/2012/12/leetcode-merge-intervals/ | |
console.log(mergeIntervals([[1,3],[2,6],[8,10],[15,18]])); | |
console.log(mergeIntervals([[1,8], [2,10], [3,6]])); | |
console.log(mergeIntervals([[1,8], [2, 8], [3, 6]])); | |
function mergeIntervals(intervals) { | |
if (intervals.length < 2) { | |
return intervals; | |
} |
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
function concatMap<T, R>( | |
project: (value: T, index: number) => Observable<R> | |
): OperatorFunction<T, R> { | |
let currentIndex = 0; | |
const buffer: Array<Observable<R>> = []; | |
const subscribeTo = ( | |
projected: Observable<R>, | |
obs: Observer<R>, | |
subscriptions: Set<Subscription> |
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
function mergeMap<T, R>( | |
project: (value: T, index: number) => Observable<R> | |
): OperatorFunction<T, R> { | |
let currentIndex = 0; | |
return source => | |
new Observable(obs => { | |
const subscriptions = new Set<Subscription>(); | |
const sub = source.subscribe( | |
x => { | |
const projected = project(x, currentIndex++); |
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
function from<T>(convertible: Promise<T> | ArrayLike<T>): Observable<T> { | |
if (typeof (convertible as any).length === "number") { | |
const arrayLike = convertible as ArrayLike<T>; | |
return new Observable(obs => { | |
for (let i = 0; i < arrayLike.length; i++) { | |
obs.next(arrayLike[i]); | |
} | |
obs.complete(); | |
}); | |
} |
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
const fs = require('fs'); | |
const fetch = require('node-fetch'); | |
const cheerio = require('cheerio'); | |
main().catch(err => console.error(err)); | |
async function main() { | |
const SCARE_RE = /^((\d{1,2}):(\d{1,2})(?::(\d{1,2}))?).*– (.+)$/; | |
const $ = cheerio.load(fs.readFileSync('./notebooks/movielist.html', 'utf8')); | |
const $movieNames = $('td.column-1 > a'); |
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
const syncScheduler: Scheduler = { | |
schedule(work) { | |
work(); | |
} | |
}; | |
const asyncScheduler: Scheduler = { | |
schedule(work) { | |
setTimeout(work, 0); | |
} |
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
interface Scheduler { | |
schedule(work: Function): void; | |
} |
NewerOlder