var crypto = require('crypto')
var test = require('tape')
var secretBox = require('../')

test('encrypt / decrypt', function (t) {
  t.plan(1)

  const passphrase = 'open sesame'
  const message = new Buffer('The secret launch code is 1234.')

  const message2 = secretBox.decrypt(secretBox.encrypt(message, passphrase), passphrase)
  t.is(message.toString('hex'), message2.toString('hex'), 'encrypt / decrypt message')

  t.end()
})

test('encrypt / decrypt (buffer phassphrase)', function (t) {
  t.plan(1)

  const passphrase = new Buffer('open sesame 2')
  const message = new Buffer('The secret launch code is 1234.')

  const message2 = secretBox.decrypt(secretBox.encrypt(message, passphrase), passphrase)
  t.is(message.toString('hex'), message2.toString('hex'), 'encrypt / decrypt message')

  t.end()
})

test('encrypt / decrypt (tune up N in scrypt)', function (t) {
  t.plan(2)
  console.time('scrypt-n')
Exemple #2
0
test("hittest", function (t) {
    var hit = hittest({ x: 10, y: 10, width: 1, height: 1 });

    t.test("left miss", function (t) {
        t.plan(3);
        t.notOk(hit({ x: 1, y: 10, width: 1, height: 1 }));
        t.notOk(hit({ x: 9, y: 10, width: 1, height: 1 }));
        t.notOk(hit({ x: 5, y: 10, width: 5, height: 1 }));
    });

    t.test("right miss", function (t) {
        t.plan(3);
        t.notOk(hit({ x: 11, y: 10, width: 1, height: 1 }));
        t.notOk(hit({ x: 15, y: 10, width: 1, height: 1 }));
        t.notOk(hit({ x: 11, y: 10, width: 5, height: 1 }));
    });

    t.test("above miss", function (t) {
        t.plan(3);
        t.notOk(hit({ x: 10, y: 9, width: 1, height: 1 }));
        t.notOk(hit({ x: 10, y: 5, width: 1, height: 5 }));
        t.notOk(hit({ x: 10, y: 1, width: 5, height: 1 }));
    });

    t.test("below miss", function (t) {
        t.plan(3);
        t.notOk(hit({ x: 10, y: 11, width: 1, height: 1 }));
        t.notOk(hit({ x: 10, y: 11, width: 1, height: 5 }));
        t.notOk(hit({ x: 10, y: 21, width: 5, height: 1 }));
    });

    t.test("hit", function (t) {
        t.plan(3);
        t.ok(hit({ x: 10, y: 10, width: 1, height: 1 }));
        t.ok(hit({ x: 9, y: 10, width: 3, height: 1 }));
        t.ok(hit({ x: 10, y: 5, width: 3, height: 6 }));
    });
});
Exemple #3
0
import { event as eventFixtures } from './fixtures.js';
import * as genericFixtures from '../../utils/fixtures.js';

/********
GET EVENT ACTIONS
********/

test('getEvent async action creator returns expected action', (t) => {

    let actual;
    const { dispatch, queue } = createThunk();
    let eventID = 'event:100';
    dispatch(getEvent(eventID));

    [{ ...actual }] = queue;

    const expected = {
        type: GET_EVENT_REQUEST,
        isFetching: true
    };

    t.deepEqual(actual, expected, "getEvent returns GET_EVENT_REQUEST action");
    t.end();
});

test('getEventRequest action creator returns expected action', (t) => {

    const expected = {
        type: GET_EVENT_REQUEST,
        isFetching: true
    };
Exemple #4
0
test('ut_metadata transfer', function (t) {
  t.plan(5)

  var client1 = new WebTorrent({ dht: false, trackers: false })
  var client2 = new WebTorrent({ dht: false, trackers: false })

  client1.on('torrent', function (torrent) {
    t.pass('client1 emits torrent event') // even though it started with metadata
  })

  // client1 starts with metadata from torrent file
  client1.add(leaves)

  client1.on('error', function (err) { t.fail(err) })
  client2.on('error', function (err) { t.fail(err) })

  client1.on('torrent', function (torrent1) {
    t.deepEqual(torrent1.parsedTorrent.info, leavesTorrent.info)

    // client2 starts with infohash
    client2.add(leavesTorrent.infoHash)

    client2.on('listening', function (port, torrent2) {
      // manually add the peer
      torrent2.addPeer('127.0.0.1:' + client1.torrentPort)

      client2.on('torrent', function () {
        t.deepEqual(torrent1.parsedTorrent.info, torrent2.parsedTorrent.info)

        client1.destroy(function () {
          t.pass('client1 destroyed')
        })
        client2.destroy(function () {
          t.pass('client2 destroyed')
        })
      })
    })
  })
})
import test from "tape"
import format from "../../../src/format"

test("cardsy.format.number should convert ints to strings", assert => {
    //Arrange
    let formattedNumber
    const unformattedNumber = 42

    //Act
    formattedNumber = format.number(unformattedNumber)

    //Assert
    assert.equal(formattedNumber, "42", "Returns a string when an int is passed")

    assert.end()
})
Exemple #6
0
import { mount } from 'enzyme';
import React from 'react';
import test from 'tape';
import App from '../src/App';

test('App mounts', t => {
  t.plan(1);
  const app = mount(<App />);
  t.equal(app.find('h1').text(), 'App');
});

Exemple #7
0
function resolveSimple (assert) {
  const pkgs = ['foo']
  const opts = { basedir: __dirname + '/fixtures/simple' }
  resolve.packages(pkgs, opts, assert)
}

test('find', function (t) {
  t.plan(10)

  resolveSimple(function assert (err, deps) {
    t.equal(err, null)
    t.equal(deps.length, 1)

    const foo = deps.shift()
    t.equal(foo.name, 'foo')
    t.equal(typeof foo.manifest, 'string')
    t.equal(typeof foo.basedir, 'string')
    t.equal(typeof foo.main, 'string')
    t.equal(typeof foo.root, 'string')

    t.equal(foo.meta.name, 'foo')
    t.equal(typeof foo.meta.dependencies, 'object')
    t.equal(foo.dependencies.length, 3)
  })
})

test('manifest', function (t) {
  t.plan(10)

  const manifest = require(__dirname + '/fixtures/simple/package.json')
  const opts = { basedir: __dirname + '/fixtures/simple' }
var eslint = require('eslint')
var test = require('tape')
var path = require('path')

var linter = new eslint.CLIEngine({
  configFile: path.join(__dirname, '..', 'eslintrc.json')
})

test('api: lintText', function (t) {
  t.plan(1)
  var result = linter.executeOnText("console.log('hi there')\n\n")
  t.equals(result.results[0].messages[0].message, 'Missing semicolon.')
})
);

test('Voronoi: Basic Chart', t => {
  const $ = mount(<StatelessVoronoiWrapper />);

  t.equal(
    $.find('.rv-voronoi__cell')
      .at(30)
      .prop('style').color,
    'red',
    'should apply inline styles'
  );
  t.equal(
    $.find('.rv-voronoi__cell')
      .at(30)
      .hasClass('my-class-30'),
    true,
    'should apply css class'
  );
  t.equal(
    $.find('.rv-voronoi__cell')
      .at(50)
      .hasClass('my-class-50'),
    true,
    'should apply css class'
  );

  t.end();
});

test('Voronoi: Showcase Example - VoronoiLineChart', t => {
Exemple #10
0
    res.render('test', { hello : 'world' });
});

function checkMinified(t) {
    request(app)
        .get('/test')
        .expect(200)
        .end(function (err, res) {
            t.equal(res.text, expectedHTML);
            t.end();
        });
};

test('Should minify EJS templates', function (t) {
    app.set('view engine', 'ejs');

    checkMinified(t);
});

test('Should minify Jade templates', function (t) {
    app.set('view engine', 'jade');

    checkMinified(t);
});

test('Should minify Handlebars templates', function (t) {
    app.set('view engine', 'handlebars');

    checkMinified(t);
});
Exemple #11
0
var copy = require('../');
var test = require('tape');

test('array', function (t) {
    t.plan(2);

    var xs = [ 3, 4, 5, { f: 6, g: 7 } ];
    var dup = copy(xs);
    dup.unshift(1, 2);
    dup[5].g += 100;

    t.deepEqual(xs, [ 3, 4, 5, { f: 6, g: 107 } ]);
    t.deepEqual(dup, [ 1, 2, 3, 4, 5, { f: 6, g: 107 } ]);
});
Exemple #12
0
var os = require( 'os' );
var path = require( 'path' );

var test = require( 'tape' );
var level = require( 'level' );
var levelPromisify = require( '../dist' );

var dbpath = path.join( os.tmpdir(), 'level-promisify-' + Math.random() );


test( 'creation', function( t ) {
    t.plan( 1 );

    var rootdb = level( dbpath );
    try {
        var db = levelPromisify( rootdb );
        t.ok( true, 'Sync create ok' );
    } catch( err ) {
        t.fail( err );
    }

    t.on( 'end', function() {
        if ( db ) {
            db.close();
        }
    });

});
test('setup', function (t) {
    vasync.pipeline({
        'funcs': [
            function createUFDS(_, cb) {
                helper.createServer(function (err, ufds) {
                    if (err) {
                        return cb(err);
                    }
                    t.ok(ufds);
                    UFDS_SERVER = ufds;
                    cb();
                });
            },
            function createServer(_, cb) {
                helper.createCAPIServer(function (err, server) {
                    if (err) {
                        return cb(err);
                    }
                    t.ok(server);
                    SERVER = server;
                    cb();
                });
            },
            function createClient(_, cb) {
                helper.createCAPIClient(function (client) {
                    t.ok(client);
                    CAPI = client;
                    cb();
                });
            }
        ]
    }, function (err, result) {
        if (err) {
            t.ifError(err);
            // Fail hard if startup isn't successful
            process.exit(1);
        }
        t.end();
    });
});
// npm
var test = require('tape');
var nock = require('nock');

// local
var createVerify = require('../browserid-verify.js');

// ----------------------------------------------------------------------------

test('test we accept a https: protocol for the url', function(t) {
    t.plan(1);

    try {
        createVerify({ url : 'https://example.com/' })
        t.pass('We did not throw an error on the https: protocol');
    }
    catch (e) {
        console.log(e);
    }
});

test('test we accept a http: protocol for the url', function(t) {
    t.plan(1);

    try {
        createVerify({ url : 'http://example.com/' })
        t.pass('We did not throw an error on the https: protocol');
    }
    catch (e) {
        console.log(e);
Exemple #15
0
'use strict';

var fs = require('fs');
var test = require('tape');
var scribble = require('../dest/index');

test('Scribbletune::midi', function(t) {
	var fileExists = false;
	scribble.midi(scribble.clip());

	fs.access('./music.mid', fs.F_OK, function(err) {
		if (!err) {
			fileExists = true;
		}
		t.equal(fileExists, true, 'Scribbletune renders a midi file');
		t.end();
	});
});
'use strict';

var test = require('tape');
var template = require('../lib/template');

var examplePaths = require('./fixtures/template/examplePaths');
var expected = require('./fixtures/template/expected');

test('template: can load', function (t) {
  t.plan(1);
  t.ok(template, 'it should be requireable');
});

test('template: works as expected', function (t) {
  t.plan(2);
  template(examplePaths, function (err, data) {
    t.notok(err, 'it should return without an error');
    t.deepEqual(data, expected, 'it should return the expected output');
  });
});
import test from 'tape';
import request from 'supertest';
import keystone from 'test/helpers/keystone';

const app = keystone.app;
const route = '/';

test(`GET ${ route }`, assert => {
  assert.test(route, assert => {
    const msg = 'should not return an error';

    request(app)
      .get(route)
      .expect(200)
      .end(err => {
        assert.error(err, msg);
        assert.end();
      });
  });
});
Exemple #18
0
test('validate react prop order', (t) => {
  t.test('make sure our eslintrc has React and JSX linting dependencies', (t) => {
    t.plan(2);
    t.deepEqual(reactRules.plugins, ['react']);
    t.deepEqual(reactA11yRules.plugins, ['jsx-a11y', 'react']);
  });

  t.test('passes a good component', (t) => {
    t.plan(3);
    const result = lint(wrapComponent(`
  componentWillMount() {}
  componentDidMount() {}
  setFoo() {}
  getFoo() {}
  setBar() {}
  someMethod() {}
  renderDogs() {}
  render() { return <div />; }
`));

    t.notOk(result.warningCount, 'no warnings');
    t.notOk(result.errorCount, 'no errors');
    t.deepEquals(result.messages, [], 'no messages in results');
  });

  t.test('order: when random method is first', t => {
    t.plan(2);
    const result = lint(wrapComponent(`
  someMethod() {}
  componentWillMount() {}
  componentDidMount() {}
  setFoo() {}
  getFoo() {}
  setBar() {}
  renderDogs() {}
  render() { return <div />; }
`));

    t.ok(result.errorCount, 'fails');
    t.equal(result.messages[0].ruleId, 'react/sort-comp', 'fails due to sort');
  });

  t.test('order: when random method after lifecycle methods', t => {
    t.plan(2);
    const result = lint(wrapComponent(`
  componentWillMount() {}
  componentDidMount() {}
  someMethod() {}
  setFoo() {}
  getFoo() {}
  setBar() {}
  renderDogs() {}
  render() { return <div />; }
`));

    t.ok(result.errorCount, 'fails');
    t.equal(result.messages[0].ruleId, 'react/sort-comp', 'fails due to sort');
  });
});
Exemple #19
0
const test = require('tape');
const routes = require('./routes')();

test('it returns a simple route', (t) => {
  t.equal(routes.home(), '/');
  t.end();
});

test('it creates a route with vars', (t) => {
  t.equal(routes.configure(), '/elections/:id/configure');
  t.end();
});

test('it replaces route vars', (t) => {
  t.equal(routes.configure({id : 7}), '/elections/7/configure');
  t.end();
});

test('it throws an error if a path var is not defined', (t) => {
  t.throws(() => {
    routes.configure({})
  });
  t.end();
});
Exemple #20
0
  height: 300,
  showLabels: true,
  width: 400
};
// make sure that the components render at all
testRenderWithProps(RadialChart, RADIAL_PROPS);

test('RadialChart: Basic rendering', t => {
  const $ = mount(<RadialChart {...RADIAL_PROPS}/>);
  const pieSlices = $.find('.rv-radial-chart__series--pie__slice').length;
  t.equal(pieSlices, RADIAL_PROPS.data.length, 'should find the same number of slices as data entries');
  t.equal($.find('.rv-radial-chart__series--pie__slice').at(0).prop('className'), 'rv-xy-plot__series rv-xy-plot__series--arc-path rv-radial-chart__series--pie__slice custom-class', 'should have custom class if defined in data entry');

  const labels = $.find('.rv-xy-plot__series--label-text').length;
  t.equal(labels, RADIAL_PROPS.data.length, 'should find the right number of label wrappers');
  t.equal($.text(), 'yellow againmagentacyanyellowgreen', 'should find appropriate text');

  $.setProps({data: []});
  t.equal($.find('.rv-radial-chart__series--pie__slice').length, 0, 'should find no slives');
  t.equal($.find('.rv-radial-chart__series--pie__slice-overlay').length, 0, 'should find no overlay slices');
  t.equal($.find('.rv-xy-plot__series--label-text').length, 0, 'should find no labels');
  t.equal($.text(), '', 'should find no text');
  t.end();
});

test('RadialChart: Showcase Example - Simple Radial Chart Example', t => {
  const $ = mount(<SimpleRadialChart />);
  t.equal($.find('.rv-radial-chart__series--pie__slice').length, 5, 'should find the same number of slices as data entries');
  t.equal($.find('.rv-xy-plot__series--label-text').length, 5, 'should find the right number of label wrappers');
  t.equal($.text(), 'yellow againmagentacyanyellowgreen', 'should find appropriate text');
  t.end();
import test from 'tape';
import React from 'react/addons';
import Hello from '../Hello';

const TestUtils = React.addons.TestUtils;

// http://simonsmith.io/unit-testing-react-components-without-a-dom/
var createComponent = function (component, props = {}, ...children) {
  const renderer = TestUtils.createRenderer();
  renderer.render(React.createElement(component, props, children.length > 1 ? children : children[0]));
  return renderer.getRenderOutput();
};


test('Components:Hello', t => {

  t.plan(1);

  let component = createComponent(Hello),
    expected = React.DOM.h1({}, 'Hello Mumm!!');

  t.deepEqual(component.props.children, expected);
});
Exemple #22
0
var test = require('tape');
var idw = require('./');
var fs = require('fs');

test('idw', function (t) {
  var testPoints = JSON.parse(fs.readFileSync('./data/data.geojson'));

  var idw1 = idw(testPoints,'value' , 0.5 , 1, 'kilometers');
  var idw2 = idw(testPoints,'value', 0.5 ,0.5, 'kilometers');
  var idw3 = idw(testPoints,'value', 2 , 1, 'miles');
  var idw4 = idw(testPoints, 'WRONGDataField', 0.5, 1, 'miles');

  t.ok(idw1.features.length);
  t.ok(idw2.features.length);
  t.ok(idw3.features.length);
  t.error(idw4);

  if (process.env.UPDATE) {
    fs.writeFileSync(__dirname+'/tests/idw1.geojson', JSON.stringify(idw1,null,2));
    fs.writeFileSync(__dirname+'/tests/idw2.geojson', JSON.stringify(idw2,null,2));
    fs.writeFileSync(__dirname+'/tests/idw3.geojson', JSON.stringify(idw3,null,2));
  }

  t.end();
});
var proxyquire = require('proxyquire');
var test = require('tape');
var ko = require('./lib/knockout');
var common = require('./common.js');

proxyquire('../', {knockout: ko});

test('filters an array’s initial contents', function (t) {
    t.plan(1);

    var a = ko.observableArray(common.orderedInts.slice(0));
    var b = a.filter(common.isEven);

    t.deepEqual(b(), [2, 4, 6, 8]);
});

test('filters values added via push', function (t) {
    t.plan(1);

    var a = ko.observableArray([]);
    var b = a.filter(common.isEven);

    a.push.apply(a, common.orderedInts);
    t.deepEqual(b(), [2, 4, 6, 8]);
});

test('filters values added via unshift', function (t) {
    t.plan(1);

    var a = ko.observableArray([]);
    var b = a.filter(common.isEven);
Exemple #24
0
var crypto = require('../');

var randomBytesFunctions = {
  randomBytes: require('randombytes'),
  pseudoRandomBytes: crypto.pseudoRandomBytes
};

for (var randomBytesName in randomBytesFunctions) {
  // Both randomBytes and pseudoRandomBytes should provide the same interface
  var randomBytes = randomBytesFunctions[randomBytesName];

  test('get error message', function (t) {
    try {
      var b = randomBytes(10);
      t.ok(Buffer.isBuffer(b));
      t.end()
    } catch (err) {
      t.ok(/not supported/.test(err.message), '"not supported"  is in error message');
      t.end()
    }
  });

  test(randomBytesName, function (t) {
    t.plan(5);
    t.equal(randomBytes(10).length, 10);
    t.ok(Buffer.isBuffer(randomBytes(10)));
    randomBytes(10, function (ex, bytes) {
      t.error(ex);
      t.equal(bytes.length, 10);
      t.ok(Buffer.isBuffer(bytes));
      t.end()
    })
Exemple #25
0
var testContext = require('./_test-context');

var opts = {
  cvv: "123",
  cardType: "visa",
  expireMonth: "11",
  expireYear: "19",
  cardHolderName: "Demo User",
  cardIssueNumber: "4111111111111111",
  cardIssueMonth: "01",
  cardIssueYear: "14"
};


test('provides an informative error if your client context does not include a required base url', 
     function(assert) {
    assert.plan(2);
    var client = require('../clients/commerce/payments/publicCard')({ context: testContext });
    delete client.context.basePciUrl;
    delete client.context.tenantPod;
    client.context.baseUrl = "https://unrecognized.domain";
    client.create(opts, {
      scope: 'NONE'
    }).then(function() {
      assert.fail('throws pci pod error');
    }, function(err) {
      assert.ok(err, 'error threw');
      assert.ok(~err.message.indexOf('no known payment service domain'), "error message is correct: " + err.message);
    });
  });
Exemple #26
0
test('ESX1: Common', function(t) {
	var Common = require('../src/common');

	var input = utils.uintFromBits(utils.uint16TestPattern);
	var params = new Common.MuteSoloParameters(input);
	var output = params.serialize();
	t.equals(input, output, 'MuteSoloParameters OK');

	var input = utils.uintFromBits(utils.uint16TestPattern);
	var sliceNumber = new Common.SliceNumber(input);
	var output = sliceNumber.serialize();
	t.equals(input, output, 'SliceNumber OK');

	var input = utils.uintFromBits(utils.uint16TestPattern);
	var samplePointer = new Common.SamplePointer(input);
	var output = samplePointer.serialize();
	t.equals(input, output, 'SamplePointer OK');

	var input = utils.uintFromBits(utils.uint8TestPattern);
	var msboff8 = new Common.MSBOff8(input);
	var output = msboff8.serialize();
	t.equals(input, output, 'MSBOff8 OK');

	var input = utils.uintFromBits(utils.uint16TestPattern);
	var msboff16 = new Common.MSBOff16BE(input);
	var output = msboff16.serialize();
	t.equals(input, output, 'MSBOff16BE OK');


	var input = utils.uintFromBits(utils.uint8TestPattern);
	var fxflags = new Common.FXFlags(input);
	var output = fxflags.serialize();
	t.equals(input, output, 'FXFlags OK');

	var input = utils.uintFromBits(utils.uint8TestPattern);
	var modflags = new Common.ModFlags(input);
	var output = modflags.serialize();
	t.equals(input, output, 'ModFlags OK');

	var input = utils.uintFromBits([
		0, 1, 0, 0, 0, 0, 0, 1, 0, // 130 bpm
		1, 0, 1,   // reserved
		0, 1, 0, 0 // .40 bpm
	]);
	var tempo = new Common.Tempo(input);
	t.equals(tempo.tempo, 130.4, 'Tempo value OK');
	var output = tempo.serialize();
	t.equals(input, output, 'Tempo OK');

	t.end();
});
Exemple #27
0
tape('git fish', function (group) {

    group.test('test valid json', function (test) {
        async.series([
            function(callback) {
                request.post('http://localhost:10888/test1?token=go-fish', { json: post_data }, function(err, res, body) {
                    test.error(err, 'should not error')
                    test.ok(res, 'should return response');
                    test.equal(res.statusCode, 200, 'should return 200');
                    setTimeout(function () {
                        // give it a bit
                        test.ok(fs.existsSync('/tmp/.git.fish.test.out'), 'should run script');
                        cleanup();
                        callback();
                    }, 200);
                });
            },
            function(callback) {
                request.post('http://localhost:10888/test2?token=go-fish', { json: post_data }, function(err, res, body) {
                    test.error(err, 'should not error')
                    test.ok(res, 'should return response');
                    test.equal(res.statusCode, 200, 'should return 200');
                    setTimeout(function () {
                        // give it a bit
                        test.ok(fs.existsSync('/tmp/.git.fish.test.out'), 'should run script');
                        cleanup();
                        callback();
                    }, 200);
                });
            },
            function(callback) {
                request.post('http://localhost:10888/test3?token=go-fish', { json: post_data }, function(err, res, body) {
                    test.error(err, 'should not error')
                    test.ok(res, 'should return response');
                    test.equal(res.statusCode, 200, 'should return 200');
                    setTimeout(function () {
                        // give it a bit
                        test.ok(fs.existsSync('/tmp/.git.fish.test.out'), 'should run script');
                        cleanup();
                        callback();
                    }, 200);
                });
            },
        ],
        function() {
            test.end();
        });
    });

    group.test('test valid form', function (test) {
        request.post('http://localhost:10888/test1?token=go-fish', { form: { payload: JSON.stringify(post_data) } }, function(err, res, body) {
            test.error(err, 'should not error')
            test.ok(res, 'should return response');
            test.equal(res.statusCode, 200, 'should return 200');
            setTimeout(function () {
                // give it a second
                test.ok(fs.existsSync('/tmp/.git.fish.test.out'), 'should run script');
                cleanup();
                test.end();
            }, 200);
        });
    });

    group.test('bad method', function (test) {
        request.post('http://localhost:10888/test1?token=badtoken', { json: post_data }, function(err, res, body) {
            test.error(err, 'should not error')
            test.ok(res, 'should return response');
            test.equal(res.statusCode, 403, 'should return 403');
            test.end();
        });
    });

    group.test('bad method', function (test) {
        request.put('http://localhost:10888/test1?token=go-fish', { json: post_data }, function(err, res, body) {
            test.error(err, 'should not error')
            test.ok(res, 'should return response');
            test.equal(res.statusCode, 403, 'should return 403');
            test.end();
        });
    });

    group.test('bad data', function (test) {
        request.post('http://localhost:10888/test1?token=go-fish', { json: { bad: 'data' } }, function(err, res, body) {
            test.error(err, 'should not error')
            test.ok(res, 'should return response');
            test.equal(res.statusCode, 500, 'should return 500');
            test.end();
        });
    });

    group.test('bad path', function (test) {
        request.post('http://localhost:10888/bad?token=go-fish', { json: post_data }, function(err, res, body) {
            test.error(err, 'should not error')
            test.ok(res, 'should return response');
            test.equal(res.statusCode, 404, 'should return 500');
            test.end();
        });
    });

    // Give tests 2 seconds to complete and then exit,
    // otherwise, the server process will hang.
    setTimeout( function () {
        server.close();
    }, 2000);
});
Exemple #28
0
import test from 'tape'
import React from 'react'
import {addons} from 'react/addons'
import CardRow from './index.jsx'
const {TestUtils} = addons
const {Simulate, renderIntoDocument, isElement, createRenderer} = TestUtils
const getReactNode = (dom, node) => TestUtils.findRenderedDOMComponentWithTag(dom, node)
const getDOMNode = (dom, node) => getReactNode(dom, node).getDOMNode()
const getDOMNodes = (dom, type) => TestUtils.scryRenderedDOMComponentsWithTag(dom, type)
const getDOMNodeText = (dom, node) => getDOMNode(dom, node).textContent

test('CardRow: constructor', (t) => {
  const cardRow = React.createElement(CardRow)
  t.ok(
    isElement(cardRow)
    , 'is a valid react component'
  )

  t.end()
})

// TODO: delete me. I'm just an example!
test('CardRow rendered DOM', (t) => {
  const name = 'Bert'
  const cardRow = React.createElement(CardRow, {name})
  const dom = renderIntoDocument(cardRow)

  t.equal(
    getDOMNodeText(dom, 'h1')
    , name
    , 'renders the `name` prop'
Exemple #29
0
test('filter', function(t) {
  var Ant = Bee.extend({
    $tpl: '<div><span b-content="filterTest"></span></div>'
  }, {
    filters: {
      filter1: function(arg) {
        return (arg  + 1) || '';
      },
      filter2: function(arg, arg1, arg2) {
        return arg + arg1 + arg2;
      }
    }
  })
  var bee = new Ant({
    $data: {
      filterTest: '{{arg | filter1}}'
    }
  })

  t.test('Bee.filter', function(t) {
    t.plan(2)
    var key = Math.random() + '';
    var data = {name: "Bee"}
    var testfilter = function(name) {
      t.equal(name, data.name)
      return key;
    }

    Bee.filter('test', testfilter)

    var bee = new Bee('<span>{{ name | test }}</span>', {
      $data: data
    })

    t.equal($(bee.$el).text(), key)
  })

  t.test('1 arg sync filter', function(t) {
    t.equal($(bee.$el).text(), '')

    bee.$set('arg', 1)
    t.equal($(bee.$el).text(), '2')

    t.end()
  })

  t.test('multi arg sync filter', function(t){
    bee.$set({'filterTest': '{{ arg | filter2 : arg1 : arg2 }}', arg1: 2, arg2: 4})
    t.equal($(bee.$el).text(), '7')

    bee.$set('arg', 2)
    t.equal($(bee.$el).text(), '8')

    bee.$set('arg1', 3)
    t.equal($(bee.$el).text(), '9')

    bee.$set('arg2', 5)
    t.equal($(bee.$el).text(), '10')

    t.end()
  })

  t.test('multi sync filter', function(t){
    bee.$set({'filterTest': '{{ arg | filter1 | filter2 : arg1 : arg2 }}', arg:1, arg1: 2, arg2: 4})

    t.equal($(bee.$el).text(), '8')

    bee.$set('arg', 2)
    t.equal($(bee.$el).text(), '9')

    bee.$set('arg1', 3)
    t.equal($(bee.$el).text(), '10')

    bee.$set('arg2', 5)
    t.equal($(bee.$el).text(), '11')

    t.end()
  })

  t.test('multi sync filter 2', function(t){
    Ant.filter('filter3', function(arg) {
      return arg * 2
    })
    bee.$set({'filterTest': '{{ arg | filter2 : arg1 : arg2 | filter3}}', arg:1, arg1: 2, arg2: 4})

    t.equal($(bee.$el).text(), '14')

    bee.$set('arg', 2)
    t.equal($(bee.$el).text(), '16')

    bee.$set('arg1', 3)
    t.equal($(bee.$el).text(), '18')

    bee.$set('arg2', 5)
    t.equal($(bee.$el).text(), '20')

    t.end()
  })

  t.test('promise in filter', function(t) {
    var Cicada = Ant.extend({}, {
      filters: {
        filter1: function(arg) {
          return new Promise(function(resolve) {
            resolve( (arg  + 1) || '')
          })
        },
        filter2: function(arg, arg1, arg2) {
          return new Promise(function(resolve) {
            resolve( arg + arg1 + arg2 )
          })
        }
      }
    })
    bee = new Cicada({
      $data: {
        filterTest: '{{arg | filter1}}'
      }
    })

    t.test('1 arg async filter', function(t) {
      t.equal($(bee.$el).text(), '')

      bee.$set('arg', 1)
      setTimeout(function() {
        t.equal($(bee.$el).text(), '2')
        t.end()
      }, 100)
    })

    t.test('multi arg async filter', function(t){
      t.test(function(t) {
        bee.$set({'filterTest': '{{ arg | filter2 : arg1 : arg2 }}', arg1: 2, arg2: 4})
        setTimeout(function() {
          t.equal($(bee.$el).text(), '7')
          t.end()
        }, 100)
      })

      t.test(function(t) {
        bee.$set('arg', 2)
        setTimeout(function() {
          t.equal($(bee.$el).text(), '8')
          t.end()
        }, 10)
      })

      t.test(function(t) {
        bee.$set('arg1', 3)
        setTimeout(function() {
          t.equal($(bee.$el).text(), '9')
          t.end()
        }, 10)
      })

      t.test(function(t) {
        bee.$set('arg2', 5)
        setTimeout(function () {
          t.equal($(bee.$el).text(), '10')
          t.end()
        }, 10)
      })

    })

    t.test('multi async filter', function(t){
      bee.$set({'filterTest': '{{ arg | filter1 | filter2 : arg1 : arg2 }}', arg:1, arg1: 2, arg2: 4})
      t.test(function(t) {
        setTimeout(function () {
          t.equal($(bee.$el).text(), '8')
          t.end();
        }, 100)
      })

      t.test(function(t) {
        bee.$set('arg', 2)
        setTimeout(function() {
          t.equal($(bee.$el).text(), '9')
          t.end()
        }, 10)
      })

      t.test(function(t) {
        bee.$set('arg1', 3)
        setTimeout(function() {
          t.equal($(bee.$el).text(), '10')
          t.end()
        }, 10)
      })

      t.test(function(t) {
        bee.$set('arg2', 5)
        setTimeout(function() {
          t.equal($(bee.$el).text(), '11')
          t.end()
        }, 10)
      })

    })


  })

})
var schedules = [
  {
    string: '* * 30 FEB *',
    error: 'Unable to find execution time for schedule'
  }
];
test('Should throw on invalid schedule', function(t) {
  t.plan(schedules.length);
  schedules.forEach(function(schedule) {
    var cron = new Cron();
    cron.fromString(schedule.string);
    try {
      cron.schedule().next();
      t.fail('Missing expected exception');
    } catch (e) {
      t.equal(
        e.message,
        schedule.error,
        schedule.string
      );
    }
  });
});

test('Should throw on invalid date', function(t) {
  var cron = new Cron();
  t.plan(1);
  cron.fromString('* * * * *');
  try {
    cron.schedule(NaN);