How to use fn3 method in storybook-root

Best JavaScript code snippet using storybook-root

tests.js

Source:tests.js Github

copy

Full Screen

1(function () {2 /*global mocha,chai,EventEmitter*/3 'use strict';4 // Setup Mocha and Chai.5 mocha.setup('tdd');6 var assert = chai.assert;7 function flattenCheck(check) {8 var sorted = check.slice(0);9 sorted.sort(function (a, b) {10 return a < b ? -1 : 1;11 });12 return sorted.join();13 }14 // Configure the tests15 suite('getListeners', function() {16 var ee;17 setup(function() {18 ee = new EventEmitter();19 });20 test('initialises the event object and a listener array', function() {21 ee.getListeners('foo');22 assert.deepEqual(ee._events, {23 foo: []24 });25 });26 test('does not overwrite listener arrays', function() {27 var listeners = ee.getListeners('foo');28 listeners.push('bar');29 assert.deepEqual(ee._events, {30 foo: ['bar']31 });32 ee.getListeners('foo');33 assert.deepEqual(ee._events, {34 foo: ['bar']35 });36 });37 test('allows you to fetch listeners by regex', function ()38 {39 var check = [];40 ee.addListener('foo', function() { check.push(1); });41 ee.addListener('bar', function() { check.push(2); return 'bar'; });42 ee.addListener('baz', function() { check.push(3); return 'baz'; });43 var listeners = ee.getListeners(/ba[rz]/);44 assert.strictEqual(listeners.bar.length + listeners.baz.length, 2);45 assert.strictEqual(listeners.bar[0].listener(), 'bar');46 assert.strictEqual(listeners.baz[0].listener(), 'baz');47 });48 });49 suite('flattenListeners', function () {50 var ee;51 var fn1 = function(){};52 var fn2 = function(){};53 var fn3 = function(){};54 setup(function () {55 ee = new EventEmitter();56 });57 test('takes an array of objects and returns an array of functions', function () {58 var input = [59 {listener: fn1},60 {listener: fn2},61 {listener: fn3}62 ];63 var output = ee.flattenListeners(input);64 assert.deepEqual(output, [fn1, fn2, fn3]);65 });66 test('if given an empty array, an empty array is returned', function () {67 var output = ee.flattenListeners([]);68 assert.deepEqual(output, []);69 });70 });71 suite('addListener', function() {72 var ee;73 var fn1 = function(){};74 var fn2 = function(){};75 setup(function() {76 ee = new EventEmitter();77 });78 test('adds a listener to the specified event', function() {79 ee.addListener('foo', fn1);80 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1]);81 });82 test('does not allow duplicate listeners', function() {83 ee.addListener('bar', fn1);84 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn1]);85 ee.addListener('bar', fn2);86 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn1, fn2]);87 ee.addListener('bar', fn1);88 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn1, fn2]);89 });90 test('allows you to add listeners by regex', function ()91 {92 var check = [];93 ee.defineEvents(['bar', 'baz']);94 ee.addListener('foo', function() { check.push(1); });95 ee.addListener(/ba[rz]/, function() { check.push(2); });96 ee.emitEvent(/ba[rz]/);97 assert.strictEqual(flattenCheck(check), '2,2');98 });99 });100 suite('addOnceListener', function () {101 var ee;102 var counter;103 var fn1 = function() { counter++; };104 setup(function () {105 ee = new EventEmitter();106 counter = 0;107 });108 test('once listeners can be added', function () {109 ee.addOnceListener('foo', fn1);110 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1]);111 });112 test('listeners are only executed once', function () {113 ee.addOnceListener('foo', fn1);114 ee.emitEvent('foo');115 ee.emitEvent('foo');116 ee.emitEvent('foo');117 assert.strictEqual(counter, 1);118 });119 test('listeners can be removed', function () {120 ee.addOnceListener('foo', fn1);121 ee.removeListener('foo', fn1);122 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);123 });124 test('can not cause infinite recursion', function () {125 ee.addOnceListener('foo', function() {126 counter += 1;127 this.emitEvent('foo');128 });129 ee.trigger('foo');130 assert.strictEqual(counter, 1);131 });132 });133 suite('removeListener', function() {134 var ee;135 var fn1 = function(){};136 var fn2 = function(){};137 var fn3 = function(){};138 var fn4 = function(){};139 var fn5 = function(){};140 var fnX = function(){};141 setup(function() {142 ee = new EventEmitter();143 });144 test('does nothing when the listener is not found', function() {145 var orig = ee.getListeners('foo').length;146 ee.removeListener('foo', fn1);147 assert.lengthOf(ee.getListeners('foo'), orig);148 });149 test('can handle removing events that have not been added', function() {150 assert.notProperty(ee, '_events');151 ee.removeEvent('foo');152 assert.property(ee, '_events');153 assert.isObject(ee._events);154 });155 test('actually removes events', function() {156 ee.removeEvent('foo');157 assert.notDeepProperty(ee, '_events.foo');158 });159 test('removes listeners', function() {160 var listeners = ee.getListeners('bar');161 ee.addListener('bar', fn1);162 ee.addListener('bar', fn2);163 ee.addListener('bar', fn3);164 ee.addListener('bar', fn3); // Make sure doubling up does nothing165 ee.addListener('bar', fn4);166 assert.deepEqual(ee.flattenListeners(listeners), [fn1, fn2, fn3, fn4]);167 ee.removeListener('bar', fn3);168 assert.deepEqual(ee.flattenListeners(listeners), [fn1, fn2, fn4]);169 ee.removeListener('bar', fnX);170 assert.deepEqual(ee.flattenListeners(listeners), [fn1, fn2, fn4]);171 ee.removeListener('bar', fn1);172 assert.deepEqual(ee.flattenListeners(listeners), [fn2, fn4]);173 ee.removeListener('bar', fn4);174 assert.deepEqual(ee.flattenListeners(listeners), [fn2]);175 ee.removeListener('bar', fn2);176 assert.deepEqual(ee.flattenListeners(ee._events.bar), []);177 });178 test('removes with a regex', function() {179 ee.addListeners({180 foo: [fn1, fn2, fn3, fn4, fn5],181 bar: [fn1, fn2, fn3, fn4, fn5],182 baz: [fn1, fn2, fn3, fn4, fn5]183 });184 ee.removeListener(/ba[rz]/, fn3);185 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3, fn2, fn1]);186 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn5, fn4, fn2, fn1]);187 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), [fn5, fn4, fn2, fn1]);188 });189 });190 suite('getListenersAsObject', function () {191 var ee;192 setup(function() {193 ee = new EventEmitter();194 ee.addListener('bar', function(){});195 ee.addListener('baz', function(){});196 });197 test('returns an object for strings', function () {198 var listeners = ee.getListenersAsObject('bar');199 assert.isObject(listeners);200 assert.lengthOf(listeners.bar, 1);201 });202 test('returns an object for regexs', function () {203 var listeners = ee.getListenersAsObject(/ba[rz]/);204 assert.isObject(listeners);205 assert.lengthOf(listeners.bar, 1);206 assert.lengthOf(listeners.baz, 1);207 });208 });209 suite('defineEvent', function () {210 var ee;211 setup(function() {212 ee = new EventEmitter();213 });214 test('defines an event when there is nothing else inside', function () {215 ee.defineEvent('foo');216 assert.isArray(ee._events.foo);217 });218 test('defines an event when there are other events already', function () {219 var f = function(){};220 ee.addListener('foo', f);221 ee.defineEvent('bar');222 assert.deepEqual(ee.flattenListeners(ee._events.foo), [f]);223 assert.isArray(ee._events.bar);224 });225 test('does not overwrite existing events', function () {226 var f = function(){};227 ee.addListener('foo', f);228 ee.defineEvent('foo');229 assert.deepEqual(ee.flattenListeners(ee._events.foo), [f]);230 });231 });232 suite('defineEvents', function () {233 var ee;234 setup(function() {235 ee = new EventEmitter();236 });237 test('defines multiple events', function () {238 ee.defineEvents(['foo', 'bar']);239 assert.isArray(ee._events.foo, []);240 assert.isArray(ee._events.bar, []);241 });242 });243 suite('removeEvent', function() {244 var ee;245 var fn1 = function(){};246 var fn2 = function(){};247 var fn3 = function(){};248 var fn4 = function(){};249 var fn5 = function(){};250 setup(function() {251 ee = new EventEmitter();252 ee.addListener('foo', fn1);253 ee.addListener('foo', fn2);254 ee.addListener('bar', fn3);255 ee.addListener('bar', fn4);256 ee.addListener('baz', fn5);257 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn2]);258 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn3, fn4]);259 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), [fn5]);260 });261 test('removes all listeners for the specified event', function() {262 ee.removeEvent('bar');263 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn2]);264 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);265 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), [fn5]);266 ee.removeEvent('baz');267 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn2]);268 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);269 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), []);270 });271 test('removes all events when no event is specified', function() {272 ee.removeEvent();273 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);274 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);275 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), []);276 });277 test('removes listeners when passed a regex', function ()278 {279 var check = [];280 ee.removeEvent();281 ee.addListener('foo', function() { check.push(1); return 'foo'; });282 ee.addListener('bar', function() { check.push(2); return 'bar'; });283 ee.addListener('baz', function() { check.push(3); return 'baz'; });284 ee.removeEvent(/ba[rz]/);285 var listeners = ee.getListeners('foo');286 assert.lengthOf(listeners, 1);287 assert.strictEqual(listeners[0].listener(), 'foo');288 });289 test('can be used through the alias, removeAllListeners', function() {290 ee.removeAllListeners('bar');291 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn2]);292 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);293 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), [fn5]);294 ee.removeAllListeners('baz');295 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn2]);296 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);297 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), []);298 });299 });300 suite('emitEvent', function() {301 var ee;302 setup(function() {303 ee = new EventEmitter();304 });305 test('executes attached listeners', function() {306 var run = false;307 ee.addListener('foo', function() {308 run = true;309 });310 ee.emitEvent('foo');311 assert.isTrue(run);312 });313 test('executes attached with a single argument', function() {314 var key = null;315 ee.addListener('bar', function(a) {316 key = a;317 });318 ee.emitEvent('bar', [50]);319 assert.strictEqual(key, 50);320 ee.emit('bar', 60);321 assert.strictEqual(key, 60);322 });323 test('executes attached with arguments', function() {324 var key = null;325 ee.addListener('bar2', function(a, b) {326 key = a + b;327 });328 ee.emitEvent('bar2', [40, 2]);329 assert.strictEqual(key, 42);330 });331 test('executes multiple listeners', function() {332 var check = [];333 ee.addListener('baz', function() { check.push(1); });334 ee.addListener('baz', function() { check.push(2); });335 ee.addListener('baz', function() { check.push(3); });336 ee.addListener('baz', function() { check.push(4); });337 ee.addListener('baz', function() { check.push(5); });338 ee.emitEvent('baz');339 assert.strictEqual(flattenCheck(check), '1,2,3,4,5');340 });341 test('executes multiple listeners after one has been removed', function() {342 var check = [];343 var toRemove = function() { check.push('R'); };344 ee.addListener('baz', function() { check.push(1); });345 ee.addListener('baz', function() { check.push(2); });346 ee.addListener('baz', toRemove);347 ee.addListener('baz', function() { check.push(3); });348 ee.addListener('baz', function() { check.push(4); });349 ee.removeListener('baz', toRemove);350 ee.emitEvent('baz');351 assert.strictEqual(flattenCheck(check), '1,2,3,4');352 });353 test('executes multiple listeners and removes those that return true', function() {354 var check = [];355 ee.addListener('baz', function() { check.push(1); });356 ee.addListener('baz', function() { check.push(2); return true; });357 ee.addListener('baz', function() { check.push(3); return false; });358 ee.addListener('baz', function() { check.push(4); return 1; });359 ee.addListener('baz', function() { check.push(5); return true; });360 ee.emitEvent('baz');361 ee.emitEvent('baz');362 assert.strictEqual(flattenCheck(check), '1,1,2,3,3,4,4,5');363 });364 test('can remove listeners that return true and also define another listener within them', function () {365 var check = [];366 ee.addListener('baz', function() { check.push(1); });367 ee.addListener('baz', function() {368 ee.addListener('baz', function() {369 check.push(2);370 });371 check.push(3);372 return true;373 });374 ee.addListener('baz', function() { check.push(4); return false; });375 ee.addListener('baz', function() { check.push(5); return 1; });376 ee.addListener('baz', function() { check.push(6); return true; });377 ee.emitEvent('baz');378 ee.emitEvent('baz');379 assert.strictEqual(flattenCheck(check), '1,1,2,3,4,4,5,5,6');380 });381 test('executes all listeners that match a regular expression', function ()382 {383 var check = [];384 ee.addListener('foo', function() { check.push(1); });385 ee.addListener('bar', function() { check.push(2); });386 ee.addListener('baz', function() { check.push(3); });387 ee.emitEvent(/ba[rz]/);388 assert.strictEqual(flattenCheck(check), '2,3');389 });390 test('global object is defined', function()391 {392 ee.addListener('foo', function() {393 assert.equal(this, ee);394 });395 ee.emitEvent('foo');396 });397 });398 suite('manipulateListeners', function() {399 var ee;400 var fn1 = function(){};401 var fn2 = function(){};402 var fn3 = function(){};403 var fn4 = function(){};404 var fn5 = function(){};405 setup(function() {406 ee = new EventEmitter();407 });408 test('manipulates multiple with an array', function() {409 ee.manipulateListeners(false, 'foo', [fn1, fn2, fn3, fn4, fn5]);410 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3, fn2, fn1]);411 ee.manipulateListeners(true, 'foo', [fn1, fn2]);412 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3]);413 ee.manipulateListeners(true, 'foo', [fn3, fn5]);414 ee.manipulateListeners(false, 'foo', [fn4, fn1]);415 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn4, fn1]);416 ee.manipulateListeners(true, 'foo', [fn4, fn1]);417 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);418 });419 test('manipulates with an object', function() {420 ee.manipulateListeners(false, {421 foo: [fn1, fn2, fn3],422 bar: fn4423 });424 ee.manipulateListeners(false, {425 bar: [fn5, fn1]426 });427 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn3, fn2, fn1]);428 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn4, fn1, fn5]);429 ee.manipulateListeners(true, {430 foo: fn1,431 bar: [fn5, fn4]432 });433 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn3, fn2]);434 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn1]);435 ee.manipulateListeners(true, {436 foo: [fn3, fn2],437 bar: fn1438 });439 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);440 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);441 });442 test('does not execute listeners just after they are added in another listeners', function() {443 var check = [];444 ee.addListener('baz', function() { check.push(1); });445 ee.addListener('baz', function() { check.push(2); });446 ee.addListener('baz', function() {447 check.push(3);448 ee.addListener('baz', function() {449 check.push(4);450 });451 });452 ee.addListener('baz', function() { check.push(5); });453 ee.addListener('baz', function() { check.push(6); });454 ee.emitEvent('baz');455 assert.strictEqual(flattenCheck(check), '1,2,3,5,6');456 });457 });458 suite('addListeners', function() {459 var ee;460 var fn1 = function(){};461 var fn2 = function(){};462 var fn3 = function(){};463 var fn4 = function(){};464 var fn5 = function(){};465 setup(function() {466 ee = new EventEmitter();467 });468 test('adds with an array', function() {469 ee.addListeners('foo', [fn1, fn2, fn3]);470 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn3, fn2, fn1]);471 ee.addListeners('foo', [fn4, fn5]);472 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn3, fn2, fn1, fn5, fn4]);473 });474 test('adds with an object', function() {475 ee.addListeners({476 foo: fn1,477 bar: [fn2, fn3]478 });479 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1]);480 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn3, fn2]);481 ee.addListeners({482 foo: [fn4],483 bar: fn5484 });485 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn4]);486 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn3, fn2, fn5]);487 });488 test('allows you to add listeners by regex', function ()489 {490 var check = [];491 ee.defineEvents(['bar', 'baz']);492 ee.addListeners('foo', [function() { check.push(1); }]);493 ee.addListeners(/ba[rz]/, [function() { check.push(2); }, function() { check.push(3); }]);494 ee.emitEvent(/ba[rz]/);495 assert.strictEqual(flattenCheck(check), '2,2,3,3');496 });497 });498 suite('removeListeners', function() {499 var ee;500 var fn1 = function(){};501 var fn2 = function(){};502 var fn3 = function(){};503 var fn4 = function(){};504 var fn5 = function(){};505 setup(function() {506 ee = new EventEmitter();507 });508 test('removes with an array', function() {509 ee.addListeners('foo', [fn1, fn2, fn3, fn4, fn5]);510 ee.removeListeners('foo', [fn2, fn3]);511 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn1]);512 ee.removeListeners('foo', [fn5, fn4]);513 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1]);514 ee.removeListeners('foo', [fn1]);515 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);516 });517 test('removes with an object', function() {518 ee.addListeners({519 foo: [fn1, fn2, fn3, fn4, fn5],520 bar: [fn1, fn2, fn3, fn4, fn5]521 });522 ee.removeListeners({523 foo: fn2,524 bar: [fn3, fn4, fn5]525 });526 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3, fn1]);527 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn2, fn1]);528 ee.removeListeners({529 foo: [fn3],530 bar: [fn2, fn1]531 });532 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn1]);533 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);534 });535 test('removes with a regex', function() {536 ee.addListeners({537 foo: [fn1, fn2, fn3, fn4, fn5],538 bar: [fn1, fn2, fn3, fn4, fn5],539 baz: [fn1, fn2, fn3, fn4, fn5]540 });541 ee.removeListeners(/ba[rz]/, [fn3, fn4]);542 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3, fn2, fn1]);543 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn5, fn2, fn1]);544 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), [fn5, fn2, fn1]);545 });546 });547 suite('setOnceReturnValue', function() {548 var ee;549 setup(function () {550 ee = new EventEmitter();551 });552 test('will remove if left as default and returning true', function () {553 var check = [];554 ee.addListener('baz', function() { check.push(1); });555 ee.addListener('baz', function() { check.push(2); return true; });556 ee.addListener('baz', function() { check.push(3); return false; });557 ee.addListener('baz', function() { check.push(4); return 1; });558 ee.addListener('baz', function() { check.push(5); return true; });559 ee.emitEvent('baz');560 ee.emitEvent('baz');561 assert.strictEqual(flattenCheck(check), '1,1,2,3,3,4,4,5');562 });563 test('will remove those that return a string when set to that string', function () {564 var check = [];565 ee.setOnceReturnValue('only-once');566 ee.addListener('baz', function() { check.push(1); });567 ee.addListener('baz', function() { check.push(2); return true; });568 ee.addListener('baz', function() { check.push(3); return 'only-once'; });569 ee.addListener('baz', function() { check.push(4); return 1; });570 ee.addListener('baz', function() { check.push(5); return 'only-once'; });571 ee.addListener('baz', function() { check.push(6); return true; });572 ee.emitEvent('baz');573 ee.emitEvent('baz');574 assert.strictEqual(flattenCheck(check), '1,1,2,2,3,4,4,5,6,6');575 });576 test('will not remove those that return a different string to the one that is set', function () {577 var check = [];578 ee.setOnceReturnValue('only-once');579 ee.addListener('baz', function() { check.push(1); });580 ee.addListener('baz', function() { check.push(2); return true; });581 ee.addListener('baz', function() { check.push(3); return 'not-only-once'; });582 ee.addListener('baz', function() { check.push(4); return 1; });583 ee.addListener('baz', function() { check.push(5); return 'only-once'; });584 ee.addListener('baz', function() { check.push(6); return true; });585 ee.emitEvent('baz');586 ee.emitEvent('baz');587 assert.strictEqual(flattenCheck(check), '1,1,2,2,3,3,4,4,5,6,6');588 });589 });590 suite('alias', function () {591 test('that it works when overwriting target method', function () {592 var addListener = EventEmitter.prototype.addListener;593 var res;594 var rand = Math.random();595 EventEmitter.prototype.addListener = function () {596 res = rand;597 };598 var ee = new EventEmitter();599 ee.on();600 assert.strictEqual(res, rand);601 EventEmitter.prototype.addListener = addListener;602 });603 });604 // Execute the tests.605 mocha.run();...

Full Screen

Full Screen

hookRunner.test.js

Source:hookRunner.test.js Github

copy

Full Screen

1'use strict'2const t = require('tap')3const test = t.test4const { hookRunner, onSendHookRunner } = require('../../lib/hooks')5test('hookRunner - Basic', t => {6 t.plan(9)7 hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)8 function iterator (fn, a, b, done) {9 return fn(a, b, done)10 }11 function fn1 (a, b, done) {12 t.equal(a, 'a')13 t.equal(b, 'b')14 done()15 }16 function fn2 (a, b, done) {17 t.equal(a, 'a')18 t.equal(b, 'b')19 done()20 }21 function fn3 (a, b, done) {22 t.equal(a, 'a')23 t.equal(b, 'b')24 done()25 }26 function done (err, a, b) {27 t.error(err)28 t.equal(a, 'a')29 t.equal(b, 'b')30 }31})32test('hookRunner - In case of error should skip to done', t => {33 t.plan(7)34 hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)35 function iterator (fn, a, b, done) {36 return fn(a, b, done)37 }38 function fn1 (a, b, done) {39 t.equal(a, 'a')40 t.equal(b, 'b')41 done()42 }43 function fn2 (a, b, done) {44 t.equal(a, 'a')45 t.equal(b, 'b')46 done(new Error('kaboom'))47 }48 function fn3 () {49 t.fail('We should not be here')50 }51 function done (err, a, b) {52 t.equal(err.message, 'kaboom')53 t.equal(a, 'a')54 t.equal(b, 'b')55 }56})57test('hookRunner - Should handle throw', t => {58 t.plan(7)59 hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)60 function iterator (fn, a, b, done) {61 return fn(a, b, done)62 }63 function fn1 (a, b, done) {64 t.equal(a, 'a')65 t.equal(b, 'b')66 done()67 }68 function fn2 (a, b, done) {69 t.equal(a, 'a')70 t.equal(b, 'b')71 throw new Error('kaboom')72 }73 function fn3 () {74 t.fail('We should not be here')75 }76 function done (err, a, b) {77 t.equal(err.message, 'kaboom')78 t.equal(a, 'a')79 t.equal(b, 'b')80 }81})82test('hookRunner - Should handle promises', t => {83 t.plan(9)84 hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)85 function iterator (fn, a, b, done) {86 return fn(a, b, done)87 }88 function fn1 (a, b) {89 t.equal(a, 'a')90 t.equal(b, 'b')91 return Promise.resolve()92 }93 function fn2 (a, b) {94 t.equal(a, 'a')95 t.equal(b, 'b')96 return Promise.resolve()97 }98 function fn3 (a, b) {99 t.equal(a, 'a')100 t.equal(b, 'b')101 return Promise.resolve()102 }103 function done (err, a, b) {104 t.error(err)105 t.equal(a, 'a')106 t.equal(b, 'b')107 }108})109test('hookRunner - In case of error should skip to done (with promises)', t => {110 t.plan(7)111 hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)112 function iterator (fn, a, b, done) {113 return fn(a, b, done)114 }115 function fn1 (a, b) {116 t.equal(a, 'a')117 t.equal(b, 'b')118 return Promise.resolve()119 }120 function fn2 (a, b) {121 t.equal(a, 'a')122 t.equal(b, 'b')123 return Promise.reject(new Error('kaboom'))124 }125 function fn3 () {126 t.fail('We should not be here')127 }128 function done (err, a, b) {129 t.equal(err.message, 'kaboom')130 t.equal(a, 'a')131 t.equal(b, 'b')132 }133})134test('hookRunner - Be able to exit before its natural end', t => {135 t.plan(4)136 let shouldStop = false137 hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)138 function iterator (fn, a, b, done) {139 if (shouldStop) {140 return undefined141 }142 return fn(a, b, done)143 }144 function fn1 (a, b, done) {145 t.equal(a, 'a')146 t.equal(b, 'b')147 done()148 }149 function fn2 (a, b) {150 t.equal(a, 'a')151 t.equal(b, 'b')152 shouldStop = true153 return Promise.resolve()154 }155 function fn3 () {156 t.fail('this should not be called')157 }158 function done () {159 t.fail('this should not be called')160 }161})162test('hookRunner - Promises that resolve to a value do not change the state', t => {163 t.plan(5)164 const originalState = { a: 'a', b: 'b' }165 hookRunner([fn1, fn2, fn3], iterator, originalState, 'b', done)166 function iterator (fn, state, b, done) {167 return fn(state, b, done)168 }169 function fn1 (state, b, done) {170 t.equal(state, originalState)171 return Promise.resolve(null)172 }173 function fn2 (state, b, done) {174 t.equal(state, originalState)175 return Promise.resolve('string')176 }177 function fn3 (state, b, done) {178 t.equal(state, originalState)179 return Promise.resolve({ object: true })180 }181 function done (err, state, b) {182 t.error(err)183 t.equal(state, originalState)184 }185})186test('onSendHookRunner - Basic', t => {187 t.plan(13)188 const originalRequest = { body: null }189 const originalReply = { request: originalRequest }190 const originalPayload = 'payload'191 onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, originalPayload, done)192 function fn1 (request, reply, payload, done) {193 t.same(request, originalRequest)194 t.same(reply, originalReply)195 t.equal(payload, originalPayload)196 done()197 }198 function fn2 (request, reply, payload, done) {199 t.same(request, originalRequest)200 t.same(reply, originalReply)201 t.equal(payload, originalPayload)202 done()203 }204 function fn3 (request, reply, payload, done) {205 t.same(request, originalRequest)206 t.same(reply, originalReply)207 t.equal(payload, originalPayload)208 done()209 }210 function done (err, request, reply, payload) {211 t.error(err)212 t.same(request, originalRequest)213 t.same(reply, originalReply)214 t.equal(payload, originalPayload)215 }216})217test('onSendHookRunner - Can change the payload', t => {218 t.plan(7)219 const originalRequest = { body: null }220 const originalReply = { request: originalRequest }221 const v1 = { hello: 'world' }222 const v2 = { ciao: 'mondo' }223 const v3 = { winter: 'is coming' }224 const v4 = { winter: 'has come' }225 onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)226 function fn1 (request, reply, payload, done) {227 t.same(payload, v1)228 done(null, v2)229 }230 function fn2 (request, reply, payload, done) {231 t.same(payload, v2)232 done(null, v3)233 }234 function fn3 (request, reply, payload, done) {235 t.same(payload, v3)236 done(null, v4)237 }238 function done (err, request, reply, payload) {239 t.error(err)240 t.same(request, originalRequest)241 t.same(reply, originalReply)242 t.same(payload, v4)243 }244})245test('onSendHookRunner - In case of error should skip to done', t => {246 t.plan(6)247 const originalRequest = { body: null }248 const originalReply = { request: originalRequest }249 const v1 = { hello: 'world' }250 const v2 = { ciao: 'mondo' }251 onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)252 function fn1 (request, reply, payload, done) {253 t.same(payload, v1)254 done(null, v2)255 }256 function fn2 (request, reply, payload, done) {257 t.same(payload, v2)258 done(new Error('kaboom'))259 }260 function fn3 () {261 t.fail('We should not be here')262 }263 function done (err, request, reply, payload) {264 t.equal(err.message, 'kaboom')265 t.same(request, originalRequest)266 t.same(reply, originalReply)267 t.same(payload, v2)268 }269})270test('onSendHookRunner - Should handle promises', t => {271 t.plan(7)272 const originalRequest = { body: null }273 const originalReply = { request: originalRequest }274 const v1 = { hello: 'world' }275 const v2 = { ciao: 'mondo' }276 const v3 = { winter: 'is coming' }277 const v4 = { winter: 'has come' }278 onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)279 function fn1 (request, reply, payload) {280 t.same(payload, v1)281 return Promise.resolve(v2)282 }283 function fn2 (request, reply, payload) {284 t.same(payload, v2)285 return Promise.resolve(v3)286 }287 function fn3 (request, reply, payload) {288 t.same(payload, v3)289 return Promise.resolve(v4)290 }291 function done (err, request, reply, payload) {292 t.error(err)293 t.same(request, originalRequest)294 t.same(reply, originalReply)295 t.same(payload, v4)296 }297})298test('onSendHookRunner - In case of error should skip to done (with promises)', t => {299 t.plan(6)300 const originalRequest = { body: null }301 const originalReply = { request: originalRequest }302 const v1 = { hello: 'world' }303 const v2 = { ciao: 'mondo' }304 onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)305 function fn1 (request, reply, payload) {306 t.same(payload, v1)307 return Promise.resolve(v2)308 }309 function fn2 (request, reply, payload) {310 t.same(payload, v2)311 return Promise.reject(new Error('kaboom'))312 }313 function fn3 () {314 t.fail('We should not be here')315 }316 function done (err, request, reply, payload) {317 t.equal(err.message, 'kaboom')318 t.same(request, originalRequest)319 t.same(reply, originalReply)320 t.same(payload, v2)321 }322})323test('onSendHookRunner - Be able to exit before its natural end', t => {324 t.plan(2)325 const originalRequest = { body: null }326 const originalReply = { request: originalRequest }327 const v1 = { hello: 'world' }328 const v2 = { ciao: 'mondo' }329 onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)330 function fn1 (request, reply, payload, done) {331 t.same(payload, v1)332 done(null, v2)333 }334 function fn2 (request, reply, payload) {335 t.same(payload, v2)336 }337 function fn3 () {338 t.fail('this should not be called')339 }340 function done () {341 t.fail('this should not be called')342 }...

Full Screen

Full Screen

test-retry-wrap.js

Source:test-retry-wrap.js Github

copy

Full Screen

1var common = require('../common');2var assert = common.assert;3var fake = common.fake.create();4var retry = require(common.dir.lib + '/retry');5function getLib() {6 return {7 fn1: function() {},8 fn2: function() {},9 fn3: function() {}10 };11}12(function wrapAll() {13 var lib = getLib();14 retry.wrap(lib);15 assert.equal(lib.fn1.name, 'bound retryWrapper');16 assert.equal(lib.fn2.name, 'bound retryWrapper');17 assert.equal(lib.fn3.name, 'bound retryWrapper');18}());19(function wrapAllPassOptions() {20 var lib = getLib();21 retry.wrap(lib, {retries: 2});22 assert.equal(lib.fn1.name, 'bound retryWrapper');23 assert.equal(lib.fn2.name, 'bound retryWrapper');24 assert.equal(lib.fn3.name, 'bound retryWrapper');25 assert.equal(lib.fn1.options.retries, 2);26 assert.equal(lib.fn2.options.retries, 2);27 assert.equal(lib.fn3.options.retries, 2);28}());29(function wrapDefined() {30 var lib = getLib();31 retry.wrap(lib, ['fn2', 'fn3']);32 assert.notEqual(lib.fn1.name, 'bound retryWrapper');33 assert.equal(lib.fn2.name, 'bound retryWrapper');34 assert.equal(lib.fn3.name, 'bound retryWrapper');35}());36(function wrapDefinedAndPassOptions() {37 var lib = getLib();38 retry.wrap(lib, {retries: 2}, ['fn2', 'fn3']);39 assert.notEqual(lib.fn1.name, 'bound retryWrapper');40 assert.equal(lib.fn2.name, 'bound retryWrapper');41 assert.equal(lib.fn3.name, 'bound retryWrapper');42 assert.equal(lib.fn2.options.retries, 2);43 assert.equal(lib.fn3.options.retries, 2);44}());45(function runWrappedWithoutError() {46 var callbackCalled;47 var lib = {method: function(a, b, callback) {48 assert.equal(a, 1);49 assert.equal(b, 2);50 assert.equal(typeof callback, 'function');51 callback();52 }};53 retry.wrap(lib);54 lib.method(1, 2, function() {55 callbackCalled = true;56 });57 assert.ok(callbackCalled);58}());59(function runWrappedSeveralWithoutError() {60 var callbacksCalled = 0;61 var lib = {62 fn1: function (a, callback) {63 assert.equal(a, 1);64 assert.equal(typeof callback, 'function');65 callback();66 },67 fn2: function (a, callback) {68 assert.equal(a, 2);69 assert.equal(typeof callback, 'function');70 callback();71 }72 };73 retry.wrap(lib, {}, ['fn1', 'fn2']);74 lib.fn1(1, function() {75 callbacksCalled++;76 });77 lib.fn2(2, function() {78 callbacksCalled++;79 });80 assert.equal(callbacksCalled, 2);81}());82(function runWrappedWithError() {83 var callbackCalled;84 var lib = {method: function(callback) {85 callback(new Error('Some error'));86 }};87 retry.wrap(lib, {retries: 1});88 lib.method(function(err) {89 callbackCalled = true;90 assert.ok(err instanceof Error);91 });92 assert.ok(!callbackCalled);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fn3 } from 'storybook-root';2import { fn4 } from 'storybook-root';3import { fn5 } from 'storybook-root';4import { fn6 } from 'storybook-root';5import { fn7 } from 'storybook-root';6import { fn8 } from 'storybook-root';7import { fn9 } from 'storybook-root';8import { fn10 } from 'storybook-root';9import { fn11 } from 'storybook-root';10import { fn12 } from 'storybook-root';11import { fn13 } from 'storybook-root';12import { fn14 } from 'storybook-root';13import { fn15 } from 'storybook-root';14import { fn16 } from 'storybook-root';15import { fn17 } from 'storybook-root';16import { fn18 } from 'storybook-root';17import { fn19 } from 'storybook-root';18import { fn20 } from 'storybook-root';19import { fn21 } from 'storybook-root';20import { fn22 } from 'storybook-root';21import { fn23 } from 'storybook-root';22import { fn24 } from 'storybook-root';23import { fn25 } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1export default {2};3import storybook-root2 from './storybook-root2';4export default {5 subcomponents: {6 }7};

Full Screen

Using AI Code Generation

copy

Full Screen

1const root = require('storybook-root');2root.fn3();3const root = require('storybook-root');4root.fn4();5const root = require('storybook-root');6root.fn5();7const root = require('storybook-root');8root.fn6();9const root = require('storybook-root');10root.fn7();11const root = require('storybook-root');12root.fn8();13const root = require('storybook-root');14root.fn9();15const root = require('storybook-root');16root.fn10();17const root = require('storybook-root');18root.fn11();19const root = require('storybook-root');20root.fn12();21const root = require('storybook-root');22root.fn13();23const root = require('storybook-root');24root.fn14();25const root = require('storybook-root');26root.fn15();27const root = require('storybook-root');28root.fn16();29const root = require('storybook-root');30root.fn17();31const root = require('storybook-root');32root.fn18();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fn3 } from "storybook-root";2fn3();3import { fn1 } from "storybook-root";4fn1();5import { fn2 } from "storybook-root";6fn2();7import { fn3 } from "storybook-root";8fn3();9import { fn4 } from "storybook-root";10fn4();11import { fn5 } from "storybook-root";12fn5();13import { fn6 } from "storybook-root";14fn6();15import { fn7 } from "storybook-root";16fn7();17import { fn8 } from "storybook-root";18fn8();19import { fn9 } from "storybook-root";20fn9();21import { fn10 } from "storybook-root";22fn10();23import { fn11 } from "storybook-root";24fn11();25import { fn12 } from "storybook-root";26fn12();27import { fn13 } from "storybook-root";28fn13();29import { fn14 } from "storybook-root";30fn14();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fn3 } from 'storybook-root'2fn3()3const path = require('path')4module.exports = {5 webpackFinal: async (config, { configType }) => {6 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../src')7 },8}

Full Screen

Using AI Code Generation

copy

Full Screen

1import {fn3} from 'storybook-root';2fn3();3import {fn2} from 'storybook-root';4export const fn3 = () => {5 fn2();6};7export const fn2 = () => {8 console.log('fn2');9};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fn3 } from 'storybook-root';2import { fn3 } from './fn3';3export { fn3 };4export const fn3 = () => {5 console.log('fn3');6};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fn3 } from 'storybook-root';2fn3();3export { fn3 } from './src/stories/MyComponent.stories.js';4export const fn3 = () => {5 console.log('fn3');6};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful