This file contains hidden or 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
| import UntestableClass from 'untestable-class'; | |
| export interface NowTestableClassType { | |
| someMethod(p: number): string; | |
| } | |
| export const NowTestableClass = UntestableClass as new (constructorParam: string) => NowTestableClassType; |
This file contains hidden or 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
| export function doubleConsole() { | |
| console.log('Now you see me'); | |
| setTimeout(() => console.log("Now you don't"), 100); | |
| setImmediate(() => console.log("Now still")); | |
| } |
This file contains hidden or 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
| import { expect } from 'chai'; | |
| import { SinonFakeTimers, useFakeTimers, stub, match } from 'sinon'; | |
| import { doubleConsole } from '../src/double-console'; | |
| describe.only('doubleConsole()', () => { | |
| let clock: SinonFakeTimers; | |
| beforeEach(() => { | |
| clock = useFakeTimers(); | |
| stub(global, 'setImmediate').callThrough(); |
This file contains hidden or 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
| import { expect } from 'chai'; | |
| import { match, stub } from 'sinon'; | |
| import { doubleConsole } from '../src/double-console'; | |
| describe.only('doubleConsole()', () => { | |
| let callbackSetImmediate: any; | |
| let callbackSetTimeout: any; | |
| beforeEach(() => { | |
| stub(global, 'setImmediate').callsFake((x) => { |
This file contains hidden or 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
| import { Readable } from 'stream'; | |
| import { createGzip } from 'zlib'; | |
| export function streamExample(stream: Readable) { | |
| return stream | |
| .pipe(createGzip()); | |
| } |
This file contains hidden or 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
| import { expect } from 'chai'; | |
| import { stub } from 'sinon'; | |
| import * as zlib from 'zlib'; | |
| import { streamExample } from '../src/stream-example'; | |
| import { Readable, Writable } from 'stream'; | |
| describe('streamExample()', () => { | |
| let data: any[]; | |
| let writable: Writable; |
This file contains hidden or 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
| import { expect } from 'chai'; | |
| import { stub } from 'sinon'; | |
| import * as zlib from 'zlib'; | |
| import { streamExample } from '../src/stream-example'; | |
| describe.only('streamExample()', () => { | |
| beforeEach(() => { | |
| stub(zlib, 'createGzip').returns('createGZip result' as any); | |
| }); |
This file contains hidden or 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
| import { Readable } from 'stream'; | |
| import { gzip } from 'zlib'; | |
| export async function notSoSimpleStreamExample(stream: Readable) { | |
| return new Promise((resolve, reject) => { | |
| const data: Array<Promise<Buffer>> = []; | |
| stream.on('data', info => { | |
| data.push(new Promise((resolve, reject) => { | |
| gzip(info, (error, result) => { | |
| if (error) { |
This file contains hidden or 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
| import { expect } from 'chai'; | |
| import { stub, SinonStub, match } from 'sinon'; | |
| import * as zlib from 'zlib'; | |
| import { notSoSimpleStreamExample } from '../src/not-so-simple-stream-example'; | |
| import { ObjectReadableMock } from 'stream-mock'; | |
| describe('notSoSimpleStreamExample()', () => { | |
| let data: any[] = []; | |
| let gzip: SinonStub<any, any>; |
This file contains hidden or 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
| import { EventEmitter } from 'events'; | |
| export function eventEmitterExample(emitter: EventEmitter) { | |
| emitter.on('somethingHappen', (x) => { | |
| console.info(`Something happened! ${x}`); | |
| }); | |
| emitter.on('sometingGoesWrong', (x) => { | |
| console.error(`Something went wrong! ${x}`); | |
| }); |