react / wstein / node_modules / browserify / node_modules / glob / node_modules / inflight / test.js
80538 viewsvar test = require('tap').test1var inf = require('./inflight.js')234function req (key, cb) {5cb = inf(key, cb)6if (cb) setTimeout(function () {7cb(key)8cb(key)9})10return cb11}1213test('basic', function (t) {14var calleda = false15var a = req('key', function (k) {16t.notOk(calleda)17calleda = true18t.equal(k, 'key')19if (calledb) t.end()20})21t.ok(a, 'first returned cb function')2223var calledb = false24var b = req('key', function (k) {25t.notOk(calledb)26calledb = true27t.equal(k, 'key')28if (calleda) t.end()29})3031t.notOk(b, 'second should get falsey inflight response')32})3334test('timing', function (t) {35var expect = [36'method one',37'start one',38'end one',39'two',40'tick',41'three'42]43var i = 04445function log (m) {46t.equal(m, expect[i], m + ' === ' + expect[i])47++i48if (i === expect.length)49t.end()50}5152function method (name, cb) {53log('method ' + name)54process.nextTick(cb)55}5657var one = inf('foo', function () {58log('start one')59var three = inf('foo', function () {60log('three')61})62if (three) method('three', three)63log('end one')64})6566method('one', one)6768var two = inf('foo', function () {69log('two')70})71if (two) method('one', two)7273process.nextTick(log.bind(null, 'tick'))74})7576test('parameters', function (t) {77t.plan(8)7879var a = inf('key', function (first, second, third) {80t.equal(first, 1)81t.equal(second, 2)82t.equal(third, 3)83})84t.ok(a, 'first returned cb function')8586var b = inf('key', function (first, second, third) {87t.equal(first, 1)88t.equal(second, 2)89t.equal(third, 3)90})91t.notOk(b, 'second should get falsey inflight response')9293setTimeout(function () {94a(1, 2, 3)95})96})979899