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
| { | |
| "version": "0.2.0", | |
| "configurations": [{ | |
| "type": "node", | |
| "request": "launch", | |
| "name": "Launch program", | |
| "skipFiles": ["<node_internals>/**"], | |
| "cwd": "${workspaceRoot}", | |
| "envFile": "${workspaceFolder}/.env", | |
| "runtimeExecutable": "${env:NVM_DIR}/nvm-exec", |
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, match } from 'sinon'; | |
| import { anonymousExample } from '../src/anonymous-example'; | |
| describe('anonymousExample()', () => { | |
| beforeEach(() => { | |
| stub(console, 'log'); | |
| }); | |
| it('should log first v when v is 1', () => { |
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 anonymousExample(callbacker: (x: (v: number) => void) => void) { | |
| callbacker((v) => { | |
| if (v === 1) { | |
| console.log('first v!'); | |
| } else { | |
| console.log('another v!'); | |
| } | |
| }); | |
| } |
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, match, SinonStub } from 'sinon'; | |
| import request = require('superagent'); | |
| import { superagentExample } from '../src/superagent-example'; | |
| describe('superAgentExample()', () => { | |
| let send: SinonStub; | |
| let set1: SinonStub; | |
| let set2: SinonStub; |
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, match } from 'sinon'; | |
| import request = require('superagent'); | |
| import { superagentExample } from '../src/superagent-example'; | |
| describe('superAgentExample()', () => { | |
| let requestResult: request.SuperAgentRequest; | |
| beforeEach(() => { | |
| requestResult = Promise.resolve({ body: 'expected body' }) 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 { EventEmitter } from 'events'; | |
| import { expect } from 'chai'; | |
| import { stub } from 'sinon'; | |
| import { eventEmitterExample } from '../src/event-emitter-example'; | |
| describe.only('eventEmitterExample()', () => { | |
| beforeEach(() => { | |
| stub(console, 'info'); | |
| stub(console, '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 { 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}`); | |
| }); |
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 { 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 } 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); | |
| }); |
NewerOlder