<commit_before>/**
 * .reel Unit Tests
 */
(function($){

  module('Annotations', reel_test_module_routine);

  test( 'One annotation DOM container (node) is rendered per each `annotations` object key/value pair', function(){
    expect(2);
    var
      selector= '#image',
      $reel= $(selector).reel({
        annotations: {
          "my_annotation_name": {}
        }
      }),
      $instance= $reel.parent()

    equal( !!$reel.siblings('.reel-annotation[id]').length, 1, 'One annotation node with `id` attribute');
    ok( !!$('#my_annotation_name').length, 'Reachable by an `id` selector equal to annotation key');
  });

  asyncTest( '`node` holds a collection of HTML attributes used for the handler\'s `div` tag', function(){
    expect(7);
    var
      selector= '#image',
      $reel= $(selector).reel({
        annotations: {
          "my_annotation": {
            node: {
              text: 'Some text',
              'class': 'some_class_name',
              title: 'Some hint',
              // Any attribute would do as it would for jQuery's `.attr()`
              'any-attribute': 'any-value'
            },
          },
          "still_node": {}
        }
      }),
      $instance= $reel.parent()

    // Positioning of annotations happens at `frameChange`
    $reel.one('frameChange.test', function(){
      ok( !!$('div#my_annotation').length, 'Node present');
      //ok( $('#my_annotation').is(':visible'), 'Node visible');
      ok( $('#my_annotation').is(':contains(Some text)'), 'Node text content');
      equal( $('#my_annotation').text(), 'Some text', 'Node text content');
      ok( !!$('#my_annotation.some_class_name').length, 'Class name applied');
      equal( $('#my_annotation[title]').attr('title'), 'Some hint', '`title` attribute applied');
      equal( $('#my_annotation[any-attribute]').attr('any-attribute'), 'any-value', 'Any attribute would do');

      ok( !!$('div#still_node').length, 'Node is always present, even when not defined');
      start();
    });
  });

  asyncTest( '`image` holds a collection of HTML attributes used for an `img` tag inside the node', function(){
    expect(5);
    var
      selector= '#image',
      $reel= $(selector).reel({
        annotations: {
          "my_annotation": {
            image: {
              src: 'samples/badge-1.gif',
              width: 120,
              height: 30
            }
          }
        }
      }),
      $instance= $reel.parent()

    // Positioning of annotations happens at `frameChange`
    $reel.one('frameChange.test', function(){
      ok( !!$('div#my_annotation').length, 'Node node present');
      ok( !!$('div#my_annotation img').length, 'Wrapping an image node');
      equal( $('#my_annotation img').attr('src'), 'samples/badge-1.gif', 'Image `src`');
      equiv( $('#my_annotation img').attr('width') || $('#my_annotation img').css('width'), 120, 'CSS width');
      equiv( $('#my_annotation img').attr('height') || $('#my_annotation img').css('height'), 30, 'CSS height');
      start();
    });
  });

  asyncTest( '`link` holds a collection of HTML attributes used for an `a` tag inside the node', function(){
    expect(8);
    var
      selector= '#image',
      $reel= $(selector).reel({
        annotations: {
          "text_link": {
            link: {
              href: 'http://some/location',
              text: 'Click to navigate away'
            }
          },
          "image_link": {
            image: {
              src: 'some/my/image.jpg'
            },
            link: {
              href: 'http://some/location'
            }
          }
        }
      })

    // Positioning of annotations happens at `frameChange`
    $reel.one('frameChange.test', function(){
      ok( !!$('div#text_link').length, 'Node node present');
      ok( !!$('div#text_link a').length, 'Wrapping a link node');
      equal( $('#text_link a').attr('href'), 'http://some/location', 'Link `href`');
      equal( $('#text_link a').text(), 'Click to navigate away', '`title`');

      ok( !!$('div#image_link').length, 'Node node present');
      ok( !!$('div#image_link > a > img').length, 'Wrapping a link node wrapping an image node');
      equal( $('#image_link a').attr('href'), 'http://some/location', 'Link `href`');
      equal( $('#image_link img').attr('src'), 'some/my/image.jpg', 'Image `src`');

      start();
    });
  });

  asyncTest( 'Frame-based visibility annotation control properties `start` and `end`', function(){
    expect(36);
    var
      selector= '#image',
      frames= 36, // Default value
      should_be= '----+++++++++-----------------------'.split(''),
      $reel= $(selector).reel({
        annotations: {
          "my_annotation": {
            node: {
              text: "aaa"
            },
            x: 1, y: 1,
            start: 5,
            end: 13
          }
        },
        // And this will autoscroll thorugh all frames once
        entry: 1,
        opening: 1
      }),
      checked= [],
      $annotation= $('#my_annotation')

    // Positioning of annotations happens at `frameChange`
    // and we test it bubbled up to instance's parent
    $reel.parent().bind('frameChange.test', function(){
      var
        frame= $reel.data('frame'),
        should= should_be[frame - 1] == '+'

      equal( $annotation.is(':visible') , should, (should ? 'On' : 'Off')+' @ frame '+frame );

      checked.push(frame);
      if (checked.length == frames){
        $reel.parent().unbind('.test');
        start();
      }
    });
  });

  asyncTest( 'GH-69 The annotations wrapper DOM element is tagged with `frame-X` class name', function(){
    expect( 2 );
    var
      $reel= $('#image').reel({ annotations: {}, speed: 1 });

    setTimeout(function(){
      var
        frame= $reel.data('frame')
      ok( frame, 'Instance stopped at frame '+frame);
      ok( $('#image-reel').attr('class').match(/frame-[0-9]+/), 'The instance wrapper carries frame-'+frame+' class name');
      start();
    }, 123);
  });

  asyncTest( 'Horizontal position of annotation is defined by `x` property relative to left top corner', function(){
    expect( 1 );
    var
      x= '50%',
      $reel= $('#image').reel({ annotations: {
        'x-positioned-annotation': {
          x: x
        }
      }})

    $reel.bind('loaded.test', function(){
      equal( $('#x-positioned-annotation').css('left'), x, '50%');
      start();
    });
  });

  asyncTest( 'Vertical position of annotation is defined by `y` property', function(){
    expect( 2 );
    var
      y= 30,
      $reel= $('#image').reel({ annotations: {
        'y-positioned-annotation': {
          y: y
        }
      }})

    $reel.bind('loaded.test', function(){
      equal( $('#y-positioned-annotation').css('top'), y + 'px', '30px');
      equiv( $('#y-positioned-annotation').css('top'), y, 'It indeed is 30px');
      start();
    });
  });

  asyncTest( 'Both `x` and `y` properties can accept an Array of positions coordinates', function(){
    expect( 12 );
    var
      frames= 6,
      xs= [ 10, 20, 30, 20, 10, 0 ],
      ys= [ 20, 10, 0 , 40, 50, 30 ],
      y= 30,
      from= 1,
      $reel= $('#image').reel({ frames: frames, speed: 1, annotations: {
        'xy-positioned-annotation': {
          x: xs,
          y: ys
        }
      }})

    $reel.parent().bind('frameChange.test', function(){
      var
        frame= $reel.data('frame'),
        index= frame - from

      if (index < 0) return;

      equiv( $('#xy-positioned-annotation').css('left'), xs[index], 'x @ frame '+frame);
      equiv( $('#xy-positioned-annotation').css('top'), ys[index], 'y @ frame '+frame);
      if (index >= xs.length-1) start();
    });
  });

  asyncTest( 'Both `x` and `y` properties can accept an Array of positions coordinates when `start` and `end` are set', function(){
    expect( 8 );
    var
      frames= 6,
      xs= [ 10, 20, 30, 20 ],
      ys= [ 20, 10, 0 , 40 ],
      y= 30,
      from= 2,
      $reel= $('#image').reel({ frames: frames, frame: 2, speed: 1, annotations: {
        'xy-positioned-annotation': {
          start: from,
          end: 5,
          x: xs,
          y: ys
        }
      }})

    $reel.parent().bind('frameChange.test', function(){
      var
        frame= $reel.data('frame'),
        index= frame - from

      if (index < 0) return;

      equiv( $('#xy-positioned-annotation').css('left'), xs[index], 'x @ frame '+frame);
      equiv( $('#xy-positioned-annotation').css('top'), ys[index], 'y @ frame '+frame);
      if (index >= xs.length-1) start();
    });
  });

  asyncTest( 'GH-79 `click` event on annotation is not propagated up, where it would cause Reel to advance left/right', function(){
    expect( 1 );
    var
      $reel= $('#image').reel({ annotations: {
        'annotation': {
          x: 10,
          y: 10,
          link: {
            click: function(){
              ok( true, 'Annotation `click` handler fired.');
            }
          }
        }
      }})

    $('#annotation a')
    .parent()
    .bind('click.test', function(){
      ok( false, '`click` propagated to the annotation wrapper...');
    })
    .parent()
    .bind('click.test', function(){
      ok( false, '`click` Cpropagated to the instance wrapper...');
    })
    $('#annotation a').click();
    start();
  });

})(jQuery);
<commit_msg>Some browsers don't like to keep dimensions in same units they were set in. Particulary IE doesn't like `%`, so switching test to use `px` instead.<commit_after>/**
 * .reel Unit Tests
 */
(function($){

  module('Annotations', reel_test_module_routine);

  test( 'One annotation DOM container (node) is rendered per each `annotations` object key/value pair', function(){
    expect(2);
    var
      selector= '#image',
      $reel= $(selector).reel({
        annotations: {
          "my_annotation_name": {}
        }
      }),
      $instance= $reel.parent()

    equal( !!$reel.siblings('.reel-annotation[id]').length, 1, 'One annotation node with `id` attribute');
    ok( !!$('#my_annotation_name').length, 'Reachable by an `id` selector equal to annotation key');
  });

  asyncTest( '`node` holds a collection of HTML attributes used for the handler\'s `div` tag', function(){
    expect(7);
    var
      selector= '#image',
      $reel= $(selector).reel({
        annotations: {
          "my_annotation": {
            node: {
              text: 'Some text',
              'class': 'some_class_name',
              title: 'Some hint',
              // Any attribute would do as it would for jQuery's `.attr()`
              'any-attribute': 'any-value'
            },
          },
          "still_node": {}
        }
      }),
      $instance= $reel.parent()

    // Positioning of annotations happens at `frameChange`
    $reel.one('frameChange.test', function(){
      ok( !!$('div#my_annotation').length, 'Node present');
      //ok( $('#my_annotation').is(':visible'), 'Node visible');
      ok( $('#my_annotation').is(':contains(Some text)'), 'Node text content');
      equal( $('#my_annotation').text(), 'Some text', 'Node text content');
      ok( !!$('#my_annotation.some_class_name').length, 'Class name applied');
      equal( $('#my_annotation[title]').attr('title'), 'Some hint', '`title` attribute applied');
      equal( $('#my_annotation[any-attribute]').attr('any-attribute'), 'any-value', 'Any attribute would do');

      ok( !!$('div#still_node').length, 'Node is always present, even when not defined');
      start();
    });
  });

  asyncTest( '`image` holds a collection of HTML attributes used for an `img` tag inside the node', function(){
    expect(5);
    var
      selector= '#image',
      $reel= $(selector).reel({
        annotations: {
          "my_annotation": {
            image: {
              src: 'samples/badge-1.gif',
              width: 120,
              height: 30
            }
          }
        }
      }),
      $instance= $reel.parent()

    // Positioning of annotations happens at `frameChange`
    $reel.one('frameChange.test', function(){
      ok( !!$('div#my_annotation').length, 'Node node present');
      ok( !!$('div#my_annotation img').length, 'Wrapping an image node');
      equal( $('#my_annotation img').attr('src'), 'samples/badge-1.gif', 'Image `src`');
      equiv( $('#my_annotation img').attr('width') || $('#my_annotation img').css('width'), 120, 'CSS width');
      equiv( $('#my_annotation img').attr('height') || $('#my_annotation img').css('height'), 30, 'CSS height');
      start();
    });
  });

  asyncTest( '`link` holds a collection of HTML attributes used for an `a` tag inside the node', function(){
    expect(8);
    var
      selector= '#image',
      $reel= $(selector).reel({
        annotations: {
          "text_link": {
            link: {
              href: 'http://some/location',
              text: 'Click to navigate away'
            }
          },
          "image_link": {
            image: {
              src: 'some/my/image.jpg'
            },
            link: {
              href: 'http://some/location'
            }
          }
        }
      })

    // Positioning of annotations happens at `frameChange`
    $reel.one('frameChange.test', function(){
      ok( !!$('div#text_link').length, 'Node node present');
      ok( !!$('div#text_link a').length, 'Wrapping a link node');
      equal( $('#text_link a').attr('href'), 'http://some/location', 'Link `href`');
      equal( $('#text_link a').text(), 'Click to navigate away', '`title`');

      ok( !!$('div#image_link').length, 'Node node present');
      ok( !!$('div#image_link > a > img').length, 'Wrapping a link node wrapping an image node');
      equal( $('#image_link a').attr('href'), 'http://some/location', 'Link `href`');
      equal( $('#image_link img').attr('src'), 'some/my/image.jpg', 'Image `src`');

      start();
    });
  });

  asyncTest( 'Frame-based visibility annotation control properties `start` and `end`', function(){
    expect(36);
    var
      selector= '#image',
      frames= 36, // Default value
      should_be= '----+++++++++-----------------------'.split(''),
      $reel= $(selector).reel({
        annotations: {
          "my_annotation": {
            node: {
              text: "aaa"
            },
            x: 1, y: 1,
            start: 5,
            end: 13
          }
        },
        // And this will autoscroll thorugh all frames once
        entry: 1,
        opening: 1
      }),
      checked= [],
      $annotation= $('#my_annotation')

    // Positioning of annotations happens at `frameChange`
    // and we test it bubbled up to instance's parent
    $reel.parent().bind('frameChange.test', function(){
      var
        frame= $reel.data('frame'),
        should= should_be[frame - 1] == '+'

      equal( $annotation.is(':visible') , should, (should ? 'On' : 'Off')+' @ frame '+frame );

      checked.push(frame);
      if (checked.length == frames){
        $reel.parent().unbind('.test');
        start();
      }
    });
  });

  asyncTest( 'GH-69 The annotations wrapper DOM element is tagged with `frame-X` class name', function(){
    expect( 2 );
    var
      $reel= $('#image').reel({ annotations: {}, speed: 1 });

    setTimeout(function(){
      var
        frame= $reel.data('frame')
      ok( frame, 'Instance stopped at frame '+frame);
      ok( $('#image-reel').attr('class').match(/frame-[0-9]+/), 'The instance wrapper carries frame-'+frame+' class name');
      start();
    }, 123);
  });

  asyncTest( 'Horizontal position of annotation is defined by `x` property relative to left top corner', function(){
    expect( 1 );
    var
      x= '120px',
      $reel= $('#image').reel({ annotations: {
        'x-positioned-annotation': {
          x: x
        }
      }})

    $reel.bind('loaded.test', function(){
      equal( $('#x-positioned-annotation').css('left'), x, '120px');
      start();
    });
  });

  asyncTest( 'Vertical position of annotation is defined by `y` property', function(){
    expect( 2 );
    var
      y= 30,
      $reel= $('#image').reel({ annotations: {
        'y-positioned-annotation': {
          y: y
        }
      }})

    $reel.bind('loaded.test', function(){
      equal( $('#y-positioned-annotation').css('top'), y + 'px', '30px');
      equiv( $('#y-positioned-annotation').css('top'), y, 'It indeed is 30px');
      start();
    });
  });

  asyncTest( 'Both `x` and `y` properties can accept an Array of positions coordinates', function(){
    expect( 12 );
    var
      frames= 6,
      xs= [ 10, 20, 30, 20, 10, 0 ],
      ys= [ 20, 10, 0 , 40, 50, 30 ],
      y= 30,
      from= 1,
      $reel= $('#image').reel({ frames: frames, speed: 1, annotations: {
        'xy-positioned-annotation': {
          x: xs,
          y: ys
        }
      }})

    $reel.parent().bind('frameChange.test', function(){
      var
        frame= $reel.data('frame'),
        index= frame - from

      if (index < 0) return;

      equiv( $('#xy-positioned-annotation').css('left'), xs[index], 'x @ frame '+frame);
      equiv( $('#xy-positioned-annotation').css('top'), ys[index], 'y @ frame '+frame);
      if (index >= xs.length-1) start();
    });
  });

  asyncTest( 'Both `x` and `y` properties can accept an Array of positions coordinates when `start` and `end` are set', function(){
    expect( 8 );
    var
      frames= 6,
      xs= [ 10, 20, 30, 20 ],
      ys= [ 20, 10, 0 , 40 ],
      y= 30,
      from= 2,
      $reel= $('#image').reel({ frames: frames, frame: 2, speed: 1, annotations: {
        'xy-positioned-annotation': {
          start: from,
          end: 5,
          x: xs,
          y: ys
        }
      }})

    $reel.parent().bind('frameChange.test', function(){
      var
        frame= $reel.data('frame'),
        index= frame - from

      if (index < 0) return;

      equiv( $('#xy-positioned-annotation').css('left'), xs[index], 'x @ frame '+frame);
      equiv( $('#xy-positioned-annotation').css('top'), ys[index], 'y @ frame '+frame);
      if (index >= xs.length-1) start();
    });
  });

  asyncTest( 'GH-79 `click` event on annotation is not propagated up, where it would cause Reel to advance left/right', function(){
    expect( 1 );
    var
      $reel= $('#image').reel({ annotations: {
        'annotation': {
          x: 10,
          y: 10,
          link: {
            click: function(){
              ok( true, 'Annotation `click` handler fired.');
            }
          }
        }
      }})

    $('#annotation a')
    .parent()
    .bind('click.test', function(){
      ok( false, '`click` propagated to the annotation wrapper...');
    })
    .parent()
    .bind('click.test', function(){
      ok( false, '`click` Cpropagated to the instance wrapper...');
    })
    $('#annotation a').click();
    start();
  });

})(jQuery);
<|endoftext|>


<commit_before>var expect = require('chai').expect,
    fixtures = require('../fixtures'),
    Cookie = require('../../lib/index.js').Cookie;

describe('Cookie', function () {
    describe('sanity', function () {
        var rawCookie = fixtures.collectionV2.item[0].response[0].cookie[0],
            cookie = new Cookie(rawCookie);

        it('initializes successfully', function () {
            expect(cookie).to.be.ok;
        });

        it('should work correctly with a raw cookie string as well', function () {
            var strCookie = new Cookie('foo=bar;');

            expect(strCookie).to.deep.include({
                name: 'foo',
                value: 'bar'
            });
        });

        it('should work correctly with specific options and value defaults', function () {
            var expires = 'Sat, 02 May 2020 23:38:25 GMT',
                strCookie = new Cookie({
                    name: 'foo',
                    expires: expires, // just a test, these options won't usually appear together
                    maxAge: 1234
                });

            expect(strCookie.value).to.be.undefined;
            expect(strCookie).to.deep.include({
                name: 'foo',
                maxAge: 1234
            });
            expect(strCookie.expires).to.be.ok;
        });

        it('should handle malformed values', function () {
            var strCookie = new Cookie('foo=%E0%A4%A');

            expect(strCookie).to.deep.include({
                name: 'foo',
                value: '%25E0%25A4%25A'
            });
            expect(strCookie.valueOf()).to.equal('%E0%A4%A');
        });

        describe('has property', function () {
            it('domain', function () {
                expect(cookie).to.have.property('domain', rawCookie.domain);
            });

            it('expires', function () {
                expect(cookie).to.have.property('expires', rawCookie.expires);
            });

            it('hostOnly', function () {
                expect(cookie).to.have.property('hostOnly', rawCookie.hostOnly);
            });

            it('httpOnly', function () {
                expect(cookie).to.have.property('httpOnly', rawCookie.httpOnly);
            });

            it.skip('maxAge', function () { // @todo: possibly delete test. seems like based on old expectations
                expect(cookie).to.have.property('maxAge', undefined);
            });

            it('path', function () {
                expect(cookie).to.have.property('path', rawCookie.path);
            });

            it('secure', function () {
                expect(cookie).to.have.property('secure', rawCookie.secure);
            });

            it('session', function () {
                expect(cookie).to.have.property('session', rawCookie.session);
            });

            it('value', function () {
                expect(cookie).to.have.property('value', rawCookie.value);
            });

            it('_', function () {
                expect(cookie).to.have.property('_');
                expect(cookie._).to.have.property('postman_storeId', rawCookie._postman_storeId);
            });

            it('update', function () {
                expect(cookie.update).to.be.ok;
                expect(cookie.update).to.be.a('function');
            });
        });
    });

    describe('json representation', function () {
        it('must match what it was initialized with', function () {
            var rawCookie = fixtures.collectionV2.item[0].response[0].cookie[0],
                cookie = new Cookie(rawCookie),
                jsonified = cookie.toJSON();
            expect(jsonified).to.deep.include({
                domain: rawCookie.domain,
                httpOnly: rawCookie.httpOnly,
                hostOnly: rawCookie.hostOnly,
                name: rawCookie.key,
                path: rawCookie.path,
                expires: rawCookie.expires,
                secure: rawCookie.secure,
                session: rawCookie.session,
                value: rawCookie.value
            });
        });
    });

    describe('parsing', function () {
        var rawCookie = fixtures.rawCookie;
        it('should be parsed properly', function () {
            var parsed = Cookie.parse(rawCookie),
                ext;
            expect(parsed).to.deep.include({
                key: 'GAPS',
                value: 'lol',
                expires: 'Sun, 04-Feb-2018 14:18:27 GMT',
                secure: true,
                httpOnly: true
            });
            expect(parsed.extensions).to.be.an('array').that.has.lengthOf(1);

            ext = parsed.extensions[0];
            expect(ext).to.deep.include({
                key: 'Priority',
                value: 'HIGH'
            });
        });
    });

    describe('isCookie', function () {
        var rawCookie = {
            domain: '.httpbin.org',
            expires: 1502442248,
            hostOnly: false,
            httpOnly: false,
            key: '_ga',
            path: '/',
            secure: false,
            session: false,
            _postman_storeId: '0',
            value: 'GA1.2.113558537.1435817423'
        };

        it('should return true for a cookie instance', function () {
            expect(Cookie.isCookie(new Cookie(rawCookie))).to.be.true;
        });

        it('should return false for a raw cookie object', function () {
            expect(Cookie.isCookie(rawCookie)).to.be.false;
        });

        it('should return false when called without arguments', function () {
            expect(Cookie.isCookie()).to.be.false;
        });
    });

    describe('.parse', function () {
        it('should bail out for non string input', function () {
            expect(Cookie.parse(['random'])).to.eql(['random']);
        });

        it('should correctly handle valid input', function () {
            expect(Cookie.parse('foo=bar;domain=postman-echo.com')).to.eql({
                domain: 'postman-echo.com',
                key: 'foo',
                value: 'bar'
            });
        });
    });

    describe('.splitParam', function () {
        it('should correctly split string cookie values into their components', function () {
            expect(Cookie.splitParam('foo="bar"')).to.eql({
                key: 'foo',
                value: 'bar'
            });
        });
    });

    describe('value', function () {
        it('should be returned by valueOf function', function () {
            expect((new Cookie({
                name: 'blah',
                value: 'this is a cookie value'
            })).valueOf()).to.eql('this is a cookie value');
        });
    });

    describe('valueOf', function () {
        it('should handle malformed URI sequence', function () {
            expect((new Cookie({
                name: 'blah',
                value: '%E0%A4%A'
            })).valueOf()).to.eql('%E0%A4%A');
        });
    });

    describe('unparseSingle', function () {
        it('should return just the value in case of no cookie name', function () {
            var rawCookie = {
                    expires: 1502442248,
                    hostOnly: false,
                    httpOnly: false,
                    key: 'foo',
                    path: '/',
                    secure: false,
                    session: false,
                    value: 'bar'
                },
                unparsedSingle = Cookie.unparseSingle(rawCookie);
            expect(unparsedSingle).equals('bar');
        });

        it('should be unparsed properly in case of valid cookie name', function () {
            var rawCookie = {
                    name: 'testCookie',
                    expires: 1502442248,
                    hostOnly: false,
                    httpOnly: false,
                    key: 'foo',
                    path: '/',
                    secure: false,
                    session: false,
                    value: 'fooTest'
                },
                unparsedSingle = Cookie.unparseSingle(rawCookie);
            expect(unparsedSingle).equals(rawCookie.name + '=' + rawCookie.value);
        });
    });

    describe('unparse', function () {
        it('should stringify an array of cookies into a single string', function () {
            var rawCookie1 = {
                    name: 'testCookie1',
                    domain: '.httpbin.org',
                    expires: 1502442248,
                    key: 'foo1',
                    path: '/',
                    value: 'fooTest1'
                },
                rawCookie2 = {
                    name: 'testCookie2',
                    domain: '.httpbin.org',
                    expires: 1502442248,
                    key: 'foo2',
                    path: '/',
                    value: 'fooTest2'
                },
                cookieArray = [],
                unparse;
            cookieArray.push(rawCookie1);
            cookieArray.push(rawCookie2);

            unparse = Cookie.unparse(cookieArray);
            expect(unparse).equals('testCookie1=fooTest1; testCookie2=fooTest2');
        });
    });

    describe('stringify', function () {
        it('should return single Set-Cookie header string', function () {
            var rawCookie = {
                    domain: '.httpbin.org',
                    expires: 1502442248,
                    hostOnly: false,
                    httpOnly: false,
                    key: 'foo',
                    path: '/',
                    secure: false,
                    session: false,
                    value: 'fooTest'
                },
                cookie = new Cookie(rawCookie);
            expect(Cookie.stringify(cookie))
                .equals('foo=fooTest; Expires=1502442248; Domain=.httpbin.org; Path=/');
        });
    });

    describe('toString', function () {
        it('should return single Set-Cookie header string with key value', function () {
            var cookie = new Cookie({
                key: 'foo',
                value: 'fooTest'
            });
            expect(cookie.toString())
                .equals('foo=fooTest');
        });

        it('should return single Set-Cookie header string with expires', function () {
            var cookie = new Cookie({
                key: 'foo',
                value: 'fooTest',
                expires: '14 Jun 2017 00:00:00 PDT'
            });
            expect(cookie.toString())
                .equals('foo=fooTest; Expires=Wed, 14 Jun 2017 07:00:00 GMT');
        });

        it('should return single Set-Cookie header string with secure and httpOnly set to true', function () {
            var cookie = new Cookie({
                key: 'foo',
                value: 'fooTest',
                httpOnly: true,
                secure: true
            });
            expect(cookie.toString())
                .equals('foo=fooTest; Secure; HttpOnly');
        });

        it('should return single Set-Cookie header string with maxAge value', function () {
            var cookie = new Cookie({
                key: 'foo',
                value: 'fooTest',
                maxAge: 1502442248
            });
            expect(cookie.toString())
                .equals('foo=fooTest; Max-Age=1502442248');
        });
    });
});
<commit_msg>Rerunning the pipeline<commit_after>var expect = require('chai').expect,
    fixtures = require('../fixtures'),
    Cookie = require('../../lib/index.js').Cookie;

describe('Cookie', function () {
    describe('sanity', function () {
        var rawCookie = fixtures.collectionV2.item[0].response[0].cookie[0],
            cookie = new Cookie(rawCookie);

        it('initializes successfully', function () {
            expect(cookie).to.be.ok;
        });

        it('should work correctly with a raw cookie string as well', function () {
            var strCookie = new Cookie('foo=bar;');

            expect(strCookie).to.deep.include({
                name: 'foo',
                value: 'bar'
            });
        });

        it('should work correctly with specific options and value defaults', function () {
            var expires = 'Sat, 02 May 2020 23:38:25 GMT',
                strCookie = new Cookie({
                    name: 'foo',
                    expires: expires, // just a test, these options won't usually appear together
                    maxAge: 1234
                });

            expect(strCookie.value).to.be.undefined;
            expect(strCookie).to.deep.include({
                name: 'foo',
                maxAge: 1234
            });
            expect(strCookie.expires).to.be.ok;
        });

        it('should handle malformed values', function () {
            var strCookie = new Cookie('foo=%E0%A4%A');

            expect(strCookie).to.deep.include({
                name: 'foo',
                value: '%25E0%25A4%25A'
            });
            expect(strCookie.valueOf()).to.equal('%E0%A4%A');
        });

        describe('has property', function () {
            it('domain', function () {
                expect(cookie).to.have.property('domain', rawCookie.domain);
            });

            it('expires', function () {
                expect(cookie).to.have.property('expires', rawCookie.expires);
            });

            it('hostOnly', function () {
                expect(cookie).to.have.property('hostOnly', rawCookie.hostOnly);
            });

            it('httpOnly', function () {
                expect(cookie).to.have.property('httpOnly', rawCookie.httpOnly);
            });

            it.skip('maxAge', function () { // @todo: possibly delete test. seems like based on old expectations
                expect(cookie).to.have.property('maxAge', undefined);
            });

            it('path', function () {
                expect(cookie).to.have.property('path', rawCookie.path);
            });

            it('secure', function () {
                expect(cookie).to.have.property('secure', rawCookie.secure);
            });

            it('session', function () {
                expect(cookie).to.have.property('session', rawCookie.session);
            });

            it('value', function () {
                expect(cookie).to.have.property('value', rawCookie.value);
            });

            it('_', function () {
                expect(cookie).to.have.property('_');
                expect(cookie._).to.have.property('postman_storeId', rawCookie._postman_storeId);
            });

            it('update', function () {
                expect(cookie.update).to.be.ok;
                expect(cookie.update).to.be.a('function');
            });
        });
    });

    describe('json representation', function () {
        it('must match what it was initialized with', function () {
            var rawCookie = fixtures.collectionV2.item[0].response[0].cookie[0],
                cookie = new Cookie(rawCookie),
                jsonified = cookie.toJSON();
            expect(jsonified).to.deep.include({
                domain: rawCookie.domain,
                httpOnly: rawCookie.httpOnly,
                hostOnly: rawCookie.hostOnly,
                name: rawCookie.key,
                path: rawCookie.path,
                expires: rawCookie.expires,
                secure: rawCookie.secure,
                session: rawCookie.session,
                value: rawCookie.value
            });
        });
    });

    describe('parsing', function () {
        var rawCookie = fixtures.rawCookie;
        it('should be parsed properly', function () {
            var parsed = Cookie.parse(rawCookie),
                ext;
            expect(parsed).to.deep.include({
                key: 'GAPS',
                value: 'lol',
                expires: 'Sun, 04-Feb-2018 14:18:27 GMT',
                secure: true,
                httpOnly: true
            });
            expect(parsed.extensions).to.be.an('array').that.has.lengthOf(1);

            ext = parsed.extensions[0];
            expect(ext).to.deep.include({
                key: 'Priority',
                value: 'HIGH'
            });
        });
    });

    describe('isCookie', function () {
        var rawCookie = {
            domain: '.httpbin.org',
            expires: 1502442248,
            hostOnly: false,
            httpOnly: false,
            key: '_ga',
            path: '/',
            secure: false,
            session: false,
            _postman_storeId: '0',
            value: 'GA1.2.113558537.1435817423'
        };

        it('should return true for a cookie instance', function () {
            expect(Cookie.isCookie(new Cookie(rawCookie))).to.be.true;
        });

        it('should return false for a raw cookie object', function () {
            expect(Cookie.isCookie(rawCookie)).to.be.false;
        });

        it('should return false when called without arguments', function () {
            expect(Cookie.isCookie()).to.be.false;
        });
    });

    describe('.parse', function () {
        it('should bail out for non string input', function () {
            expect(Cookie.parse(['random'])).to.eql(['random']);
        });

        it('should correctly handle valid input', function () {
            expect(Cookie.parse('foo=bar;domain=postman-echo.com')).to.eql({
                domain: 'postman-echo.com',
                key: 'foo',
                value: 'bar'
            });
        });
    });

    describe('.splitParam', function () {
        it('should correctly split string cookie values into their components', function () {
            expect(Cookie.splitParam('foo="bar"')).to.eql({
                key: 'foo',
                value: 'bar'
            });
        });
    });

    describe('value', function () {
        it('should be returned by valueOf function', function () {
            expect((new Cookie({
                name: 'blah',
                value: 'this is a cookie value'
            })).valueOf()).to.eql('this is a cookie value');
        });
    });

    describe('valueOf', function () {
        it('should handle malformed URI sequence', function () {
            expect((new Cookie({
                name: 'blah',
                value: '%E0%A4%A'
            })).valueOf()).to.eql('%E0%A4%A');
        });
    });

    describe('unparseSingle', function () {
        it('should return only the value in case of no cookie name specified', function () {
            var rawCookie = {
                    expires: 1502442248,
                    hostOnly: false,
                    httpOnly: false,
                    key: 'foo',
                    path: '/',
                    secure: false,
                    session: false,
                    value: 'bar'
                },
                unparsedSingle = Cookie.unparseSingle(rawCookie);
            expect(unparsedSingle).equals('bar');
        });

        it('should be unparsed properly in case of valid cookie name', function () {
            var rawCookie = {
                    name: 'testCookie',
                    expires: 1502442248,
                    hostOnly: false,
                    httpOnly: false,
                    key: 'foo',
                    path: '/',
                    secure: false,
                    session: false,
                    value: 'fooTest'
                },
                unparsedSingle = Cookie.unparseSingle(rawCookie);
            expect(unparsedSingle).equals(rawCookie.name + '=' + rawCookie.value);
        });
    });

    describe('unparse', function () {
        it('should stringify an array of cookies into a single string', function () {
            var rawCookie1 = {
                    name: 'testCookie1',
                    domain: '.httpbin.org',
                    expires: 1502442248,
                    key: 'foo1',
                    path: '/',
                    value: 'fooTest1'
                },
                rawCookie2 = {
                    name: 'testCookie2',
                    domain: '.httpbin.org',
                    expires: 1502442248,
                    key: 'foo2',
                    path: '/',
                    value: 'fooTest2'
                },
                cookieArray = [],
                unparse;
            cookieArray.push(rawCookie1);
            cookieArray.push(rawCookie2);

            unparse = Cookie.unparse(cookieArray);
            expect(unparse).equals('testCookie1=fooTest1; testCookie2=fooTest2');
        });
    });

    describe('stringify', function () {
        it('should return single Set-Cookie header string', function () {
            var rawCookie = {
                    domain: '.httpbin.org',
                    expires: 1502442248,
                    hostOnly: false,
                    httpOnly: false,
                    key: 'foo',
                    path: '/',
                    secure: false,
                    session: false,
                    value: 'fooTest'
                },
                cookie = new Cookie(rawCookie);
            expect(Cookie.stringify(cookie))
                .equals('foo=fooTest; Expires=1502442248; Domain=.httpbin.org; Path=/');
        });
    });

    describe('toString', function () {
        it('should return single Set-Cookie header string with key value', function () {
            var cookie = new Cookie({
                key: 'foo',
                value: 'fooTest'
            });
            expect(cookie.toString())
                .equals('foo=fooTest');
        });

        it('should return single Set-Cookie header string with expires', function () {
            var cookie = new Cookie({
                key: 'foo',
                value: 'fooTest',
                expires: '14 Jun 2017 00:00:00 PDT'
            });
            expect(cookie.toString())
                .equals('foo=fooTest; Expires=Wed, 14 Jun 2017 07:00:00 GMT');
        });

        it('should return single Set-Cookie header string with secure and httpOnly set to true', function () {
            var cookie = new Cookie({
                key: 'foo',
                value: 'fooTest',
                httpOnly: true,
                secure: true
            });
            expect(cookie.toString())
                .equals('foo=fooTest; Secure; HttpOnly');
        });

        it('should return single Set-Cookie header string with maxAge value', function () {
            var cookie = new Cookie({
                key: 'foo',
                value: 'fooTest',
                maxAge: 1502442248
            });
            expect(cookie.toString())
                .equals('foo=fooTest; Max-Age=1502442248');
        });
    });
});
<|endoftext|>


<commit_before>var expect = require('expect.js'),
    fixtures = require('../fixtures'),
    Header = require('../../lib/index.js').Header,
    PropertyList = require('../../lib/index.js').PropertyList;

/* global describe, it */
describe('Header', function () {
    describe('sanity', function () {
        var rawHeaders = fixtures.collectionV2.item[0].response[0].header,
            headers = (new PropertyList(Header, undefined, rawHeaders)).all();

        it('initialize successfully', function () {
            expect(headers).to.be.ok();
            expect(headers).to.be.an('array');
        });

        describe('each contain property', function () {
            var header = headers[0];

            it('key', function () {
                expect(header).to.have.property('key', 'Content-Type');
            });

            it('value', function () {
                expect(header).to.have.property('value', 'application/json');
            });
        });
    });

    it('must have a .create to create new instamce', function () {
        expect(Header.create('Mon, 25 Jul 2016 13:11:41 GMT', 'Date')).to.eql({
            key: 'Date',
            value: 'Mon, 25 Jul 2016 13:11:41 GMT'
        });
        expect(Header.create('value', 'name')).to.eql({
            key: 'name',
            value: 'value'
        });
        expect(Header.create('name:value')).to.eql({
            key: 'name',
            value: 'value'
        });
        expect(Header.create({ key: 'name', value: 'value' })).to.eql({
            key: 'name',
            value: 'value'
        });
        expect(Header.create('name: my: value:is this')).to.eql({
            key: 'name',
            value: 'my: value:is this'
        });
    });

    describe('parseSingle', function () {
        it('should return an empty header on invalid input', function () {
            expect(Header.parseSingle({})).to.eql({
                key: '',
                value: ''
            });
        });

        it('should create an empty header on invalid input', function () {
            expect(Header.parseSingle('novalue')).to.eql({
                key: 'novalue',
                value: ''
            });
        });

        it('should strip whitespace and return the header', function () {
            expect(Header.parseSingle('\tDate: Mon, 25 Jul 2016 13:11:41 GMT\n\n')).to.eql({
                key: 'Date',
                value: 'Mon, 25 Jul 2016 13:11:41 GMT'
            });
        });
    });

    describe('unparse', function () {
        it('should unparse headers to a string', function () {
            var raw = 'name1: value1\r\nname2: value2',
                list = new PropertyList(Header, {}, raw);
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
            expect(Header.unparse(list)).to.be('name1: value1\nname2: value2');
        });

        it('should honor the given separator "\\r\\n"', function () {
            var raw = 'name1: value1\r\nname2: value2',
                list = new PropertyList(Header, {}, raw);
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
            expect(Header.unparse(list, '\r\n')).to.be(raw);
        });
    });

    describe('inside PropertyList', function () {
        it('must load a header string', function () {
            var list = new PropertyList(Header, {}, 'name1:value1\r\nname2:value2');
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
        });
        it('must load an array of strings', function () {
            var list = new PropertyList(Header, {}, ['name1:value1', 'name2:value2']);
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
        });
        it('must load an array of objects', function () {
            var list = new PropertyList(Header, {}, [{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
        });
        it('must load a plain header key:value object', function () {
            var list = new PropertyList(Header, {}, {
                name1: 'value1',
                name2: 'value2'
            });
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
        });

        // @todo - this is not supported yet, unskip this test when this method of header construction is supported
        it.skip('must load a plain header key:value object, with values being an array', function () {
            var list = new PropertyList(Header, {}, {
                name1: ['value1', 'value2'],
                name2: 'value3'
            });
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name1',
                value: 'value2'
            }, {
                key: 'name2',
                value: 'value3'
            }]);
        });
        it('must load headers with empty values', function () {
            var list = new PropertyList(Header, {}, {
                name1: 'value1',
                name2: ''
            });
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: ''
            }]);
        });
    });

    describe('isHeader', function () {
        // eslint-disable-next-line max-len
        var rawHeader = 'Content-Type: application/json\nAuthorization: Hawk id="dh37fgj492je", ts="1448549987", nonce="eOJZCd", mac="O2TFlvAlMvKVSKOzc6XkfU6+5285k5p3m5dAjxumo2k="\n';

        it('should return true for a Header instance', function () {
            expect(Header.isHeader(new Header(rawHeader))).to.be(true);
        });

        it('should return false for a raw Header object', function () {
            expect(Header.isHeader(rawHeader)).to.be(false);
        });

        it('should return false when called without arguments', function () {
            expect(Header.isHeader()).to.be(false);
        });
    });
});
<commit_msg>test(unit): Added Header edge case tests :white_check_mark:<commit_after>var expect = require('expect.js'),
    fixtures = require('../fixtures'),
    Header = require('../../lib/index.js').Header,
    PropertyList = require('../../lib/index.js').PropertyList;

/* global describe, it */
describe('Header', function () {
    describe('sanity', function () {
        var rawHeaders = fixtures.collectionV2.item[0].response[0].header,
            headers = (new PropertyList(Header, undefined, rawHeaders)).all();

        it('initialize successfully', function () {
            expect(headers).to.be.ok();
            expect(headers).to.be.an('array');
        });

        describe('each contain property', function () {
            var header = headers[0];

            it('key', function () {
                expect(header).to.have.property('key', 'Content-Type');
            });

            it('value', function () {
                expect(header).to.have.property('value', 'application/json');
            });
        });
    });

    it('must have a .create to create new instamce', function () {
        expect(Header.create('Mon, 25 Jul 2016 13:11:41 GMT', 'Date')).to.eql({
            key: 'Date',
            value: 'Mon, 25 Jul 2016 13:11:41 GMT'
        });
        expect(Header.create('value', 'name')).to.eql({
            key: 'name',
            value: 'value'
        });
        expect(Header.create('name:value')).to.eql({
            key: 'name',
            value: 'value'
        });
        expect(Header.create({ key: 'name', value: 'value' })).to.eql({
            key: 'name',
            value: 'value'
        });
        expect(Header.create('name: my: value:is this')).to.eql({
            key: 'name',
            value: 'my: value:is this'
        });
    });

    describe('parseSingle', function () {
        it('should return an empty header on invalid input', function () {
            expect(Header.parseSingle({})).to.eql({
                key: '',
                value: ''
            });
        });

        it('should create an empty header on invalid input', function () {
            expect(Header.parseSingle('novalue')).to.eql({
                key: 'novalue',
                value: ''
            });
        });

        it('should strip whitespace and return the header', function () {
            expect(Header.parseSingle('\tDate: Mon, 25 Jul 2016 13:11:41 GMT\n\n')).to.eql({
                key: 'Date',
                value: 'Mon, 25 Jul 2016 13:11:41 GMT'
            });
        });
    });

    describe('unparse', function () {
        it('should unparse headers to a blank string for invalid inputs', function () {
            expect(Header.unparse('')).to.be('');
            expect(Header.unparse({ key: 'foo', value: 'bar' })).to.be('');

            expect(Header.unparseSingle('')).to.be('');
        });

        it('should unparse headers to a string', function () {
            var raw = 'name1: value1\r\nname2: value2',
                list = new PropertyList(Header, {}, raw);
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
            expect(Header.unparse(list)).to.be('name1: value1\nname2: value2');
        });

        it('should honor the given separator "\\r\\n"', function () {
            var raw = 'name1: value1\r\nname2: value2',
                list = new PropertyList(Header, {}, raw);
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
            expect(Header.unparse(list, '\r\n')).to.be(raw);
        });
    });

    describe('inside PropertyList', function () {
        it('must load a header string', function () {
            var list = new PropertyList(Header, {}, 'name1:value1\r\nname2:value2');
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
        });
        it('must load an array of strings', function () {
            var list = new PropertyList(Header, {}, ['name1:value1', 'name2:value2']);
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
        });
        it('must load an array of objects', function () {
            var list = new PropertyList(Header, {}, [{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
        });
        it('must load a plain header key:value object', function () {
            var list = new PropertyList(Header, {}, {
                name1: 'value1',
                name2: 'value2'
            });
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: 'value2'
            }]);
        });

        // @todo - this is not supported yet, unskip this test when this method of header construction is supported
        it.skip('must load a plain header key:value object, with values being an array', function () {
            var list = new PropertyList(Header, {}, {
                name1: ['value1', 'value2'],
                name2: 'value3'
            });
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name1',
                value: 'value2'
            }, {
                key: 'name2',
                value: 'value3'
            }]);
        });
        it('must load headers with empty values', function () {
            var list = new PropertyList(Header, {}, {
                name1: 'value1',
                name2: ''
            });
            expect(list.all()).to.eql([{
                key: 'name1',
                value: 'value1'
            }, {
                key: 'name2',
                value: ''
            }]);
        });
    });

    describe('isHeader', function () {
        // eslint-disable-next-line max-len
        var rawHeader = 'Content-Type: application/json\nAuthorization: Hawk id="dh37fgj492je", ts="1448549987", nonce="eOJZCd", mac="O2TFlvAlMvKVSKOzc6XkfU6+5285k5p3m5dAjxumo2k="\n';

        it('should return true for a Header instance', function () {
            expect(Header.isHeader(new Header(rawHeader))).to.be(true);
        });

        it('should return false for a raw Header object', function () {
            expect(Header.isHeader(rawHeader)).to.be(false);
        });

        it('should return false when called without arguments', function () {
            expect(Header.isHeader()).to.be(false);
        });
    });
});
<|endoftext|>


<commit_before>describe('timers module', function () {
    this.timeout(1000 * 60);
    var Timers = require('../../lib/sandbox/timers');

    it('must be able to set an event', function (done) {
        var status = 'uneventful',
            timers,
            id;

        timers = new Timers(null, done, null, function () {
            expect(status).to.eql('eventful');
            done();
        });

        id = timers.setEvent(function (msg) {
            status = msg;
        });

        setTimeout(function () {
            timers.clearEvent(id, 'eventful');
        }, 10);
    });
});
<commit_msg>Update timers tests to chai<commit_after>describe('timers module', function () {
    this.timeout(1000 * 60);
    var Timers = require('../../lib/sandbox/timers');

    it('should be able to set an event', function (done) {
        var status = 'uneventful',
            timers,
            id;

        timers = new Timers(null, done, null, function () {
            expect(status).to.eql('eventful');
            done();
        });

        id = timers.setEvent(function (msg) {
            status = msg;
        });

        setTimeout(function () {
            timers.clearEvent(id, 'eventful');
        }, 10);
    });
});
<|endoftext|>


<commit_before>// jasmine-based where.spec.js

if (typeof require == 'function') {
  // enable to re-use in a browser without require.js
  require('../../where.js');
}

describe('where.js jasmine spec', function () {

   /* CHARACTERIZATION TESTS */

  describe('where characteristics', function () {

    it('should be global', function() {
      expect(typeof where).toBe('function');
    });

    it('should accept 2 arguments', function () {
      expect(where.length).toBe(2);
    });

    it('should accept context with jasmine and expect specified', function () {
      where(function(){/***
          a  |  b  |  c
          1  |  2  |  3
        ***/
        expect(jasmine).toBe(context.jasmine);
        expect(expect).toBe(context.expect);

      }, { jasmine: 1, expect: expect});
    });

    it('should accept context arg with {strategy: "jasmine"}', function () {
      where(function(){/***
          a  |  b  |  c
          1  |  2  |  3
        ***/
        expect(strategy).toBe('jasmine');

      }, { strategy: 'jasmine', expect: expect});
    });

    it('should accept only a function as first argument', function () {
      expect(function () {
        where(!function(){});
       }).toThrow();
    });

    it('should remove line comments', function () {
      expect(function () {
        where(function(){
          /***
            | a | b | c |
            | 1 | 2 | 2 | // should pass
          //| 4 | 3 | x | (should not execute)
          ***/
          expect(Math.max(a, b)).toBe(c);
        });
       }).not.toThrow();
    });

    it('should throw when all data rows are commented', function () {
      expect(function () {
        where(function(){
          /***
              a  |  b  |  c
          //  1  |  2  |  2 // should fail
          ***/
          expect(Math.max(a, b)).toBe(Number(c));
        });
       }).toThrow();
    });

    it('should not throw if missing expectation', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          1  |  2  |  2
          4  |  3  |  4
          6  |  6  |  6
        ***/});
       }).not.toThrow();
    });

    it('should pass with correct data and expectation', function () {
      where(function(){/***
          a  |  b  |  c
          1  |  2  |  2
          4  |  3  |  4
          6  |  6  |  6
        ***/
        expect(Math.max(a, b)).toBe(Number(c));
      });
    });

    it('should pass with left and right table borders', function () {
      where(function(){/***
        | d | e | f |
        | 1 | 2 | 2 |
        | 4 | 3 | 4 |
        | 6 | 6 | 6 |
        ***/
        expect(Math.max(d, e)).toBe(f);
      });
    });

    it('should return results', function () {
      var results = where(function(){/***
          a  |  b  |  c
          6  |  6  |  6
        ***/
        expect(Math.max(a, b)).toBe(Number(c));
      });

      expect(results.passing.length).toBe(1);
      expect(results.values.length).toBe(2);
      // values[0] is the label or header row
      expect(results.values[0].join(',')).toBe("a,b,c");
    });

    it('should ignore empty rows', function () {
      var results = where(function(){/***
          a  |  b  |  c

          6  |  6  |  6
        ***/
        expect(Math.max(a, b)).toBe(Number(c));
      });

      expect(results.values.length).toBe(2);
    });

    it('should pass with data containing various padding', function () {
      expect(function () {
        where(function(){/***
            a | b|c
             6|4 |10
          ***/

         // /* I DETECT A USABILITY ISSUE WITH Number() for every input      */
          expect(Number(a) + Number(b)).toBe(Number(c))
        });
      }).not.toThrow();
    });

    it('should convert numeric data automatically', function () {
      expect(function () {
        where(function(){/***

                a     |    b     |    c     |  p

                0     |    1     |    1     |  1
                0.0   |    1.0   |    1     |  1
               -1     |   +1     |    0     |  1
               +1.1   |   -1.2   |   -0.1   |  2
               08     |   08     |   16     |  2
                6     |    4     |   10.0   |  3
                8.030 |   -2.045 |    5.985 |  4
            1,000.67  | 1345     | 2345.67  |  6
                5f |      5 | 10f | 1
          ***/

          /*
           * using precisions for famous .1 + .2 == 0.30000000000000004
           * and 5.985 vs 5.98499999999999999999999999 bugs
           */
          var s = (a + b).toPrecision(p)
          expect(+s).toBe(c) // implicit conversion with prefixed +
        });

       }).not.toThrow();
    });

    it('should convert null, undefined, true, false automatically', function () {
      where(function () {
        /***
          a    | b         | c     | d
          null | undefined | false | true
        ***/
        expect(a).toBe(null);
        expect(b).toBe(undefined);
        expect(c).toBe(false);
        expect(d).toBe(true);
      });
    });

    it('should not modify quoted values', function () {
      where(function () {
        /***
          a  | b  | c    | d    | e   | f        | g
          '' | "" | "''" | '""' | ' ' | ' faff ' | 'undefined'
        ***/
        expect(a).toBe('\'\'');
        expect(b).toBe('\"\"');
        expect(c).toBe('\"\'\'\"');
        expect(d).toBe('\'"\"\'');
        expect(e).toBe('\' \'');
        expect(f).toBe('\' faff \'');
        expect(g).toBe('\'undefined\'');
      });
    });
  });

  /* MALFORMED TABLE */

  describe('malformed data table', function () {

    it('should throw when function has no data-table comment', function () {
      expect(function () {
        where(function(){});
       }).toThrow();
    });

    it('should throw when function has no data-table rows', function () {
      expect(function () {
        where(function(){/***
        ***/});
       }).toThrow();
    });

    it('should throw when function has only one row in data-table', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
        ***/});
       }).toThrow();
    });

    it('should throw with duplicate labels', function () {
      expect(function () {
        where(function(){/***
          a | a
          0 | 1
          ***/
        });
      }).toThrow();
    });

    it('should throw when function has un-separated items in data-table', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          6
        ***/});
       }).toThrow();
    });

    it('should throw when missing last value', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          1  |  2  |
        ***/});
      }).toThrow();
    });

    it('should throw when missing first value', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
             |  1  |  2
        ***/});
      }).toThrow();
    });

    it('should throw when missing inner value', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          1  |     | 2
        ***/});
      }).toThrow();
    });

    it('should throw when missing separator in data-table', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          6     4  |  0
        ***/});
       }).toThrow();
    });

    it('should throw if borders not balanced', function() {
      expect(function () {
        where(function(){/***
          | a | b | c
          | t | o | to
          ***/
          expect(a + b).toBe(c);
        });
      }).toThrow();
    });
  });

  /***
   * INTERCEPT & LOG TESTS
   * Use these tests to intercept results set by jasmine, particularly on specs
   * that fail.
   ***/

  describe('using strategy for intercept and log', function () {

    it('specify jasmine strategy in context', function () {

      var results = where(function(){/***
            a  |  b  |  c
            1  |  1  |  1
          ***/

          expect(jasmine).toBe(context.jasmine);

        }, { jasmine: jasmine, expect: expect});

      expect(results.failing.length).toBe(0);
      expect(results.passing.length).toBe(1);
    });

    it('should not throw on error when intercept specified', function () {

      var results = where(function(){/***
            a  |  b  |  c
            1  |  1  |  x
          ***/

          expect(Math.max(a, b)).toBe(c);

        }, { jasmine: jasmine, expect: expect, intercept: 1});

      expect(results.failing.length).toBe(1);
    });

    it('should log all results when specified', function () {

      // stub out console.log - then restore it afterward
      var log = console.log;

      var count = 0;

      console.log = function () {
        count += 1;
      }

      var results = where(function(){/***
            a  |  b  |  c
            1  |  1  |  1
            1  |  2  |  2
            4  |  2  |  4
            4  |  8  |  7
          ***/
          expect(Math.max(a, b)).toBe(Number(c));

        }, { jasmine: 1, expect: expect, intercept: 1, log: 1});

      expect(count).toBe(results.passing.length + results.failing.length);

      // RESTORE console.log
      console.log = log;
    });

    it('should return results for incorrect expectation', function () {

      var results = where(function(){/***
          a  |  b  |  c
          1  |  1  |  1
          1  |  2  |  2
          4  |  2  |  4
          4  |  8  |  7
        ***/
        expect(Math.max(a, b)).toBe(c);
      }, { strategy: 'jasmine', expect: expect, intercept: 1 });

      expect(results.failing.length).toBe(1);
      expect(results.passing.length).toBe(3);
      expect(results.failing[0].message).toContain("[a | b | c]");
      expect(results.failing[0].message).toContain("[4 | 8 | 7]");
      expect(results.failing[0].message).toContain("Expected 8 to be 7.");
    });

    it('should return results for incorrect matches or values', function () {

      var results = where(function(){/***
          a  |  b  |  c
          1  |  1  |  1
          1  |  2  |  x
          3  |  2  |  3
          5  |  3  |  5.01
        ***/

        // /* using match for numeric data here */
        expect(Math.max(a, b)).toBe(c);
      }, { strategy: 'jasmine', expect: expect, intercept: 1 });

      expect(results.failing.length).toBe(2);
      expect(results.passing.length).toBe(2);
      expect(results.failing[0].message).toContain("Expected 2 to be '" + results.values[2][2] + "'.");
      expect(results.failing[1].message).toContain("Expected 5 to be 5.01.");

    });

  });

  // ASYNCHRONOUS TESTS IN JASMINE

  describe('asynchronous tests', function () {

    it('should throw when missing separator in data-table', function (done) {

      setTimeout(function () {

        expect(function () {
          where(function(){/***
            a  |  b  |  c
            6     4  |  0
          ***/});
         }).toThrow();

         done();

      }, 500);

    });

    it('should work with intercept', function (done) {

      setTimeout(function () {

        var results = where(function(){/***
              a  |  b  |  c
              1  |  1  |  1
              1  |  2  |  2
              4  |  2  |  4
              4  |  8  |  7
            ***/
            expect(Math.max(a, b)).toBe(Number(c));
          }, { jasmine: 1, expect: expect, intercept: 1});

        expect(results.failing.length).toBe(1);
        expect(results.passing.length).toBe(3);
        expect(results.failing[0].message).toContain("Expected 8 to be 7.");

        done();

      }, 500);
    });

    it('should log all results', function (done) {

      setTimeout(function () {

        var results = where(function(){/***
              a  |  b  |  c
              1  |  1  |  1
              1  |  2  |  2
              4  |  2  |  4
              4  |  8  |  7
            ***/
            expect(Math.max(a, b)).toBe(Number(c));
          }, { jasmine: 1, expect: expect, intercept: 1, log: 1});

        expect(results.failing.length).toBe(1);
        expect(results.passing.length).toBe(3);
        expect(results.failing[0].message).toContain("[a | b | c]");
        expect(results.failing[0].message).toContain("[4 | 8 | 7]");
        expect(results.failing[0].message).toContain("Expected 8 to be 7.");

        done();

      }, 500);
    });

  });

  /***
   * Use these tests to see displayed stack traces and results messages for failed specs.
   ***/
  describe('non-intercepted failing tests', function () {

    it("stack trace ~ 'should contain at least 2 rows but has 0'", function () {

      // stub out console.log - then restore it afterwards.
      var log = console.log;

      var last;
      var results;

      console.log = function (msg) {
        last = msg;
      }
      try {
        results = where(function(){/***
          ***/
        });
      } catch(error) {
        last = error.message;
        console.log = log;
      }

      expect(last).toContain('should contain at least 2 rows but has 0');
      expect(results).toBeUndefined();
    });

  });

  describe('object tests', function () {
    // contributed via issues by @jamonholmgren 4 FEB 2014
    it('should instantiate objects with correct keys', function () {

      where(function () {
        /***
          a | b | c
          1 | 2 | 3
          6 | 12 | 18
        ***/

        var obj = new Obj(a,b,c); // DIY instantiation
        expect(obj.a + obj.b).toEqual(obj.c);

        // quick array test
        expect([a,b,c].reverse()).toEqual([c,b,a]);

      }, { Obj: function (a,b,c) { this.a = a; this.b = b; this.c = c;} });

    });
  });

  describe('Math tests', function () {
    it('should accept Math constants', function () {

      where(function () {
        /***
          a | b | c
          6 | 12 | 18
        ***/

      });

    });
  });
});<commit_msg>comment out Math constants test for now<commit_after>// jasmine-based where.spec.js

if (typeof require == 'function') {
  // enable to re-use in a browser without require.js
  require('../../where.js');
}

describe('where.js jasmine spec', function () {

   /* CHARACTERIZATION TESTS */

  describe('where characteristics', function () {

    it('should be global', function() {
      expect(typeof where).toBe('function');
    });

    it('should accept 2 arguments', function () {
      expect(where.length).toBe(2);
    });

    it('should accept context with jasmine and expect specified', function () {
      where(function(){/***
          a  |  b  |  c
          1  |  2  |  3
        ***/
        expect(jasmine).toBe(context.jasmine);
        expect(expect).toBe(context.expect);

      }, { jasmine: 1, expect: expect});
    });

    it('should accept context arg with {strategy: "jasmine"}', function () {
      where(function(){/***
          a  |  b  |  c
          1  |  2  |  3
        ***/
        expect(strategy).toBe('jasmine');

      }, { strategy: 'jasmine', expect: expect});
    });

    it('should accept only a function as first argument', function () {
      expect(function () {
        where(!function(){});
       }).toThrow();
    });

    it('should remove line comments', function () {
      expect(function () {
        where(function(){
          /***
            | a | b | c |
            | 1 | 2 | 2 | // should pass
          //| 4 | 3 | x | (should not execute)
          ***/
          expect(Math.max(a, b)).toBe(c);
        });
       }).not.toThrow();
    });

    it('should throw when all data rows are commented', function () {
      expect(function () {
        where(function(){
          /***
              a  |  b  |  c
          //  1  |  2  |  2 // should fail
          ***/
          expect(Math.max(a, b)).toBe(Number(c));
        });
       }).toThrow();
    });

    it('should not throw if missing expectation', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          1  |  2  |  2
          4  |  3  |  4
          6  |  6  |  6
        ***/});
       }).not.toThrow();
    });

    it('should pass with correct data and expectation', function () {
      where(function(){/***
          a  |  b  |  c
          1  |  2  |  2
          4  |  3  |  4
          6  |  6  |  6
        ***/
        expect(Math.max(a, b)).toBe(Number(c));
      });
    });

    it('should pass with left and right table borders', function () {
      where(function(){/***
        | d | e | f |
        | 1 | 2 | 2 |
        | 4 | 3 | 4 |
        | 6 | 6 | 6 |
        ***/
        expect(Math.max(d, e)).toBe(f);
      });
    });

    it('should return results', function () {
      var results = where(function(){/***
          a  |  b  |  c
          6  |  6  |  6
        ***/
        expect(Math.max(a, b)).toBe(Number(c));
      });

      expect(results.passing.length).toBe(1);
      expect(results.values.length).toBe(2);
      // values[0] is the label or header row
      expect(results.values[0].join(',')).toBe("a,b,c");
    });

    it('should ignore empty rows', function () {
      var results = where(function(){/***
          a  |  b  |  c

          6  |  6  |  6
        ***/
        expect(Math.max(a, b)).toBe(Number(c));
      });

      expect(results.values.length).toBe(2);
    });

    it('should pass with data containing various padding', function () {
      expect(function () {
        where(function(){/***
            a | b|c
             6|4 |10
          ***/

         // /* I DETECT A USABILITY ISSUE WITH Number() for every input      */
          expect(Number(a) + Number(b)).toBe(Number(c))
        });
      }).not.toThrow();
    });

    it('should convert numeric data automatically', function () {
      expect(function () {
        where(function(){/***

                a     |    b     |    c     |  p

                0     |    1     |    1     |  1
                0.0   |    1.0   |    1     |  1
               -1     |   +1     |    0     |  1
               +1.1   |   -1.2   |   -0.1   |  2
               08     |   08     |   16     |  2
                6     |    4     |   10.0   |  3
                8.030 |   -2.045 |    5.985 |  4
            1,000.67  | 1345     | 2345.67  |  6
                5f |      5 | 10f | 1
          ***/

          /*
           * using precisions for famous .1 + .2 == 0.30000000000000004
           * and 5.985 vs 5.98499999999999999999999999 bugs
           */
          var s = (a + b).toPrecision(p)
          expect(+s).toBe(c) // implicit conversion with prefixed +
        });

       }).not.toThrow();
    });

    it('should convert null, undefined, true, false automatically', function () {
      where(function () {
        /***
          a    | b         | c     | d
          null | undefined | false | true
        ***/
        expect(a).toBe(null);
        expect(b).toBe(undefined);
        expect(c).toBe(false);
        expect(d).toBe(true);
      });
    });

    it('should not modify quoted values', function () {
      where(function () {
        /***
          a  | b  | c    | d    | e   | f        | g
          '' | "" | "''" | '""' | ' ' | ' faff ' | 'undefined'
        ***/
        expect(a).toBe('\'\'');
        expect(b).toBe('\"\"');
        expect(c).toBe('\"\'\'\"');
        expect(d).toBe('\'"\"\'');
        expect(e).toBe('\' \'');
        expect(f).toBe('\' faff \'');
        expect(g).toBe('\'undefined\'');
      });
    });
  });

  /* MALFORMED TABLE */

  describe('malformed data table', function () {

    it('should throw when function has no data-table comment', function () {
      expect(function () {
        where(function(){});
       }).toThrow();
    });

    it('should throw when function has no data-table rows', function () {
      expect(function () {
        where(function(){/***
        ***/});
       }).toThrow();
    });

    it('should throw when function has only one row in data-table', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
        ***/});
       }).toThrow();
    });

    it('should throw with duplicate labels', function () {
      expect(function () {
        where(function(){/***
          a | a
          0 | 1
          ***/
        });
      }).toThrow();
    });

    it('should throw when function has un-separated items in data-table', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          6
        ***/});
       }).toThrow();
    });

    it('should throw when missing last value', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          1  |  2  |
        ***/});
      }).toThrow();
    });

    it('should throw when missing first value', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
             |  1  |  2
        ***/});
      }).toThrow();
    });

    it('should throw when missing inner value', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          1  |     | 2
        ***/});
      }).toThrow();
    });

    it('should throw when missing separator in data-table', function () {
      expect(function () {
        where(function(){/***
          a  |  b  |  c
          6     4  |  0
        ***/});
       }).toThrow();
    });

    it('should throw if borders not balanced', function() {
      expect(function () {
        where(function(){/***
          | a | b | c
          | t | o | to
          ***/
          expect(a + b).toBe(c);
        });
      }).toThrow();
    });
  });

  /***
   * INTERCEPT & LOG TESTS
   * Use these tests to intercept results set by jasmine, particularly on specs
   * that fail.
   ***/

  describe('using strategy for intercept and log', function () {

    it('specify jasmine strategy in context', function () {

      var results = where(function(){/***
            a  |  b  |  c
            1  |  1  |  1
          ***/

          expect(jasmine).toBe(context.jasmine);

        }, { jasmine: jasmine, expect: expect});

      expect(results.failing.length).toBe(0);
      expect(results.passing.length).toBe(1);
    });

    it('should not throw on error when intercept specified', function () {

      var results = where(function(){/***
            a  |  b  |  c
            1  |  1  |  x
          ***/

          expect(Math.max(a, b)).toBe(c);

        }, { jasmine: jasmine, expect: expect, intercept: 1});

      expect(results.failing.length).toBe(1);
    });

    it('should log all results when specified', function () {

      // stub out console.log - then restore it afterward
      var log = console.log;

      var count = 0;

      console.log = function () {
        count += 1;
      }

      var results = where(function(){/***
            a  |  b  |  c
            1  |  1  |  1
            1  |  2  |  2
            4  |  2  |  4
            4  |  8  |  7
          ***/
          expect(Math.max(a, b)).toBe(Number(c));

        }, { jasmine: 1, expect: expect, intercept: 1, log: 1});

      expect(count).toBe(results.passing.length + results.failing.length);

      // RESTORE console.log
      console.log = log;
    });

    it('should return results for incorrect expectation', function () {

      var results = where(function(){/***
          a  |  b  |  c
          1  |  1  |  1
          1  |  2  |  2
          4  |  2  |  4
          4  |  8  |  7
        ***/
        expect(Math.max(a, b)).toBe(c);
      }, { strategy: 'jasmine', expect: expect, intercept: 1 });

      expect(results.failing.length).toBe(1);
      expect(results.passing.length).toBe(3);
      expect(results.failing[0].message).toContain("[a | b | c]");
      expect(results.failing[0].message).toContain("[4 | 8 | 7]");
      expect(results.failing[0].message).toContain("Expected 8 to be 7.");
    });

    it('should return results for incorrect matches or values', function () {

      var results = where(function(){/***
          a  |  b  |  c
          1  |  1  |  1
          1  |  2  |  x
          3  |  2  |  3
          5  |  3  |  5.01
        ***/

        // /* using match for numeric data here */
        expect(Math.max(a, b)).toBe(c);
      }, { strategy: 'jasmine', expect: expect, intercept: 1 });

      expect(results.failing.length).toBe(2);
      expect(results.passing.length).toBe(2);
      expect(results.failing[0].message).toContain("Expected 2 to be '" + results.values[2][2] + "'.");
      expect(results.failing[1].message).toContain("Expected 5 to be 5.01.");

    });

  });

  // ASYNCHRONOUS TESTS IN JASMINE

  describe('asynchronous tests', function () {

    it('should throw when missing separator in data-table', function (done) {

      setTimeout(function () {

        expect(function () {
          where(function(){/***
            a  |  b  |  c
            6     4  |  0
          ***/});
         }).toThrow();

         done();

      }, 500);

    });

    it('should work with intercept', function (done) {

      setTimeout(function () {

        var results = where(function(){/***
              a  |  b  |  c
              1  |  1  |  1
              1  |  2  |  2
              4  |  2  |  4
              4  |  8  |  7
            ***/
            expect(Math.max(a, b)).toBe(Number(c));
          }, { jasmine: 1, expect: expect, intercept: 1});

        expect(results.failing.length).toBe(1);
        expect(results.passing.length).toBe(3);
        expect(results.failing[0].message).toContain("Expected 8 to be 7.");

        done();

      }, 500);
    });

    it('should log all results', function (done) {

      setTimeout(function () {

        var results = where(function(){/***
              a  |  b  |  c
              1  |  1  |  1
              1  |  2  |  2
              4  |  2  |  4
              4  |  8  |  7
            ***/
            expect(Math.max(a, b)).toBe(Number(c));
          }, { jasmine: 1, expect: expect, intercept: 1, log: 1});

        expect(results.failing.length).toBe(1);
        expect(results.passing.length).toBe(3);
        expect(results.failing[0].message).toContain("[a | b | c]");
        expect(results.failing[0].message).toContain("[4 | 8 | 7]");
        expect(results.failing[0].message).toContain("Expected 8 to be 7.");

        done();

      }, 500);
    });

  });

  /***
   * Use these tests to see displayed stack traces and results messages for failed specs.
   ***/
  describe('non-intercepted failing tests', function () {

    it("stack trace ~ 'should contain at least 2 rows but has 0'", function () {

      // stub out console.log - then restore it afterwards.
      var log = console.log;

      var last;
      var results;

      console.log = function (msg) {
        last = msg;
      }
      try {
        results = where(function(){/***
          ***/
        });
      } catch(error) {
        last = error.message;
        console.log = log;
      }

      expect(last).toContain('should contain at least 2 rows but has 0');
      expect(results).toBeUndefined();
    });

  });

  describe('object tests', function () {
    // contributed via issues by @jamonholmgren 4 FEB 2014
    it('should instantiate objects with correct keys', function () {

      where(function () {
        /***
          a | b | c
          1 | 2 | 3
          6 | 12 | 18
        ***/

        var obj = new Obj(a,b,c); // DIY instantiation
        expect(obj.a + obj.b).toEqual(obj.c);

        // quick array test
        expect([a,b,c].reverse()).toEqual([c,b,a]);

      }, { Obj: function (a,b,c) { this.a = a; this.b = b; this.c = c;} });

    });
  });

  // describe('Math tests', function () {
    // it('should accept Math constants', function () {

    // /* oops better implement something here... */
      // where(function () {
        // /***
          // a | b | c
          // 6 | 12 | 18
        // ***/

      // });

    // });
  // });
});<|endoftext|>


<commit_before>/*jshint node:true*/
module.exports = {
    "suites": {
        "config csslintrc override": {
            "args": [
                "--config=.rc1",
                "dir"
            ],
            "expecting": [
                "csslint: No errors in dir/a.css.",
                "csslint: No errors in dir/b.css.",
                0
            ]
        },
        "straight linting": {
            "args": [
                "dir"
            ],
            "expecting": [
                "csslint: There is 1 problem in dir/a.css.",
                "csslint: There is 1 problem in dir/b.css.",
                0
            ]
        },
        "version": {
            "args": [
                "--version"
            ],
            "expecting": [
                "v@VERSION@",
                0
            ]
        }
    },

    "fakedFs": {
        ".rc1": "--ignore=important,ids",
        "dir": {
            "a.css": ".a {color: red!important;}",
            "b.css": "#a {color: red;}"
        },
    }
};
<commit_msg>more tests<commit_after>/*jshint node:true*/
module.exports = {
    "suites": {
        "config csslintrc override": {
            "args": [
                "--config=.rc1",
                "dir"
            ],
            "expecting": [
                "csslint: No errors in dir/a.css.",
                "csslint: No errors in dir/b.css.",
                0
            ]
        },
        "straight linting": {
            "args": [
                "dir"
            ],
            "expecting": [
                "csslint: There is 1 problem in dir/a.css.",
                "csslint: There is 1 problem in dir/b.css.",
                0
            ]
        },
        "mix of cli options": {
            "args": [
                "--config=.rc1",
                "--ignore=important",
                "dir"
            ],
            "expecting": [
                "csslint: No errors in dir/a.css.",
                "csslint: There is 1 problem in dir/b.css.",
                0
            ]
        },
        "more mixes of cli options": {
            "args": [
                "--config=.rc1",
                "--errors=important",
                "dir"
            ],
            "expecting": [
                "csslint: There is 1 problem in dir/a.css.",
                "csslint: No errors in dir/b.css.",
                1
            ]
        },
        "version": {
            "args": [
                "--version"
            ],
            "expecting": [
                "v@VERSION@",
                0
            ]
        }
    },

    "fakedFs": {
        ".rc1": "--ignore=important,ids",
        "dir": {
            "a.css": ".a {color: red!important;}",
            "b.css": "#a {color: red;}"
        },
    }
};
<|endoftext|>


<commit_before>'use strict';

const Flow = require('../../lib/Flow');
const dispatcher = require('../../lib/Dispatcher');
const fs = require('graceful-fs');
const test = require('tape');
const group = require('tape-plus').group;
const httpDock = require('../../example/docks/http');
const handler = require('../../example/handlers/handler1');
const hook1 = require('../../example/hooks/hook1');
const hook2 = require('../../example/hooks/hook2');

const flows = [
    new Flow('Flow 1', {
        tag: 'tag1',
        docks: [httpDock],
        handler: handler,
        inputHooks: [hook1],
        outputHooks: [hook2]
    }),
    new Flow('Flow 2', {
        tag: 'tag2',
        docks: [httpDock],
        handler: handler,
        inputHooks: [hook1],
        outputHooks: [hook2]
    })
];
const tags = {
    'tag1': {
        flow: flows[0]
    },
    'tag2': {
        flow: flows[1]
    }
};
const config = {
    flows: flows
};

httpDock.config = {
    port: 5000
};

group('dispatcher.tags', (test) => {
    test('gets tags', (t) => {
        dispatcher._tags = tags;
        t.deepEqual(dispatcher.tags, tags);
    });
});

group('dispatcher.config', (test) => {
    const threadPool = {
        test: 'Test',
        run: (data) => {
            return {
                on: (event) => {}
            };
        }
    };

    test('sets dispatcher config', (t) => {
        config.flows[0].docks[0].listen = () => {};
        config.flows[1].docks[0].listen = () => {};

        dispatcher.threadPool = threadPool;
        dispatcher.config = config;
        t.deepEqual(dispatcher._config, config);
    });
});

group('dispatcher.threadPool', (test) => {
    test('sets dispatcher threadpool instance', (t) => {
        const threadPool = {
            test: 'Test'
        };

        dispatcher.threadPool = threadPool;
        t.equal(dispatcher._threadPool, threadPool);
    });
});

group('dispatcher.dispatch()', (test) => {
    const threadPool = {
        test: 'Test',
        send: (data) => {
            return {
                on: () => {}
            };
        }
    };
    const data = {
        tag: 'tag1',
        data: {},
        meta: {}
    };

    test('sends data to threadpool', (t) => {
        var valid = false;

        dispatcher.threadPool = threadPool;
        dispatcher._threadPool.send = (data) => {
            valid = true;

            return {
                on: () => {}
            };
        }
        dispatcher._tags = tags;
        dispatcher.dispatch(data);
        t.equal(valid, true);
    });

    test('adds flow name to metadata', (t) => {
        dispatcher.threadPool = threadPool;
        dispatcher._tags = tags;
        dispatcher.dispatch(data);
        t.equal(data.meta.flow, 'Flow 1');
    });
});

group('dispatcher.respond()', (test) => {
    test('sends response to original dock', (t) => {
        var valid = false;
        const response = {
            message: 'Test',
            meta: {
                dock: 'test'
            },
            tag: 'tag1'
        };

        flows[0].docks[0].reply = (response) => {
            valid = true;
        };
        dispatcher._docks['test'] = flows[0].docks[0];
        dispatcher.respond(response);
        t.equal(valid, true);
    });
});

group('dispatcher._processFlows()', (test) => {
    test('pushes content to tags array', (t) => {
        dispatcher._processFlows(config);
        t.deepEqual(dispatcher.tags, tags)
    });
});

group('dispatcher._generateJob()', (test) => {
    test('generates javascript file', (t) => {
        const fileName = '.iris';

        dispatcher._generateJob(dispatcher.tags, fileName);
        t.equal(Number.isInteger(fs.openSync(fileName, 'r')), true);
    });
});

group('dispatcher._startDock()', (test) => {
    const dock = {
        config: {
            port: 5000
        }
    };
    test('stops docks', (t) => {
        var valid = false;
        dock.stop = () => valid = true;
        dock.listen = () => {};

        dispatcher._startDock(dock);
        t.equal(valid, true);
    });

    test('starts docks', (t) => {
        var valid = false;
        dock.stop = () => {};
        dock.listen = () => valid = true;

        dispatcher._startDock(dock);
        t.equal(valid, true);
    });
});<commit_msg>Added a new dispatcher test<commit_after>'use strict';

const Flow = require('../../lib/Flow');
const dispatcher = require('../../lib/Dispatcher');
const fs = require('graceful-fs');
const test = require('tape');
const group = require('tape-plus').group;
const httpDock = require('../../example/docks/http');
const handler = require('../../example/handlers/handler1');
const hook1 = require('../../example/hooks/hook1');
const hook2 = require('../../example/hooks/hook2');

const flows = [
    new Flow('Flow 1', {
        tag: 'tag1',
        docks: [httpDock],
        handler: handler,
        inputHooks: [hook1],
        outputHooks: [hook2]
    }),
    new Flow('Flow 2', {
        tag: 'tag2',
        docks: [httpDock],
        handler: handler,
        inputHooks: [hook1],
        outputHooks: [hook2]
    })
];
const tags = {
    'tag1': {
        flow: flows[0]
    },
    'tag2': {
        flow: flows[1]
    }
};
const config = {
    flows: flows
};

httpDock.config = {
    port: 5000
};

group('dispatcher.tags', (test) => {
    test('gets tags', (t) => {
        dispatcher._tags = tags;
        t.deepEqual(dispatcher.tags, tags);
    });
});

group('dispatcher.config', (test) => {
    const threadPool = {
        test: 'Test',
        run: (data) => {
            return {
                on: (event) => {}
            };
        }
    };

    test('sets dispatcher config', (t) => {
        config.flows[0].docks[0].listen = () => {};
        config.flows[1].docks[0].listen = () => {};

        dispatcher.threadPool = threadPool;
        dispatcher.config = config;
        t.deepEqual(dispatcher._config, config);
    });
});

group('dispatcher.threadPool', (test) => {
    test('sets dispatcher threadpool instance', (t) => {
        const threadPool = {
            test: 'Test'
        };

        dispatcher.threadPool = threadPool;
        t.equal(dispatcher._threadPool, threadPool);
    });
});

group('dispatcher.dispatch()', (test) => {
    const threadPool = {
        test: 'Test',
        send: (data) => {
            return {
                on: () => {}
            };
        }
    };
    const data = {
        tag: 'tag1',
        data: {},
        meta: {}
    };

    test('sends data to threadpool', (t) => {
        var valid = false;

        dispatcher.threadPool = threadPool;
        dispatcher._threadPool.send = (data) => {
            valid = true;

            return {
                on: () => {}
            };
        }
        dispatcher._tags = tags;
        dispatcher.dispatch(data);
        t.equal(valid, true);
    });

    test('adds flow name to metadata', (t) => {
        dispatcher.threadPool = threadPool;
        dispatcher._tags = tags;
        dispatcher.dispatch(data);
        t.equal(data.meta.flow, 'Flow 1');
    });
});

group('dispatcher.respond()', (test) => {
    test('sends response to original dock', (t) => {
        var valid = false;
        const response = {
            message: 'Test',
            meta: {
                dock: 'test'
            },
            tag: 'tag1'
        };

        flows[0].docks[0].reply = (response) => {
            valid = true;
        };
        dispatcher._docks['test'] = flows[0].docks[0];
        dispatcher.respond(response);
        t.equal(valid, true);
    });
});

group('dispatcher._processFlows()', (test) => {
    test('pushes content to tags array', (t) => {
        dispatcher._processFlows(config);
        t.deepEqual(dispatcher.tags, tags)
    });
});

group('dispatcher._generateJob()', (test) => {
    test('generates javascript file', (t) => {
        const fileName = '.iris';

        dispatcher._generateJob(dispatcher.tags, fileName);
        t.equal(Number.isInteger(fs.openSync(fileName, 'r')), true);
    });
});

group('dispatcher._startDock()', (test) => {
    const dock = {
        config: {
            port: 5000
        }
    };
    test('stops docks', (t) => {
        var valid = false;
        dock.stop = () => valid = true;
        dock.listen = () => {};

        dispatcher._startDock(dock);
        t.equal(valid, true);
    });

    test('starts docks', (t) => {
        var valid = false;
        dock.stop = () => {};
        dock.listen = () => valid = true;

        dispatcher._startDock(dock);
        t.equal(valid, true);
    });
});

group('dispatcher._emitEvent', (test) => {
    test('emits an event', (t) => {
        const config = {
            events: true
        };

        dispatcher._events = {};
        dispatcher._events.emit = function (event, callback) {
            t.pass('Ok');
        }.bind(this);
        dispatcher._emitEvent('test', {});
    });
});<|endoftext|>