process.nextTick(function () {
      assert.equals(j, 10)
      assert.equals(i, 0)

      if(streamEnd) done()
      putEnd = true
    })
Example #2
0
test('clone objects', () => {
  let a = {a: 1, b: 2}
  let b = clone(a)
  b.c = 3
  assert.equals(a, {a: 1, b: 2})
  assert.equals(b, {a: 1, b: 2, c: 3})
})
Example #3
0
test('clone arrays', () => {
  let a = [1, 2, 3]
  let b = clone(a)
  b.push(4)
  assert.equals(a, [1, 2, 3])
  assert.equals(b, [1, 2, 3, 4])
})
Example #4
0
    'test basic add': function (done) {
      var utilMock
        , argsParserMock     = this.mock(argsParser)
        , mainBuildMock
        , parseContextStub   = this.stub()
        , optionsArg         = { options: 1 }
        , filenameArg        = { filename: 1 }
        , contextArg         = { options: { contextOptions: 1 } }
        , extendedOptionsArg = { extendedOptions: 1 }
        , outArg             = { out: 1 }

      requireSubvert.subvert('../../lib/parse-context', parseContextStub)
      parseContextStub.callsArgWith(1, null, contextArg)
      util          = require('../../lib/util')
      mainBuild     = require('../../lib/main-build')
      utilMock      = this.mock(util)
      mainBuildMock = this.mock(mainBuild)
      mainAdd       = requireSubvert.require('../../lib/main-add')

      utilMock.expects('getInputFilenameFromOptions').once().withExactArgs(optionsArg).returns(filenameArg)
      argsParserMock.expects('extend').once().withExactArgs(contextArg.options, optionsArg).returns(extendedOptionsArg)
      mainBuildMock.expects('exec').once().withExactArgs(extendedOptionsArg, outArg, done).callsArg(2)

      mainAdd.exec(optionsArg, outArg, done)

      assert.equals(parseContextStub.callCount, 1)
      assert.equals(parseContextStub.getCall(0).args.length, 2)
      assert.equals(parseContextStub.getCall(0).args[0], filenameArg)
    }
Example #5
0
 parseContext(filename, function (err, data) {
   refute(err)
   assert(data)
   assert.equals(data.options, expectedOptions)
   assert.equals(data.packages, expectedPackages)
   done()
 })
 data.forEach(function (d, i) {
   var call = this.dataSpy.getCall(i)
   if (call) {
     //console.log('call', i, ':', call.args[0].key, '=', call.args[0].value, '(expected', d.key, '=', d.value, ')')
     assert.equals(call.args.length, 1, 'Stream "data" event #' + i + ' fired with 1 argument')
     assert.equals(+call.args[0].toString(), +d, 'Stream correct "data" event #' + i + ': ' + d)
   }
 }.bind(this))
Example #7
0
  Then(/^the resource-list route is rendered$/, function (done) {
    const $ = cheerio.load(this.getResponseBody());
    const $resources = $('ul.list-group');

    assert.equals($resources.length, 1);
    assert.equals($resources.find('li').length, this.resourceCount);

    done();
  });
Example #8
0
test('#match matches a path against the routes', () => {
  router.map(routes)
  let match = router.match('/application/KidkArolis/status/42')
  assert.equals(match.params, {
    user: '******',
    id: '42'
  })
  assert.equals(_.pluck(match.routes, 'name'), ['application', 'status'])
})
 .on('close', function () {
   assert.equals(entries, expected, 'correct entries')
   assert.equals(
       md._store['$foo'].keys
     , expected.map(function (e) { return e.key })
     , 'memdown has the entries'
   )
   done()
 })
Example #10
0
   requireSubvert.require('../lib/minify').minify(parsedArgs, sourceArg, function (err, result) {
   refute(err)
   assert.same(result, resultArg)
   assert.equals(enderMinifyStub.callCount, 1)
   assert.equals(enderMinifyStub.getCall(0).args.length, 4)
   assert.equals(enderMinifyStub.getCall(0).args[0], minifier)
   assert.same(enderMinifyStub.getCall(0).args[1], sourceArg)
   assert.equals(enderMinifyStub.getCall(0).args[2], expectedOptions)
   done()
 }.bind(this))
Example #11
0
 parseContext(filename, function (err, options, packages) {
   assert(err)
   refute(options)
   refute(packages)
   assert.equals(err.name, 'BuildParseError')
   assert(err.cause)
   assert(err.cause instanceof argsParser.UnknownMainError)
   assert.equals(err.cause.name, 'UnknownMainError')
   done()
 })
Example #12
0
test('extend', () => {
  assert.equals(extend({}, {a: 1, b: 2}, null, {c: 3}), {a: 1, b: 2, c: 3})

  let obj = {d: 4}
  let target = {}
  extend(target, obj)
  target.a = 1
  obj.b = 2
  assert.equals(obj, {b: 2, d: 4})
  assert.equals(target, {a: 1, d: 4})
})
Example #13
0
  Then(/^the primary nav is rendered$/, function (done) {
    const $ = cheerio.load(this.getResponseBody());
    const $primaryNav = $('#wrap').find('ul.navbar-nav');
    const expectedLinkCount = this.availableResourceTypes.length + Object.keys(this.apiResponseLinks).length;

    assert.equals($primaryNav.length, 1);
    assert.greater(expectedLinkCount, 0);
    assert.equals(expectedLinkCount, $primaryNav.find('> li').length);

    done();
  });
Example #14
0
test('#transitionTo called on an abstract route with a child index route should activate the index route', async () => {
  router.map((route) => {
    route('foo', {abstract: true}, () => {
      route('bar', {path: ''})
    })
  }).listen()
  await router.transitionTo('foo')
  assert.equals(router.isActive('foo'), true)
  assert.equals(router.isActive('bar'), true)
  assert.equals(router.state.routes.length, 2)
  assert.equals(router.state.path, '/foo')
})
Example #15
0
test('#match matches a path with query params', () => {
  router.map(routes)
  let match = router.match('/application/KidkArolis/status/42?withReplies=true&foo=bar')
  assert.equals(match.params, {
    user: '******',
    id: '42'
  })
  assert.equals(match.query, {
    withReplies: 'true',
    foo: 'bar'
  })
})
 this.verify = delayed(function (rs, data, done) {
   assert.equals(this.endSpy.callCount, 1, 'Stream emitted single "end" event')
   assert.equals(this.dataSpy.callCount, data.length, 'Stream emitted correct number of "data" events')
   data.forEach(function (d, i) {
     var call = this.dataSpy.getCall(i)
     if (call) {
       //console.log('call', i, ':', call.args[0].key, '=', call.args[0].value, '(expected', d.key, '=', d.value, ')')
       assert.equals(call.args.length, 1, 'Stream "data" event #' + i + ' fired with 1 argument')
       assert.equals(+call.args[0].toString(), +d, 'Stream correct "data" event #' + i + ': ' + d)
     }
   }.bind(this))
   done()
 }, 0.05, this)
Example #17
0
test('#map registers the routes', () => {
  router.map(routes)
  // check that the internal matchers object is created
  assert.equals(_.pluck(router.matchers, 'path'), [
    '/application',
    '/application/notifications',
    '/application/messages',
    '/application/:user/status/:id'
  ])
  // check that the internal routes object is created
  assert.equals(router.routes[0].name, 'application')
  assert.equals(router.routes[0].routes[3].options.path, ':user/status/:id')
})
Example #18
0
    it('should return false when unsuccesful', function(){
        var unknownToken = 'my unknown token',
            result = PubSub.unsubscribe( unknownToken ),
            func = function(){ return undefined; },
            message = TestHelper.getUniqueString(),
            token = PubSub.subscribe( message, func );

        // first, let's try a completely unknown token
        assert.equals( result, false );

        // now let's try unsubscribing the same method twice
        PubSub.unsubscribe( token );
        assert.equals( PubSub.unsubscribe( token ), false );
    });
Example #19
0
        levelup(location, function (err, db) { // no options object
          refute(err)
          assert.isObject(db)
          assert.isTrue(db.options.createIfMissing)
          assert.isFalse(db.options.errorIfExists)
          assert.equals(db.options.keyEncoding, 'utf8')
          assert.equals(db.options.valueEncoding, 'utf8')
          assert.equals(db.location, location)

            // read-only properties
          db.location = 'foo'
          assert.equals(db.location, location)

          done()
        })
Example #20
0
  let m = (transition) => {
    let t = _.omit(transition, ['catch', 'then', 'cancel', 'retry', 'followRedirects'])
    let et = {
      id: 3,
      prev: {
        routes: [{
          name: 'application',
          path: 'application',
          paramNames: [],
          options: {
            path: 'application'
          },
          ancestors: []
        }, {
          name: 'home',
          path: '',
          paramNames: [],
          options: {
            path: ''
          },
          ancestors: ['application']
        }],
        path: '/application',
        pathname: '/application',
        params: {},
        query: {}
      },
      routes: [{
        name: 'application',
        path: 'application',
        paramNames: [],
        options: {
          path: 'application'
        },
        ancestors: []
      }, {
        name: 'status',
        path: ':user/status/:id',
        paramNames: ['user', 'id'],
        options: {
          path: ':user/status/:id'
        },
        ancestors: [
          'application'
        ]
      }],
      path: '/application/1/status/2?withReplies=true',
      pathname: '/application/1/status/2',
      params: {
        user: '******',
        id: '2'
      },
      query: {
        withReplies: 'true'
      }
    }
    assert.equals(t, et)

    done()
  }
Example #21
0
 test('#generate when pushState: true and root != "/" in modern browsers', () => {
   router.options.pushState = true
   router.options.root = '/foo/bar'
   router.map(routes).listen()
   var url = router.generate('status', {user: '******', id: 1}, {withReplies: true})
   assert.equals(url, '/foo/bar/application/usr/status/1?withReplies=true')
 })
Example #22
0
  Then(/^the "([^"]*)" page should be displayed$/, function (statusCode, done) {
    const $ = cheerio.load(this.getResponseBody());

    assert.equals($('h2').text(), statusCode);

    done();
  });
Example #23
0
test('a complex route map', () => {
  router.map((route) => {
    route('application', () => {
      route('home', {path: ''})
      route('notifications')
      route('messages', () => {
        route('unread', () => {
          route('priority')
        })
        route('read')
        route('draft', () => {
          route('recent')
        })
      })
      route('status', {path: ':user/status/:id'})
    })
    route('anotherTopLevel', () => {
      route('withChildren')
    })
  })
  // check that the internal matchers object is created
  assert.equals(_.pluck(router.matchers, 'path'), [
    '/application',
    '/application/notifications',
    '/application/messages/unread/priority',
    '/application/messages/read',
    '/application/messages/draft/recent',
    '/application/:user/status/:id',
    '/anotherTopLevel/withChildren'
  ])
})
Example #24
0
test('a parent route can be excluded from the route map by setting abstract to true', () => {
  router.map((route) => {
    route('application', { abstract: true }, () => {
      route('notifications')
      route('messages', () => {
        route('unread', () => {
          route('priority')
        })
        route('read')
        route('draft', { abstract: true }, () => {
          route('recent')
        })
      })
      route('status', {path: ':user/status/:id'})
    })
    route('anotherTopLevel', () => {
      route('withChildren')
    })
  })

  assert.equals(router.matchers.map(m => m.path), [
    '/application/notifications',
    '/application/messages',
    '/application/messages/unread',
    '/application/messages/unread/priority',
    '/application/messages/read',
    '/application/messages/draft/recent',
    '/application/:user/status/:id',
    '/anotherTopLevel',
    '/anotherTopLevel/withChildren'
  ])
})
Example #25
0
test('modifying params or query in middleware does not affect the router state', async function () {
  router.map(routes)
  await router.listen()
  router.use(transition => {
    transition.params.foo = 1
    transition.query.bar = 2
    transition.routes.push({})
    transition.routes[0].foobar = 123
  })
  await router.transitionTo('status', {user: '******', id: 42}, {q: 'abc'})
  // none of the modifications to params, query or routes
  // array are persisted to the router state
  assert.equals(router.state.params, {user: '******', id: '42'})
  assert.equals(router.state.query, {q: 'abc'})
  assert.equals(router.state.routes.length, 2)
})
Example #26
0
        it("is matcher", function () {
            var numberOrString = sinonMatch.number.or(sinonMatch.string);

            assert(sinonMatch.isMatcher(numberOrString));
            assert.equals(numberOrString.toString(),
                          "typeOf(\"number\").or(typeOf(\"string\"))");
        });
Example #27
0
        it("will coerce to matcher", function () {
            var abcOrObj = sinonMatch("abc").or({a: 1});

            assert(sinonMatch.isMatcher(abcOrObj));
            assert.equals(abcOrObj.toString(),
                          "match(\"abc\").or(match(a: 1))");
        });
Example #28
0
        it("will coerce argument to matcher", function () {
            var abcOrDef = sinonMatch("abc").or("def");

            assert(sinonMatch.isMatcher(abcOrDef));
            assert.equals(abcOrDef.toString(),
                          "match(\"abc\").or(match(\"def\"))");
        });
Example #29
0
 this.openTestDatabase(function (db) {
   var batch = db.batch()
     .put('one', '1')
     .del('two')
     .put('three', '3')
   assert.equals(batch.length, 3)
   batch.clear()
   assert.equals(batch.length, 0)
   batch
     .del('1')
     .put('2', 'two')
     .put('3', 'three')
     .del('3')
   assert.equals(batch.length, 4)
   done()
 })
Example #30
0
test('#match returns an array of route descriptors', () => {
  router.map((route) => {
    route('foo', {customData: 1}, () => {
      route('bar', {customData: 2})
    })
  })
  let match = router.match('/foo/bar')
  assert.equals(match.routes, [{
    name: 'foo',
    path: 'foo',
    paramNames: [],
    options: {
      customData: 1,
      path: 'foo'
    },
    ancestors: []
  }, {
    name: 'bar',
    path: 'bar',
    paramNames: [],
    options: {
      customData: 2,
      path: 'bar'
    },
    ancestors: ['foo']
  }])
})