update tests

This commit is contained in:
Philipp Kunz 2017-06-17 14:44:55 +02:00
parent 4a7749be47
commit 408faa97a4
7 changed files with 437 additions and 397 deletions

View File

@ -10,6 +10,7 @@ class Objectmap {
*/
constructor() {
this.objectArray = [];
// nothing here
}
/**
* add object to Objectmap
@ -102,4 +103,4 @@ class Objectmap {
}
}
exports.Objectmap = Objectmap;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx5Q0FBd0M7QUFVeEM7O0dBRUc7QUFDSDtJQUdJOztPQUVHO0lBQ0g7UUFMUSxnQkFBVyxHQUFRLEVBQUUsQ0FBQTtJQU83QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxHQUFHLENBQUMsU0FBWTtRQUNaLElBQUksQ0FBQyxXQUFXLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxDQUFBO0lBQ3BDLENBQUM7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxjQUFtQjtRQUN4QixHQUFHLENBQUMsQ0FBQyxJQUFJLElBQUksSUFBSSxjQUFjLENBQUMsQ0FBQyxDQUFDO1lBQzlCLElBQUksQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUE7UUFDbEIsQ0FBQztJQUNMLENBQUM7SUFFRDs7T0FFRztJQUNILGNBQWMsQ0FBQyxTQUFZO1FBQ3ZCLE1BQU0sQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQTtJQUNyRCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJLENBQUMsWUFBdUM7UUFDeEMsSUFBSSxXQUFXLEdBQUcsSUFBSSxDQUFDLFdB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dCLENBQUE7SUFDckMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsSUFBSTtRQUNGLElBQUksQ0FBQyxXQUFXLEdBQUcsRUFBRSxDQUFBO0lBQ3ZCLENBQUM7Q0FDRjtBQTNHRCw4QkEyR0MifQ==

View File

@ -1,3 +1,4 @@
/// <reference types="node" />
import * as plugins from './lik.plugins';
import { Objectmap } from './lik.objectmap';
import { Observable } from 'rxjs/Rx';

View File

@ -17,11 +17,7 @@
"url": "https://gitlab.com/pushrocks/lik/issues"
},
"homepage": "https://gitlab.com/pushrocks/lik#README",
"devDependencies": {
"@types/should": "^8.1.30",
"should": "^11.2.1",
"typings-test": "^1.0.3"
},
"devDependencies": {},
"dependencies": {
"@types/lodash": "^4.14.62",
"@types/minimatch": "2.x.x",
@ -30,6 +26,8 @@
"minimatch": "^3.0.3",
"q": "^1.5.0",
"rxjs": "^5.3.0",
"smartq": "^1.1.1",
"tapbundle": "^1.0.14",
"typings-global": "^1.0.14"
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,134 +1,151 @@
import 'typings-test'
import { expect, tap } from 'tapbundle'
import * as events from 'events'
import * as rx from 'rxjs/Rx'
import * as should from 'should'
import * as smartq from 'smartq'
import lik = require('../dist/index')
describe('lik',function(){
describe('Stringmap',function(){
let testStringmap: lik.Stringmap
let testString1 = 'testString1'
let testString2 = 'testString2'
let testString3 = 'testString3'
let testString4 = 'testString4'
let testString5 = 'testString5'
let testString6 = 'testString6'
it('new lik.Objectmap() -> should create an instance of Stringmap',function(){
testStringmap = new lik.Stringmap()
should(testStringmap).be.instanceof(lik.Stringmap)
})
it('lik.Stringmap.checkString -> should return false for an string not in Stringmap',function(){
should(testStringmap.checkString(testString1)).be.false()
})
it('lik.Stringmap.addString -> should add an string to Stringmap',function(){
testStringmap.addString(testString1)
testStringmap.addString(testString2)
testStringmap.addString(testString3)
should(testStringmap.checkString(testString1)).be.true()
should(testStringmap.checkString(testString2)).be.true()
should(testStringmap.checkString(testString3)).be.true()
should(testStringmap.checkMinimatch('*String1')).be.true()
should(testStringmap.checkMinimatch('*String2')).be.true()
should(testStringmap.checkMinimatch('*String4')).be.false()
})
it('lik.Stringmap.addStringArray -> should add an array of strings',function(){
testStringmap.addStringArray([testString4,testString5,testString6])
should(testStringmap.checkMinimatch('*String4')).be.true()
})
it('lik.Stringmap.removeString -> should remove a string from Stringmap',function(){
testStringmap.removeString(testString2)
should(testStringmap.checkString(testString2)).be.false()
})
it('lik.Stringmap.getStringArray() -> should return a copy of stringArray',function(){
let clonedArray = testStringmap.getStringArray()
should(clonedArray[0] === 'testString1').be.true()
should(clonedArray[0] === testString1).be.true()
})
it('lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty',function(){
testStringmap.registerUntilTrue(
() => { return testStringmap.checkIsEmpty() },
() => { console.log('Stringmap now is empty') }
)
})
it('lik.Stringmap.empty() -> should remove wipe and then notify',function(){
testStringmap.wipe()
})
})
describe('Objectmap',function(){
interface ITestObject {
propOne: string
propTwo: string
}
let testObjectmap: lik.Objectmap<ITestObject>
let testObject1: ITestObject = {
propOne: 'hello',
propTwo: 'hello2'
}
let testObject2: ITestObject = {
propOne: 'hello',
propTwo: 'hello2'
}
it('new lik.Objectmap() -> should correctly instantiate an Objectmap',function(){
testObjectmap = new lik.Objectmap<ITestObject>()
should(testObjectmap).be.instanceof(lik.Objectmap)
})
it('lik.Objectmap.add() -> should correctly add an object to Objectmap',function(){
testObjectmap.add(testObject1)
should(testObjectmap.checkForObject(testObject1)).be.true
should(testObjectmap.checkForObject(testObject2)).be.false
})
it('lik.Objectmap.remove() -> should correctly remove an object to Objectmap',function(){
testObjectmap.add(testObject2)
testObjectmap.remove(testObject1)
should(testObjectmap.checkForObject(testObject1)).be.false
should(testObjectmap.checkForObject(testObject2)).be.true
})
it('Objectmap.forEach -> should correctly run a function forEach map object',function(){
testObjectmap.forEach(itemArg => {
should(itemArg).have.ownProperty('propOne')
})
})
it('lik.Objectmap.find() -> should correctly find an object',function(){
let myObject = {propOne: 'helloThere', propTwo: 'helloAnyway'}
testObjectmap.add(myObject)
let referenceObject = testObjectmap.find((itemArg) => { return (itemArg.propOne === 'helloThere') })
should(myObject === referenceObject).be.true()
})
it('lik.Objectmap.getArray() -> should return a cloned array', function(){
let myObject = {propOne : 'test1', propTwo: 'wow, how awesome'}
testObjectmap.add(myObject)
let clonedArray = testObjectmap.getArray()
should(clonedArray[clonedArray.length - 1]).eql(myObject)
})
it('should get one object and then remove it', function() {
let originalLength = testObjectmap.getArray().length
let oneObject = testObjectmap.getOneAndRemove()
should(oneObject).not.be.null()
should(testObjectmap.getArray().length).equal(originalLength - 1)
should(testObjectmap.getArray()).not.containEql(oneObject)
})
})
describe('Observablemap',function(){
let testObservablemap: lik.Observablemap
let testObservable1: rx.Observable<any>
let testObservable2: rx.Observable<any>
let testObservable3: rx.Observable<any>
let testEmitter: events.EventEmitter
it('should create an instance',function(){
testObservablemap = new lik.Observablemap()
should(testObservablemap).be.instanceof(lik.Observablemap)
})
it('should accept a new emitter',function(done) {
testEmitter = new events.EventEmitter()
testObservable1 = testObservablemap.getObservableForEmitterEvent(testEmitter,'event1')
testObservable1.subscribe(x => {
done()
})
testObservable2 = testObservablemap.getObservableForEmitterEvent(testEmitter,'event1')
testObservable3 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event2')
should(testObservable1 === testObservable2).be.true()
should(testObservable1 === testObservable3).be.false()
testEmitter.emit('event1')
})
})
let testStringmap: lik.Stringmap
let testString1 = 'testString1'
let testString2 = 'testString2'
let testString3 = 'testString3'
let testString4 = 'testString4'
let testString5 = 'testString5'
let testString6 = 'testString6'
tap.test('new lik.Objectmap() -> should create an instance of Stringmap', async () => {
testStringmap = new lik.Stringmap()
expect(testStringmap).be.instanceof(lik.Stringmap)
})
tap.test('lik.Stringmap.checkString -> should return false for an string not in Stringmap', async () => {
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString1)).be.false
})
tap.test('lik.Stringmap.addString -> should add an string to Stringmap', async () => {
testStringmap.addString(testString1)
testStringmap.addString(testString2)
testStringmap.addString(testString3)
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString1)).be.true
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString2)).be.true
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString3)).be.true
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkMinimatch('*String1')).be.true
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkMinimatch('*String2')).be.true
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkMinimatch('*String4')).be.false
})
tap.test('lik.Stringmap.addStringArray -> should add an array of strings', async () => {
testStringmap.addStringArray([ testString4, testString5, testString6 ])
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkMinimatch('*String4')).be.true
})
tap.test('lik.Stringmap.removeString -> should remove a string from Stringmap', async () => {
testStringmap.removeString(testString2)
// tslint:disable-next-line:no-unused-expression
expect(testStringmap.checkString(testString2)).be.false
})
tap.test('lik.Stringmap.getStringArray() -> should return a copy of stringArray', async () => {
let clonedArray = testStringmap.getStringArray()
// tslint:disable-next-line:no-unused-expression
expect(clonedArray[ 0 ] === 'testString1').be.true
// tslint:disable-next-line:no-unused-expression
expect(clonedArray[ 0 ] === testString1).be.true
})
tap.test('lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty', async () => {
testStringmap.registerUntilTrue(
() => { return testStringmap.checkIsEmpty() },
() => { console.log('Stringmap now is empty') }
)
})
tap.test('lik.Stringmap.empty() -> should remove wipe and then notify', async () => {
testStringmap.wipe()
})
// Objectmap
interface ITestObject {
propOne: string
propTwo: string
}
let testObjectmap: lik.Objectmap<ITestObject>
let testObject1: ITestObject = {
propOne: 'hello',
propTwo: 'hello2'
}
let testObject2: ITestObject = {
propOne: 'hello',
propTwo: 'hello2'
}
tap.test('new lik.Objectmap() -> should correctly instantiate an Objectmap', async () => {
testObjectmap = new lik.Objectmap<ITestObject>()
expect(testObjectmap).be.instanceof(lik.Objectmap)
})
tap.test('lik.Objectmap.add() -> should correctly add an object to Objectmap', async () => {
testObjectmap.add(testObject1)
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject1)).be.true
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject2)).be.false
})
tap.test('lik.Objectmap.remove() -> should correctly remove an object to Objectmap', async () => {
testObjectmap.add(testObject2)
testObjectmap.remove(testObject1)
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject1)).be.false
// tslint:disable-next-line:no-unused-expression
expect(testObjectmap.checkForObject(testObject2)).be.true
})
tap.test('Objectmap.forEach -> should correctly run a function forEach map object', async () => {
testObjectmap.forEach(itemArg => {
expect(itemArg).have.ownProperty('propOne')
})
})
tap.test('lik.Objectmap.find() -> should correctly find an object', async () => {
let myObject = { propOne: 'helloThere', propTwo: 'helloAnyway' }
testObjectmap.add(myObject)
let referenceObject = testObjectmap.find((itemArg) => { return (itemArg.propOne === 'helloThere') })
// tslint:disable-next-line:no-unused-expression
expect(myObject === referenceObject).be.true
})
tap.test('lik.Objectmap.getArray() -> should return a cloned array', async () => {
let myObject = { propOne: 'test1', propTwo: 'wow, how awesome' }
testObjectmap.add(myObject)
let clonedArray = testObjectmap.getArray()
expect(clonedArray[ clonedArray.length - 1 ]).eql(myObject)
})
tap.test('should get one object and then remove it', async () => {
let originalLength = testObjectmap.getArray().length
let oneObject = testObjectmap.getOneAndRemove()
// tslint:disable-next-line:no-unused-expression
expect(oneObject).not.be.null
expect(testObjectmap.getArray().length).equal(originalLength - 1)
expect(testObjectmap.getArray()).to.not.contain(oneObject)
})
let testObservablemap: lik.Observablemap
let testObservable1: rx.Observable<any>
let testObservable2: rx.Observable<any>
let testObservable3: rx.Observable<any>
let testEmitter: events.EventEmitter
tap.test('should create an instance', async () => {
testObservablemap = new lik.Observablemap()
expect(testObservablemap).be.instanceof(lik.Observablemap)
})
tap.test('should accept a new emitter', async () => {
let done = smartq.defer()
testEmitter = new events.EventEmitter()
testObservable1 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1')
testObservable1.subscribe(x => {
done.resolve()
})
testObservable2 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1')
testObservable3 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event2')
// tslint:disable-next-line:no-unused-expression
expect(testObservable1 === testObservable2).be.true
// tslint:disable-next-line:no-unused-expression
expect(testObservable1 === testObservable3).be.false
testEmitter.emit('event1')
await done.promise
})
tap.start()

View File

@ -1,121 +1,121 @@
import * as plugins from './lik.plugins'
export interface IObjectmapForEachFunction<T> {
(itemArg: T): void
(itemArg: T): void
}
export interface IObjectmapFindFunction<T> {
(itemArg: T): boolean
(itemArg: T): boolean
}
/**
* allows keeping track of objects
*/
export class Objectmap<T> {
private objectArray: T[] = []
private objectArray: T[] = []
/**
* returns a new instance
*/
constructor() {
/**
* returns a new instance
*/
constructor () {
// nothing here
}
/**
* add object to Objectmap
*/
add (objectArg: T) {
this.objectArray.push(objectArg)
}
/**
* like .add but adds an whole array of objects
*/
addArray (objectArrayArg: T[]) {
for (let item of objectArrayArg) {
this.add(item)
}
}
/**
* add object to Objectmap
*/
add(objectArg: T) {
this.objectArray.push(objectArg)
}
/**
* check if object is in Objectmap
*/
checkForObject (objectArg: T) {
return this.objectArray.indexOf(objectArg) !== -1
}
/**
* like .add but adds an whole array of objects
*/
addArray(objectArrayArg: T[]) {
for (let item of objectArrayArg) {
this.add(item)
}
/**
* find object
*/
find (findFunction: IObjectmapFindFunction<T>) {
let resultArray = this.objectArray.filter(findFunction)
if (resultArray.length > 0) {
return resultArray[ 0 ]
} else {
return null
}
}
/**
* check if object is in Objectmap
*/
checkForObject(objectArg: T) {
return this.objectArray.indexOf(objectArg) !== -1
/**
* finds a specific element and then removes it
*/
findOneAndRemove (findFunction): T {
let foundElement = this.find(findFunction)
if (foundElement) {
this.remove(foundElement)
}
return foundElement
}
/**
* find object
*/
find(findFunction: IObjectmapFindFunction<T>) {
let resultArray = this.objectArray.filter(findFunction)
if (resultArray.length > 0) {
return resultArray[0]
} else {
return null
}
}
/**
* run function for each item in Objectmap
*/
forEach (functionArg: IObjectmapForEachFunction<T>) {
return this.objectArray.forEach(functionArg)
}
/**
* finds a specific element and then removes it
*/
findOneAndRemove(findFunction): T {
let foundElement = this.find(findFunction)
if (foundElement) {
this.remove(foundElement)
}
return foundElement
}
/**
* gets an object in the Observablemap and removes it, so it can't be retrieved again
*/
getOneAndRemove (): T {
return this.objectArray.shift()
}
/**
* run function for each item in Objectmap
*/
forEach(functionArg: IObjectmapForEachFunction<T>) {
return this.objectArray.forEach(functionArg)
}
/**
* returns a cloned array of all the objects currently in the Objectmap
*/
getArray () {
return plugins.lodash.cloneDeep(this.objectArray)
}
/**
* gets an object in the Observablemap and removes it, so it can't be retrieved again
*/
getOneAndRemove(): T {
return this.objectArray.shift()
/**
* check if Objectmap ist empty
*/
isEmpty (): boolean {
if (this.objectArray.length === 0) {
return true
} else {
return false
}
}
/**
* returns a cloned array of all the objects currently in the Objectmap
*/
getArray() {
return plugins.lodash.cloneDeep(this.objectArray)
/**
* remove object from Objectmap
*/
remove (objectArg: T) {
let replacementArray = []
for (let item of this.objectArray) {
if (item !== objectArg) {
replacementArray.push(item)
}
}
this.objectArray = replacementArray
}
/**
* check if Objectmap ist empty
*/
isEmpty(): boolean {
if (this.objectArray.length === 0) {
return true
} else {
return false
}
}
/**
* remove object from Objectmap
*/
remove(objectArg: T) {
let replacementArray = []
for (let item of this.objectArray) {
if (item !== objectArg) {
replacementArray.push(item)
}
}
this.objectArray = replacementArray
}
/**
* wipe Objectmap
*/
wipe() {
this.objectArray = []
}
/**
* wipe Objectmap
*/
wipe () {
this.objectArray = []
}
}

236
yarn.lock
View File

@ -2,6 +2,23 @@
# yarn lockfile v1
"@types/chai-as-promised@0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-0.0.29.tgz#43d52892aa998e185a3de3e2477edb8573be1d77"
dependencies:
"@types/chai" "*"
"@types/promises-a-plus" "*"
"@types/chai-string@^1.1.30":
version "1.1.30"
resolved "https://registry.yarnpkg.com/@types/chai-string/-/chai-string-1.1.30.tgz#4d8744b31a5a2295fc01c981ed1e2d4c8a070f0a"
dependencies:
"@types/chai" "*"
"@types/chai@*", "@types/chai@^3.4.35":
version "3.5.2"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-3.5.2.tgz#c11cd2817d3a401b7ba0f5a420f35c56139b1c1e"
"@types/lodash@^4.14.62":
version "4.14.62"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.62.tgz#8674f9861582148a60b7a89cb260f11378d11683"
@ -10,22 +27,51 @@
version "2.0.29"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-2.0.29.tgz#5002e14f75e2d71e564281df0431c8c1b4a2a36a"
"@types/mocha@^2.2.31":
version "2.2.40"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.40.tgz#9811dd800ece544cd84b5b859917bf584a150c4c"
"@types/node@*", "@types/node@^7.0.29":
version "7.0.31"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.31.tgz#80ea4d175599b2a00149c29a10a4eb2dff592e86"
"@types/promises-a-plus@*":
version "0.0.27"
resolved "https://registry.yarnpkg.com/@types/promises-a-plus/-/promises-a-plus-0.0.27.tgz#c64651134614c84b8f5d7114ce8901d36a609780"
"@types/q@1.x.x":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.0.0.tgz#57e5465d665b370d4217e69b344b20faa6b724f5"
"@types/should@^8.1.30":
version "8.1.30"
resolved "https://registry.yarnpkg.com/@types/should/-/should-8.1.30.tgz#e6b4f3ca4fb0799f6ce3303f3a8c003df6585aa3"
"@types/shelljs@^0.6.0":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.6.0.tgz#090b705c102ce7fc5c0c5ea9b524418ff15840df"
dependencies:
"@types/node" "*"
"@types/which@^1.0.28":
version "1.0.28"
resolved "https://registry.yarnpkg.com/@types/which/-/which-1.0.28.tgz#016e387629b8817bed653fe32eab5d11279c8df6"
ansi-256-colors@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-256-colors/-/ansi-256-colors-1.1.0.tgz#910de50efcc7c09e3d82f2f87abd6b700c18818a"
assertion-error@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c"
balanced-match@^0.4.1:
version "0.4.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"
beautycolor@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/beautycolor/-/beautycolor-1.0.7.tgz#a4715738ac4c8221371e9cbeb5a6cc6d11ecbf7c"
dependencies:
ansi-256-colors "^1.1.0"
typings-global "^1.0.14"
bindings@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.2.1.tgz#14ad6113812d2d37d72e67b4cacb4bb726505f11"
brace-expansion@^1.0.0:
version "1.1.7"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.7.tgz#3effc3c50e000531fb720eaff80f0ae8ef23cf59"
@ -33,10 +79,50 @@ brace-expansion@^1.0.0:
balanced-match "^0.4.1"
concat-map "0.0.1"
chai-as-promised@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-6.0.0.tgz#1a02a433a6f24dafac63b9c96fa1684db1aa8da6"
dependencies:
check-error "^1.0.2"
chai-string@^1.3.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/chai-string/-/chai-string-1.4.0.tgz#359140c051d36a4e4b1a5fc6b910152f438a8d49"
chai@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247"
dependencies:
assertion-error "^1.0.1"
deep-eql "^0.1.3"
type-detect "^1.0.0"
check-error@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
deep-eql@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2"
dependencies:
type-detect "0.1.1"
early@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/early/-/early-2.1.1.tgz#841e23254ea5dc54d8afaeee82f5ab65c00ee23c"
dependencies:
beautycolor "^1.0.7"
smartq "^1.1.1"
typings-global "^1.0.16"
es6-error@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.0.2.tgz#eec5c726eacef51b7f6b73c20db6e1b13b069c98"
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@ -67,16 +153,49 @@ interpret@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.2.tgz#f4f623f0bb7122f15f5717c8e254b8161b5c5b2d"
isexe@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
leakage@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/leakage/-/leakage-0.3.0.tgz#15d698abdc76bbc6439601f4f3020e77e2d50c39"
dependencies:
es6-error "^4.0.2"
left-pad "^1.1.3"
memwatch-next "^0.3.0"
minimist "^1.2.0"
pretty-bytes "^4.0.2"
left-pad@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"
lodash@^4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
memwatch-next@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/memwatch-next/-/memwatch-next-0.3.0.tgz#2111050f9a906e0aa2d72a4ec0f0089c78726f8f"
dependencies:
bindings "^1.2.1"
nan "^2.3.2"
minimatch@^3.0.2, minimatch@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774"
dependencies:
brace-expansion "^1.0.0"
minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
nan@^2.3.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45"
once@^1.3.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
@ -91,6 +210,10 @@ path-parse@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1"
pretty-bytes@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-4.0.2.tgz#b2bf82e7350d65c6c33aa95aaa5a4f6327f61cd9"
q@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.0.tgz#dd01bac9d06d30e6f219aecb8253ee9ebdc308f1"
@ -117,7 +240,7 @@ semver@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
shelljs@^0.7.4:
shelljs@^0.7.4, shelljs@^0.7.6:
version "0.7.7"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.7.tgz#b2f5c77ef97148f4b4f6e22682e10bba8667cff1"
dependencies:
@ -125,61 +248,88 @@ shelljs@^0.7.4:
interpret "^1.0.0"
rechoir "^0.6.2"
should-equal@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/should-equal/-/should-equal-1.0.1.tgz#0b6e9516f2601a9fb0bb2dcc369afa1c7e200af7"
smartchai@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/smartchai/-/smartchai-1.0.3.tgz#de6d010bb8b5aef24cb70b31a5f5334e8c41b72f"
dependencies:
should-type "^1.0.0"
"@types/chai" "^3.4.35"
"@types/chai-as-promised" "0.0.29"
"@types/chai-string" "^1.1.30"
chai "^3.5.0"
chai-as-promised "^6.0.0"
chai-string "^1.3.0"
should-format@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/should-format/-/should-format-3.0.3.tgz#9bfc8f74fa39205c53d38c34d717303e277124f1"
smartdelay@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/smartdelay/-/smartdelay-1.0.3.tgz#5fd44dad77262d110702f0293efa80c072cfb579"
dependencies:
should-type "^1.3.0"
should-type-adaptors "^1.0.1"
smartq "^1.1.1"
typings-global "^1.0.16"
should-type-adaptors@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/should-type-adaptors/-/should-type-adaptors-1.0.1.tgz#efe5553cdf68cff66e5c5f51b712dc351c77beaa"
smartq@^1.1.0, smartq@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/smartq/-/smartq-1.1.1.tgz#efb358705260d41ae18aef7ffd815f7b6fe17dd3"
dependencies:
should-type "^1.3.0"
should-util "^1.0.0"
typed-promisify "^0.3.0"
typings-global "^1.0.14"
should-type@^1.0.0, should-type@^1.3.0, should-type@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/should-type/-/should-type-1.4.0.tgz#0756d8ce846dfd09843a6947719dfa0d4cff5cf3"
should-util@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/should-util/-/should-util-1.0.0.tgz#c98cda374aa6b190df8ba87c9889c2b4db620063"
should@^11.2.1:
version "11.2.1"
resolved "https://registry.yarnpkg.com/should/-/should-11.2.1.tgz#90f55145552d01cfc200666e4e818a1c9670eda2"
smartshell@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/smartshell/-/smartshell-1.0.6.tgz#27b1c79029784abe72ac7e91fe698b7ebecc6629"
dependencies:
should-equal "^1.0.0"
should-format "^3.0.2"
should-type "^1.4.0"
should-type-adaptors "^1.0.1"
should-util "^1.0.0"
"@types/shelljs" "^0.6.0"
"@types/which" "^1.0.28"
shelljs "^0.7.6"
smartq "^1.1.0"
which "^1.2.12"
symbol-observable@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d"
typings-global@*, typings-global@^1.0.14:
tapbundle@^1.0.14:
version "1.0.14"
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-1.0.14.tgz#75827e335fcb02216f0267a26a26d702ddc02e3c"
dependencies:
early "^2.1.1"
leakage "^0.3.0"
smartchai "^1.0.3"
smartdelay "^1.0.3"
smartq "^1.1.1"
typings-global "^1.0.16"
type-detect@0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822"
type-detect@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2"
typed-promisify@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/typed-promisify/-/typed-promisify-0.3.0.tgz#1ba0af5e444c87d8047406f18ce49092a1191853"
typings-global@^1.0.14:
version "1.0.14"
resolved "https://registry.yarnpkg.com/typings-global/-/typings-global-1.0.14.tgz#ab682720a03d6b9278869fb5c30c30d7dc61d12c"
dependencies:
semver "^5.3.0"
shelljs "^0.7.4"
typings-test@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/typings-test/-/typings-test-1.0.3.tgz#fbab895eb3f0c44842e73db059f65946b971e369"
typings-global@^1.0.16:
version "1.0.17"
resolved "https://registry.yarnpkg.com/typings-global/-/typings-global-1.0.17.tgz#41edc331ccec3168289adc8849e1e255efbe7152"
dependencies:
"@types/mocha" "^2.2.31"
typings-global "*"
"@types/node" "^7.0.29"
semver "^5.3.0"
smartshell "^1.0.6"
which@^1.2.12:
version "1.2.14"
resolved "https://registry.yarnpkg.com/which/-/which-1.2.14.tgz#9a87c4378f03e827cecaf1acdf56c736c01c14e5"
dependencies:
isexe "^2.0.0"
wrappy@1:
version "1.0.2"