feat: 초기 프로젝트 설정 및 룰.md 파일 추가
This commit is contained in:
48
api.hyungi.net/node_modules/shimmer/test/init.tap.js
generated
vendored
Normal file
48
api.hyungi.net/node_modules/shimmer/test/init.tap.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
'use strict'
|
||||
|
||||
var tap = require('tap')
|
||||
var test = tap.test
|
||||
var sinon = require('sinon')
|
||||
var shimmer = require('../index.js')
|
||||
|
||||
test('shimmer initialization', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
t.doesNotThrow(function () { shimmer() })
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withArgs('no original function undefined to wrap')
|
||||
.once()
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer({ logger: mock })
|
||||
}, "initializer doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.wrap()
|
||||
}, "invoking the wrap method with no params doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger method was called with the expected message')
|
||||
})
|
||||
|
||||
test('shimmer initialized with non-function logger', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withArgs("new logger isn't a function, not replacing")
|
||||
.once()
|
||||
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer({ logger: { ham: 'chunx' } })
|
||||
}, "even bad initialization doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger initialization failed in the expected way')
|
||||
})
|
||||
121
api.hyungi.net/node_modules/shimmer/test/massUnwrap.tap.js
generated
vendored
Normal file
121
api.hyungi.net/node_modules/shimmer/test/massUnwrap.tap.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
'use strict'
|
||||
|
||||
var tap = require('tap')
|
||||
var test = tap.test
|
||||
var sinon = require('sinon')
|
||||
var shimmer = require('../index.js')
|
||||
|
||||
var outsider = 0
|
||||
function counter () { return ++outsider }
|
||||
function anticounter () { return --outsider }
|
||||
|
||||
var generator = {
|
||||
inc: counter,
|
||||
dec: anticounter
|
||||
}
|
||||
|
||||
test('should unwrap safely', function (t) {
|
||||
t.plan(18)
|
||||
|
||||
t.equal(counter, generator.inc, 'basic function equality testing should work')
|
||||
t.equal(anticounter, generator.dec, 'basic function equality testing should work')
|
||||
t.doesNotThrow(function () { generator.inc() })
|
||||
t.equal(1, outsider, 'calls have side effects')
|
||||
t.doesNotThrow(function () { generator.dec() })
|
||||
t.equal(0, outsider, 'calls have side effects')
|
||||
|
||||
function wrapper (original) {
|
||||
return function () {
|
||||
return original.apply(this, arguments)
|
||||
}
|
||||
}
|
||||
shimmer.massWrap(generator, ['inc', 'dec'], wrapper)
|
||||
|
||||
t.doesNotEqual(counter, generator.inc, 'function should be wrapped')
|
||||
t.doesNotEqual(anticounter, generator.dec, 'function should be wrapped')
|
||||
|
||||
t.doesNotThrow(function () { generator.inc() })
|
||||
t.equal(1, outsider, 'original function has still been called')
|
||||
t.doesNotThrow(function () { generator.dec() })
|
||||
t.equal(0, outsider, 'original function has still been called')
|
||||
|
||||
shimmer.massUnwrap(generator, ['inc', 'dec'])
|
||||
t.equal(counter, generator.inc, 'basic function equality testing should work')
|
||||
t.equal(anticounter, generator.dec, 'basic function equality testing should work')
|
||||
|
||||
t.doesNotThrow(function () { generator.inc() })
|
||||
t.equal(1, outsider, 'original function has still been called')
|
||||
t.doesNotThrow(function () { generator.dec() })
|
||||
t.equal(0, outsider, 'original function has still been called')
|
||||
})
|
||||
|
||||
test("shouldn't throw on double unwrapping", function (t) {
|
||||
t.plan(10)
|
||||
|
||||
t.equal(counter, generator.inc, 'basic function equality testing should work')
|
||||
t.equal(anticounter, generator.dec, 'basic function equality testing should work')
|
||||
|
||||
var mock = sinon.stub()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
function wrapper (original) {
|
||||
return function () {
|
||||
return original.apply(this, arguments)
|
||||
}
|
||||
}
|
||||
shimmer.wrap(generator, 'inc', wrapper)
|
||||
shimmer.wrap(generator, 'dec', wrapper)
|
||||
|
||||
t.doesNotEqual(counter, generator.inc, 'function should be wrapped')
|
||||
t.doesNotEqual(anticounter, generator.dec, 'function should be wrapped')
|
||||
|
||||
shimmer.massUnwrap(generator, ['inc', 'dec'])
|
||||
t.equal(counter, generator.inc, 'basic function equality testing should work')
|
||||
t.equal(anticounter, generator.dec, 'basic function equality testing should work')
|
||||
|
||||
t.doesNotThrow(function () { shimmer.massUnwrap(generator, ['inc', 'dec']) },
|
||||
'should double unwrap without issue')
|
||||
t.equal(counter, generator.inc, 'function is unchanged after unwrapping')
|
||||
t.equal(anticounter, generator.dec, 'function is unchanged after unwrapping')
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
sinon.assert.calledWith(mock, 'no original to unwrap to -- ' +
|
||||
'has inc already been unwrapped?')
|
||||
sinon.assert.calledWith(mock, 'no original to unwrap to -- ' +
|
||||
'has dec already been unwrapped?')
|
||||
sinon.assert.calledTwice(mock)
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('massUnwrap called with no arguments', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.twice()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () { shimmer.massUnwrap() }, 'should log instead of throwing')
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('massUnwrap called with module but nothing else', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withExactArgs('must provide one or more functions to unwrap on modules')
|
||||
.once()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.massUnwrap(generator)
|
||||
}, "wrapping with only 1 argument doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
174
api.hyungi.net/node_modules/shimmer/test/massWrap.tap.js
generated
vendored
Normal file
174
api.hyungi.net/node_modules/shimmer/test/massWrap.tap.js
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
'use strict'
|
||||
|
||||
var tap = require('tap')
|
||||
var test = tap.test
|
||||
var sinon = require('sinon')
|
||||
var shimmer = require('../index.js')
|
||||
|
||||
var outsider = 0
|
||||
function counter () { return ++outsider }
|
||||
function anticounter () { return --outsider }
|
||||
|
||||
var generator = {
|
||||
inc: counter,
|
||||
dec: anticounter
|
||||
}
|
||||
|
||||
var arrow = {
|
||||
in: counter,
|
||||
out: anticounter
|
||||
}
|
||||
|
||||
var nester = {
|
||||
in: counter,
|
||||
out: anticounter
|
||||
}
|
||||
|
||||
test('should wrap multiple functions safely', function (t) {
|
||||
t.plan(9)
|
||||
|
||||
t.equal(counter, generator.inc, 'basic function equality testing should work')
|
||||
t.equal(anticounter, generator.dec, 'basic function equality testing should work')
|
||||
t.doesNotThrow(function () { generator.inc() })
|
||||
t.doesNotThrow(function () { generator.dec() })
|
||||
t.equal(0, outsider, 'calls have side effects')
|
||||
|
||||
var count = 0
|
||||
function wrapper (original) {
|
||||
return function () {
|
||||
count++
|
||||
var returned = original.apply(this, arguments)
|
||||
count++
|
||||
return returned
|
||||
}
|
||||
}
|
||||
shimmer.massWrap(generator, ['inc', 'dec'], wrapper)
|
||||
|
||||
t.doesNotThrow(function () { generator.inc() })
|
||||
t.doesNotThrow(function () { generator.dec() })
|
||||
t.equal(4, count, 'both pre and post increments should have happened')
|
||||
t.equal(0, outsider, 'original function has still been called')
|
||||
})
|
||||
|
||||
test('should wrap multiple functions on multiple modules safely', function (t) {
|
||||
t.plan(15)
|
||||
|
||||
t.equal(counter, arrow.in, 'basic function equality testing should work')
|
||||
t.equal(counter, nester.in, 'basic function equality testing should work')
|
||||
t.equal(anticounter, arrow.out, 'basic function equality testing should work')
|
||||
t.equal(anticounter, nester.out, 'basic function equality testing should work')
|
||||
|
||||
t.doesNotThrow(function () { arrow.in() })
|
||||
t.doesNotThrow(function () { nester.in() })
|
||||
t.doesNotThrow(function () { arrow.out() })
|
||||
t.doesNotThrow(function () { nester.out() })
|
||||
|
||||
t.equal(0, outsider, 'calls have side effects')
|
||||
|
||||
var count = 0
|
||||
function wrapper (original) {
|
||||
return function () {
|
||||
count++
|
||||
var returned = original.apply(this, arguments)
|
||||
count++
|
||||
return returned
|
||||
}
|
||||
}
|
||||
shimmer.massWrap([arrow, nester], ['in', 'out'], wrapper)
|
||||
|
||||
t.doesNotThrow(function () { arrow.in() })
|
||||
t.doesNotThrow(function () { arrow.out() })
|
||||
t.doesNotThrow(function () { nester.in() })
|
||||
t.doesNotThrow(function () { nester.out() })
|
||||
|
||||
t.equal(8, count, 'both pre and post increments should have happened')
|
||||
t.equal(0, outsider, 'original function has still been called')
|
||||
})
|
||||
|
||||
test('wrap called with no arguments', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.twice()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.massWrap()
|
||||
}, "wrapping with no arguments doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('wrap called with module but nothing else', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withExactArgs('must provide one or more functions to wrap on modules')
|
||||
.once()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.massWrap(generator)
|
||||
}, "wrapping with only 1 argument doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('wrap called with original but no wrapper', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.twice()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.massWrap(generator, ['inc'])
|
||||
}, "wrapping with only original function doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('wrap called with non-function original', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withExactArgs('must provide one or more functions to wrap on modules')
|
||||
.once()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.massWrap({ orange: 'slices' }, 'orange', function () {})
|
||||
}, "wrapping non-function original doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('wrap called with non-function wrapper', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withArgs('must provide one or more functions to wrap on modules')
|
||||
.once()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.massWrap({ orange: function () {} }, 'orange', 'hamchunx')
|
||||
}, "wrapping with non-function wrapper doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
101
api.hyungi.net/node_modules/shimmer/test/unwrap.tap.js
generated
vendored
Normal file
101
api.hyungi.net/node_modules/shimmer/test/unwrap.tap.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
'use strict'
|
||||
|
||||
var tap = require('tap')
|
||||
var test = tap.test
|
||||
var sinon = require('sinon')
|
||||
var shimmer = require('../index.js')
|
||||
|
||||
var outsider = 0
|
||||
function counter () { return ++outsider }
|
||||
|
||||
var generator = {
|
||||
inc: counter
|
||||
}
|
||||
|
||||
test('should unwrap safely', function (t) {
|
||||
t.plan(9)
|
||||
|
||||
t.equal(counter, generator.inc, 'basic function equality testing should work')
|
||||
t.doesNotThrow(function () { generator.inc() })
|
||||
t.equal(1, outsider, 'calls have side effects')
|
||||
|
||||
function wrapper (original) {
|
||||
return function () {
|
||||
return original.apply(this, arguments)
|
||||
}
|
||||
}
|
||||
shimmer.wrap(generator, 'inc', wrapper)
|
||||
|
||||
t.doesNotEqual(counter, generator.inc, 'function should be wrapped')
|
||||
|
||||
t.doesNotThrow(function () { generator.inc() })
|
||||
t.equal(2, outsider, 'original function has still been called')
|
||||
|
||||
shimmer.unwrap(generator, 'inc')
|
||||
t.equal(counter, generator.inc, 'basic function equality testing should work')
|
||||
t.doesNotThrow(function () { generator.inc() })
|
||||
t.equal(3, outsider, 'original function has still been called')
|
||||
})
|
||||
|
||||
test("shouldn't throw on double unwrapping", function (t) {
|
||||
t.plan(6)
|
||||
|
||||
t.equal(counter, generator.inc, 'basic function equality testing should work')
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withArgs('no original to unwrap to -- ' +
|
||||
'has inc already been unwrapped?')
|
||||
.once()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
function wrapper (original) {
|
||||
return function () {
|
||||
return original.apply(this, arguments)
|
||||
}
|
||||
}
|
||||
shimmer.wrap(generator, 'inc', wrapper)
|
||||
|
||||
t.doesNotEqual(counter, generator.inc, 'function should be wrapped')
|
||||
|
||||
shimmer.unwrap(generator, 'inc')
|
||||
t.equal(counter, generator.inc, 'basic function equality testing should work')
|
||||
|
||||
t.doesNotThrow(function () { shimmer.unwrap(generator, 'inc') },
|
||||
'should double unwrap without issue')
|
||||
t.equal(counter, generator.inc, 'function is unchanged after unwrapping')
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('unwrap called with no arguments', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.twice()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () { shimmer.unwrap() }, 'should log instead of throwing')
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('unwrap called with module but no name', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.twice()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () { shimmer.unwrap({}) }, 'should log instead of throwing')
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
148
api.hyungi.net/node_modules/shimmer/test/wrap.tap.js
generated
vendored
Normal file
148
api.hyungi.net/node_modules/shimmer/test/wrap.tap.js
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
'use strict'
|
||||
|
||||
var tap = require('tap')
|
||||
var test = tap.test
|
||||
var sinon = require('sinon')
|
||||
var shimmer = require('../index.js')
|
||||
|
||||
var outsider = 0
|
||||
function counter () { return ++outsider }
|
||||
function anticounter () { return --outsider }
|
||||
|
||||
var generator = {
|
||||
inc: counter
|
||||
}
|
||||
Object.defineProperty(generator, 'dec', {
|
||||
value: anticounter,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: false
|
||||
})
|
||||
|
||||
test('should wrap safely', function (t) {
|
||||
t.plan(12)
|
||||
|
||||
t.equal(counter, generator.inc, 'method is mapped to function')
|
||||
t.doesNotThrow(function () { generator.inc() }, 'original function works')
|
||||
t.equal(1, outsider, 'calls have side effects')
|
||||
|
||||
var count = 0
|
||||
function wrapper (original, name) {
|
||||
t.equal(name, 'inc')
|
||||
return function () {
|
||||
count++
|
||||
var returned = original.apply(this, arguments)
|
||||
count++
|
||||
return returned
|
||||
}
|
||||
}
|
||||
shimmer.wrap(generator, 'inc', wrapper)
|
||||
|
||||
t.ok(generator.inc.__wrapped, "function tells us it's wrapped")
|
||||
t.equal(generator.inc.__original, counter, 'original function is available')
|
||||
t.doesNotThrow(function () { generator.inc() }, 'wrapping works')
|
||||
t.equal(2, count, 'both pre and post increments should have happened')
|
||||
t.equal(2, outsider, 'original function has still been called')
|
||||
t.ok(generator.propertyIsEnumerable('inc'),
|
||||
'wrapped enumerable property is still enumerable')
|
||||
t.equal(Object.keys(generator.inc).length, 0,
|
||||
'wrapped object has no additional properties')
|
||||
|
||||
shimmer.wrap(generator, 'dec', function (original) {
|
||||
return function () {
|
||||
return original.apply(this, arguments)
|
||||
}
|
||||
})
|
||||
|
||||
t.ok(!generator.propertyIsEnumerable('dec'),
|
||||
'wrapped unenumerable property is still unenumerable')
|
||||
})
|
||||
|
||||
test('wrap called with no arguments', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withExactArgs('no original function undefined to wrap')
|
||||
.once()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.wrap()
|
||||
}, "wrapping with no arguments doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('wrap called with module but nothing else', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withExactArgs('no original function undefined to wrap')
|
||||
.once()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.wrap(generator)
|
||||
}, "wrapping with only 1 argument doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('wrap called with original but no wrapper', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.twice()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.wrap(generator, 'inc')
|
||||
}, "wrapping with only original method doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('wrap called with non-function original', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withExactArgs('original object and wrapper must be functions')
|
||||
.once()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.wrap({ orange: 'slices' }, 'orange', function () {})
|
||||
}, "wrapping non-function original doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
|
||||
test('wrap called with non-function wrapper', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var mock = sinon.expectation
|
||||
.create('logger')
|
||||
.withArgs('original object and wrapper must be functions')
|
||||
.once()
|
||||
shimmer({ logger: mock })
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
shimmer.wrap({ orange: function () {} }, 'orange', 'hamchunx')
|
||||
}, "wrapping with non-function wrapper doesn't throw")
|
||||
|
||||
t.doesNotThrow(function () {
|
||||
mock.verify()
|
||||
}, 'logger was called with the expected message')
|
||||
})
|
||||
Reference in New Issue
Block a user