Exemplo n.º 1
0
				}).exec(function (error, results) {

					if (!error) {
						// Ensure our optional $meta expression has added a value.
						// Each result should have a 'score'
						_.each(results.results, function (result) {
							var score = result.get('score');
							assert.notEqual(score, undefined);
						});

						// Ensure our paginated result set works as expected
						assert.equal(results.currentPage, pageNumber);
						assert.equal(results.totalPages, searchTestData.expectedPages.length);
						assert.deepStrictEqual(results.pages, searchTestData.expectedPages);

						if (_.first(searchTestData.expectedPages) === pageNumber) {
							assert(!results.previous);
							assert(results.next);
						}
						else if (_.last(searchTestData.expectedPages) === pageNumber) {
							assert(results.previous);
							assert(!results.next);
						}
						else {
							assert(results.previous);
							assert(results.next);
						}

						assert(results.results.length <= searchTestData.perPage);
					}
					callback(error);
				});
Exemplo n.º 2
0
				}).exec(function (error, results) {
					if (!error) {
						assert.equal(results.currentPage, pageNumber);
						assert.equal(results.totalPages, regressionTestData.expectedPages.length);
						assert.deepStrictEqual(results.pages, regressionTestData.expectedPages);

						// If we're on the first page of results, test that there is no
						// `previous` page to go back to.
						//
						// If it's the last page, test that there is no `next`.
						//
						// Otherwise test that there are both `previous` and `next`
						// pages to go to.
						if (_.first(regressionTestData.expectedPages) === pageNumber) {
							assert(!results.previous);
							assert(results.next);
						}
						else if (_.last(regressionTestData.expectedPages) === pageNumber) {
							assert(results.previous);
							assert(!results.next);
						}
						else {
							assert(results.previous);
							assert(results.next);
						}

						// Ensure we don't have more results per page than we
						// defined.
						assert(results.results.length <= regressionTestData.perPage);
					}
					callback(error);
				});
  helper.run('test/fixtures/nested-test.js#sub', function (er, result, log) {
    assert.equal(result, true)
    log.assert(
      'TAP version 13',
      '1..2',
      'ok 1 - "sub test2" - test #1 in `test/fixtures/nested-test.js`',
      'ok 2 - "sub test3" - test #2 in `test/fixtures/nested-test.js`'
    )

    // Make sure all the hooks ran as expected
    assert.deepEqual(global.__results, [
      'A', // top beforeAll
      'D', //   sub beforeAll
      'B', // top beforeEach
      'E', //   sub beforeEach
      'F', //   "sub test 2"
      'H', //   sub afterEach
      'J', // top afterEach
      'B', // top beforeEach
      'E', //   sub beforeEach
      'G', //   "sub test 3"
      'H', //   sub afterEach
      'J', // top afterEach
      'I', //   sub afterAll
      'K' // top afterAll
    ])
    delete global.__results
    cb(er)
  })
Exemplo n.º 4
0
 helper.run('test/fixtures/async-*.js', function (er, result, log) {
   assert.equal(result, false)
   log.assert(
     'TAP version 13',
     '1..6',
     ' An error occurred in test hook: "module beforeAll" defined in `test/fixtures/async-beforeAll-fails-all.js`',
     '  ---',
     '  message: nope',
     /stacktrace: Error: nope/,
     '  ...',
     'not ok 1 - "test1" - test #1 in `test/fixtures/async-beforeAll-fails-all.js` [SKIPPED]',
     'not ok 2 - "test2" - test #2 in `test/fixtures/async-beforeAll-fails-all.js` [SKIPPED]',
     'not ok 3 - test #1 in `test/fixtures/async-error-test.js`',
     '  ---',
     '  message: Something bad',
     /stacktrace: Error: Something bad/,
     '  ...',
     'not ok 4 - test #1 in `test/fixtures/async-fail-test.js`',
     '  ---',
     '  message: 98 == 42',
     /stacktrace: AssertionError: 98 == 42/,
     '  ...',
     'ok 5 - "firstTest" - test #1 in `test/fixtures/async-good-test.js`',
     'ok 6 - "secondTest" - test #2 in `test/fixtures/async-good-test.js`'
   )
   cb(er)
 })
 helper.run('test/fixtures/single-named-func.js:123', function (er, result, log) {
   assert.equal(result, true)
   log.assert(
     'TAP version 13',
     '1..0'
   )
   cb(er)
 })
 helper.run('test/fixtures/single-named-func.js:2', function (er, result, log) {
   assert.equal(result, true)
   log.assert(
     'TAP version 13',
     '1..1',
     'ok 1 - "pop" - test #1 in `test/fixtures/single-named-func.js`'
   )
   cb(er)
 })
Exemplo n.º 7
0
 helper.run('test/fixtures/context-*.js', function (er, result, log) {
   assert.equal(result, true)
   log.assert(
     'TAP version 13',
     '1..2',
     'ok 1 - "test1" - test #1 in `test/fixtures/context-test.js`',
     'ok 2 - "test2" - test #2 in `test/fixtures/context-test.js`'
   )
   cb(er)
 })
Exemplo n.º 8
0
  registeringNamelessPlugin: function (cb) {
    store.initialize()

    try {
      teenytest.plugins.register({})
      return cb(new Error('expected an error to be thrown'))
    } catch (e) {
      assert.equal(e.message, 'Plugins are required to have a "name" attribute.')
      return cb(null)
    }
  }
Exemplo n.º 9
0
  registeringSameNameDifferentPluginThrowsError: function (cb) {
    store.initialize()

    teenytest.plugins.register(somePlugin)
    try {
      teenytest.plugins.register(someOtherPlugin)
      return cb(new Error('expected an error to be thrown'))
    } catch (e) {
      assert.equal(e.message, 'A different plugin named "some-plugin" is ' +
                              'already registered. First unregister it with ' +
                              '`teenytest.plugins.unregister("some-plugin"))`.')
      return cb(null)
    }
  },
module.exports = function (cb) {
  var error
  try {
    teenytest.plugins.register({name: 'lol'})
  } catch (e) {
    error = e
  }

  assert.equal(error.message,
    'A teenytest run has not been properly kicked off yet, so plugins cannot ' +
    'be registered. Consider registering the plugin via the `--plugin` CLI, a ' +
    '`teenytest.plugins` property in your package.json, or via a `configurator` ' +
    'function. See the teenytest README.md for more information on registering ' +
    'plugins.')

  cb(null)
}
 }, function (er, result, log) {
   assert.equal(result, false)
   log.assert(
     'TAP version 13',
     '1..2',
     'ok 1 - "bar" - test #1 in `test/fixtures/basic-test-passing-object.js`',
     'ok 2 - "baz" - test #2 in `test/fixtures/basic-test-passing-object.js`',
     / An error occurred in suite: /,
     '  ---',
     '  message: lol',
     /stacktrace: Error: lol/,
     '  ...',
     ' An error occurred in suite: "global" in `test/fixtures/basic-test-passing-obj*.js`',
     '  ---',
     '  message: lol',
     /stacktrace: Error: lol/,
     '  ...'
   )
   cb(er)
 })
Exemplo n.º 12
0
 subtracts: function () { assert.equal(4 - 2, 2) },
Exemplo n.º 13
0
 _.defer(function () {
   assert.equal(98, 42)
   done()
 })
Exemplo n.º 14
0
 subtract: function () {
   assert.equal(5, 11 - 6)
 }
Exemplo n.º 15
0
 add: function () {
   assert.equal(5, 3 + 2)
 },
Exemplo n.º 16
0
 adds: function () { assert.equal(1 + 1, 2) },
Exemplo n.º 17
0
 pendingButDone: function () {
   assert.equal(4, 2 + 2)
 }