Esempio n. 1
0
test('type errors', function () {
  test('size as a string', function () {
    try {
      throat('foo')
    } catch (ex) {
      assert(/Expected throat size to be a number/.test(ex.message));
      return;
    }
    throw new Error('Expected a failure')
  })
  test('fn as a string', function () {
    try {
      throat(2, 'foo')
    } catch (ex) {
      assert(/Expected throat fn to be a function/.test(ex.message));
      return;
    }
    throw new Error('Expected a failure')
  })
  test('late fn as a string', function () {
    try {
      throat(2)('foo')
    } catch (ex) {
      assert(/Expected throat fn to be a function/.test(ex.message));
      return;
    }
    throw new Error('Expected a failure')
  })
})
Esempio n. 2
0
test('throat(fn, n)', function () {
  test('throat(fn, 1) acts as a sequential worker', function (done) {
    Promise.all([sentA, sentB, sentC].map(throat(worker(1), 1)))
      .then(function (res) {
        assert(res[0] instanceof Processed && res[0].val.length > 1 && res[0].val[0] === sentA)
        assert(res[1] instanceof Processed && res[1].val.length > 1 && res[1].val[0] === sentB)
        assert(res[2] instanceof Processed && res[2].val.length > 1 && res[2].val[0] === sentC)
      })
      .nodeify(done)
  })
  test('throat(fn, 2) works on two inputs in parallel', function (done) {
    Promise.all([sentA, sentB, sentC].map(throat(worker(2), 2)))
      .then(function (res) {
        assert(res[0] instanceof Processed && res[0].val.length > 1 && res[0].val[0] === sentA)
        assert(res[1] instanceof Processed && res[1].val.length > 1 && res[1].val[0] === sentB)
        assert(res[2] instanceof Processed && res[2].val.length > 1 && res[2].val[0] === sentC)
      })
      .nodeify(done)
  })
  test('throat(fn, 3) works on three inputs in parallel', function (done) {
    Promise.all([sentA, sentB, sentC].map(throat(worker(3), 3)))
      .then(function (res) {
        assert(res[0] instanceof Processed && res[0].val.length > 1 && res[0].val[0] === sentA)
        assert(res[1] instanceof Processed && res[1].val.length > 1 && res[1].val[0] === sentB)
        assert(res[2] instanceof Processed && res[2].val.length > 1 && res[2].val[0] === sentC)
      })
      .nodeify(done)
  })
})
Esempio n. 3
0
test('throat(n, fn)', function () {
  test('throat(1, fn) acts as a sequential worker', function () {
    return Promise.all([sentA, sentB, sentC].map(throat(1, worker(1))))
      .then(function (res) {
        assert(res[0] instanceof Processed && res[0].val.length > 1 && res[0].val[0] === sentA)
        assert(res[1] instanceof Processed && res[1].val.length > 1 && res[1].val[0] === sentB)
        assert(res[2] instanceof Processed && res[2].val.length > 1 && res[2].val[0] === sentC)
      })
  })
  test('throat(2, fn) works on two inputs in parallel', function () {
    return Promise.all([sentA, sentB, sentC].map(throat(2, worker(2))))
      .then(function (res) {
        assert(res[0] instanceof Processed && res[0].val.length > 1 && res[0].val[0] === sentA)
        assert(res[1] instanceof Processed && res[1].val.length > 1 && res[1].val[0] === sentB)
        assert(res[2] instanceof Processed && res[2].val.length > 1 && res[2].val[0] === sentC)
      })
  })
  test('throat(3, fn) works on three inputs in parallel', function () {
    return Promise.all([sentA, sentB, sentC].map(throat(3, worker(3))))
      .then(function (res) {
        assert(res[0] instanceof Processed && res[0].val.length > 1 && res[0].val[0] === sentA)
        assert(res[1] instanceof Processed && res[1].val.length > 1 && res[1].val[0] === sentB)
        assert(res[2] instanceof Processed && res[2].val.length > 1 && res[2].val[0] === sentC)
      })
  })
})
Esempio n. 4
0
function testBrowser(getBrowser, promise) {
  function testCase(persona) {
    return function () {
      var getStatus;
      var browser = getBrowser();
      return promise(browser.sauceJobUpdate({
        name: 'cabbie-persona',
        build: process.env.TRAVIS_JOB_ID
      })).then(function () {
        return promise(browser.navigateTo(location))
      }).then(function () {
        return promise(browser.getElement('#status'));
      }).then(function (status) {
        getStatus = function () { return promise(status.text()); };
        return getStatus();
      }).then(function (status) {
        assert(status === 'Logged Out');
      }).then(function () {
        return promise(browser.getElement('#login'));
      }).then(function (login) {
        return promise(login.click());
      }).then(function () {
        return promise(persona(browser));
      }).then(function () {
        return delay('5000ms');
      }).then(function () {
        return getStatus();
      }).then(function (status) {
        assert(status === 'Logged In');
      }).then(function () {
        return promise(browser.getElement('#logout'));
      }).then(function (logout) {
        return promise(logout.click());
      }).then(function () {
        return delay('500ms');
      }).then(function () {
        return getStatus();
      }).then(function (status) {
        assert(status === 'Logged Out');
      }).then(function () {
        return promise(browser.dispose({passed: true}));
      }, function (err) {
        return promise(browser.dispose({passed: false})).then(function () {
          throw err;
        }, function () {
          throw err;
        });
      });
    };
  }
  test('it lets you login with username and password', testCase(function (browser) {
    return persona(browser, 'jepso-test@mailinator.com', 'abc1234567');
  }), '2 minutes');
  test('it lets you login with mockmyid.com', testCase(function (browser) {
    return persona(browser, 'jepso-test@mockmyid.com');
  }), '2 minutes');
}
Esempio n. 5
0
}).forEach(function (name) {
  name = name.replace(/\.jade$/, '');
  test(name, function () {
    var src = fs.readFileSync(inputDir + '/' + name + '.jade', 'utf8');
    var expected = htmlparser.parseDOM(fs.readFileSync(inputDir + '/' + name + '.html', 'utf8'));
    fs.writeFileSync(outputDir + '/' + name + '.jade', src);
    var js = jade.compileFileClient(inputDir + '/' + name + '.jade', {
      outputFile: outputDir + '/' + name + '.js',
      basedir: inputDir
    });
    fs.writeFileSync(outputDir + '/' + name + '.js', js);
    mockDom.mock();
    var fn = jade.compileFile(inputDir + '/' + name + '.jade', {
      outputFile: outputDir + '/' + name + '.js',
      basedir: inputDir
    });
    var actual = fn({title: 'Jade'});
    var hasDiv = expected.filter(function(element) { return element.type !== 'text' }).length !== 1;
    actual = hasDiv ? actual.children : actual; 
    mockDom.reset();

    if (domToString(expected) !== domToString(actual)) {
      fs.writeFileSync(outputDir + '/' + name + '.expected.dom', domToString(expected) + '\n');
      fs.writeFileSync(outputDir + '/' + name + '.actual.dom', domToString(actual) + '\n');
      assert(domToString(expected) === domToString(actual), 'Expected output dom to match expected dom (see /test/output/' + name + '.actual.dom and /test/output/' + name + '.expected.dom for details.');
    }
  });
});
Esempio n. 6
0
fs.readdirSync(dir).forEach(function (testCase) {
  if (/\.input\.json$/.test(testCase)) {
    testit(testCase, function () {
      var stem = testCase.replace(/\.input\.json$/, '.');

      function test (name, options) {
        var expected;
        var input = fs.readFileSync(dir + testCase, 'utf8');
        input = lineJSON.parse(input);
        try {
          expected = fs.readFileSync(dir + stem + name + '.expected.json', 'utf8');
          expected = lineJSON.parse(expected);
        } catch (ex) {
          if (ex.code !== 'ENOENT') throw ex;
        }

        var result = strip(input, options);
        try {
          assert.deepEqual(expected, result);
        } catch (ex) {
          console.log('Updating', testCase);
          fs.writeFileSync(dir + stem + name + '.expected.json'. lineJSON.stringify(result));
        }
      }

      test('unbuffered');
      test('buffered',   { stripBuffered: true, stripUnbuffered: false });
      test('both',       { stripBuffered: true });
    });
  }
});
Esempio n. 7
0
fs.readdirSync(edir).forEach(function (testCase) {
  if (/\.input\.json$/.test(testCase)) {
    testit(testCase, function () {
      var stem = testCase.replace(/\.input\.json$/, '.');

      var input = fs.readFileSync(edir + testCase, 'utf8');
      input = lineJSON.parse(input);
      var expected = fs.readFileSync(edir + stem + 'err.json', 'utf8');
      expected = JSON.parse(expected);

      var actual;
      try {
        strip(input);
        throw new Error('Expected ' + testCase + ' to throw an exception.');
      } catch (ex) {
        if (!ex || !ex.code || !ex.code.indexOf('JADE:') === 0) throw ex;
        actual = {
          msg: ex.msg,
          code: ex.code,
          line: ex.line
        };
      }
      assert.deepEqual(expected, actual);
    });
  }
});
/**
 * Define a test case.
 *
 * @param name - The folder name for the test fixtures.
 * @param plugins - An associative array of plugin key name, and options for it.
 */
function test(name, plugins) {
  testit(name, function (done) {
    // Ensure we load the Metalsmith JSTransformer Layouts plugin.
    plugins = plugins || {}
    if (!plugins['..']) {
      plugins['..'] = {}
    }

    // Construct Metalsmith with a clean build directory.
    var testPath = 'test/fixtures/' + name
    rmdir.sync(testPath + '/build')
    var metalsmith = new Metalsmith(testPath)
    for (var plugin in plugins || {}) {
      if (plugins.hasOwnProperty(plugin)) {
        metalsmith.use(require(plugin)(plugins[plugin]))
      }
    }
    metalsmith.build(function (err) {
      if (err) {
        done(err)
      }
      assertDir(testPath + '/build', testPath + '/expected')
      done()
    })
  })
}
Esempio n. 9
0
fs.readdirSync(__dirname + '/cases').forEach(function (testCase) {
  if (!/\.input\.js$/.test(testCase)) {
    return;
  } else {
    testCase = testCase.replace(/\.input\.js$/, '');
  }
  test(testCase, function () {
    var input = fs.readFileSync(__dirname + '/cases/' + testCase + '.input.js', 'utf8');
    var expected = fs.readFileSync(__dirname + '/cases/' + testCase + '.expected.js', 'utf8');
    var output = removeRequire(input);
    fs.writeFileSync(__dirname + '/output/' + testCase + '.js', output.src);
    assert.equal(output.src, expected);
  });
});
Esempio n. 10
0
function error (src, line, col, options) {
  testit(JSON.stringify(src), function () {
    options = options || {}
    assert(!isExpression(src, options))
    options.throw = true 
    assert.throws(function () {
      isExpression(src, options)
    }, function (err) {
      assert.equal(err.loc.line, line)
      assert.equal(err.loc.column, col)
      assert(err.message)
      return true
    })
  })
}
Esempio n. 11
0
function testEnv(env) {
  var request = require(env === 'browser' ? '../browser.js' : '../index.js');
  test(env + ' - GET', function () {
    return request('GET', 'http://example.com').then(function (res) {
      assert(res.statusCode === 200);
      assert(res.headers['foo'] === 'bar');
      assert(res.body.toString() === 'body');
    });
  });
  test(env + ' - GET query', function () {
    return request('GET', 'http://example.com', {qs: {foo: 'baz'}}).then(function (res) {
      assert(res.statusCode === 200);
      assert(res.headers['foo'] === 'baz');
      assert(res.body.toString() === 'body');
    });
  });
  test(env + ' - GET -> .getBody("utf8")', function () {
    return request('GET', 'http://example.com').getBody('utf8').then(function (body) {
      assert(body === 'body');
    });
  });
  test(env + ' - POST json', function () {
    return request('POST', 'http://example.com', {json: {foo: 'baz'}}).then(function (res) {
      assert(res.statusCode === 200);
      assert(res.body.toString() === 'json body');
    });
  });


  test(env + ' - invalid method', function () {
    return request({}, 'http://example.com').then(function (res) {
      throw new Error('Expected an error');
    }, function (err) {
      assert(err instanceof TypeError);
    });
  });
  test(env + ' - invalid url', function () {
    return request('GET', {}).then(function (res) {
      throw new Error('Expected an error');
    }, function (err) {
      assert(err instanceof TypeError);
    });
  });
  test(env + ' - invalid options', function () {
    return request('GET', 'http://example.com', 'options').then(function (res) {
      throw new Error('Expected an error');
    }, function (err) {
      assert(err instanceof TypeError);
    });
  });
}
Esempio n. 12
0
function test(input, expected, locals) {
  var opts = options;
  locals = locals || {};
  locals.pug = locals.pug || require('pug-runtime');
  testit(utils.inspect(input).replace(/\n/g, '') + ' => ' + utils.inspect(expected), function () {
    var src = attrs(input, opts);
    var localKeys = Object.keys(locals).sort();
    var output = Function(localKeys.join(', '), 'return (' + src + ');').apply(null, localKeys.map(function (key) { return locals[key]; }));
    if (opts.format === 'html') {
      assert.strictEqual(output, expected);
    } else {
      assert.deepEqual(output, expected);
    }
  });
}
Esempio n. 13
0
}).forEach(function(name) {
  name = name.replace(/\.pug/, '');
  test(name, function () {
    var fn = jade.compileFile(bonusDir + '/' + name + '.pug');
    var c = React.createClass({ render: fn });
    var html = ReactDOM.renderToStaticMarkup(React.createElement(c, { title: 'Jade', list: ['a', 'b', 'c']}));

    var actual = htmlparser.parseDOM(html);
    var expected = htmlparser.parseDOM(fs.readFileSync(bonusDir + '/' + name + '.html', 'utf8'));
    if (domToString(expected) !== domToString(actual)) {
      fs.writeFileSync(outputDir + '/' + name + '.expected.dom', domToString(expected) + '\n');
      fs.writeFileSync(outputDir + '/' + name + '.actual.dom', domToString(actual) + '\n');
      assert(domToString(expected) === domToString(actual), 'Expected output dom to match expected dom (see /test/output/' + name + '.actual.dom and /test/output/' + name + '.expected.dom for details.');
    }
  });
});
Esempio n. 14
0
srcFiles.forEach( function(file) {
  var mode = path.basename(file, path.extname(file));
  it('Generate formated HTML from '+mode+' code', function() {
    var source = readSrcFile(file);
    var result = highlight(source, mode);
    var mime = highlight.CodeMirror.findModeByName(mode).mime;

    var child = child_process.exec( source_highlight, ['-s', mime], {encoding: 'utf8'},
      function(error, stdout, stderr) {
        assert(error == null);
        assert.equal(result, stdout);
    });

    child.stdin.write(source);
    child.stdin.end();
  });
});
Esempio n. 15
0
fs.readdirSync(dir).forEach(function (testCase) {
  if (/\.input\.json$/.test(testCase)) {
    testit(testCase, function () {
      var stem = testCase.replace(/\.input\.json$/, '.');

      function test (name, options) {
        var input = fs.readFileSync(dir + testCase, 'utf8');
        input = lineJSON.parse(input);
        var expected = fs.readFileSync(dir + stem + name + '.expected.json', 'utf8');
        expected = lineJSON.parse(expected);

        var result = strip(input, options);
        fs.writeFileSync(dir + stem + name + '.actual.json', lineJSON.stringify(result));
        assert.deepEqual(expected, result);
      }

      test('unbuffered');
      test('buffered',   { stripBuffered: true, stripUnbuffered: false });
      test('both',       { stripBuffered: true });
    });
  }
});
Esempio n. 16
0
fs.readdirSync(edir).forEach(function (testCase) {
  if (/\.input\.json$/.test(testCase)) {
    testit(testCase, function () {
      var stem = testCase.replace(/\.input\.json$/, '.');

      var input = fs.readFileSync(edir + testCase, 'utf8');
      input = lineJSON.parse(input);
      var expected;
      try {
        expected = fs.readFileSync(edir + stem + 'err.json', 'utf8');
        expected = JSON.parse(expected);
      } catch (ex) {
        if (ex.code !== 'ENOENT') throw ex;
      }

      var actual;
      try {
        strip(input);
        throw new Error('Expected ' + testCase + ' to throw an exception.');
      } catch (ex) {
        if (!ex || !ex.code || !ex.code.indexOf('JADE:') === 0) throw ex;
        actual = {
          msg: ex.msg,
          code: ex.code,
          line: ex.line
        };
      }
      try {
        assert.deepEqual(expected, actual);
      } catch (ex) {
        console.log('Updating', testCase);
        fs.writeFileSync(edir + stem + 'err.json',
                         JSON.stringify(actual, null, '  '));
      }
    });
  }
});
Esempio n. 17
0
function testEnv(env) {
  var request, FormData;
  test(env + ' - GET', function () {
    request = require(env === 'browser' ? '../lib/browser.js' : '../');
    FormData = request.FormData;
    return request('GET', 'http://localhost:3000').then(function (res) {
      assert(res.statusCode === 200);
      assert(res.headers['foo'] === 'bar');
      assert(res.body.toString() === 'body');
    });
  });
  test(env + ' - GET query', function () {
    return request('GET', 'http://localhost:3000', {qs: {foo: 'baz'}}).then(function (res) {
      assert(res.statusCode === 200);
      assert(res.headers['foo'] === 'baz');
      assert(res.body.toString() === 'body');
    });
  });
  test(env + ' - GET -> .getBody("utf8")', function () {
    return request('GET', 'http://localhost:3000').getBody('utf8').then(function (body) {
      assert(body === 'body');
    });
  });
  test(env + ' - POST json', function () {
    return request('POST', 'http://localhost:3000', {json: {foo: 'baz'}}).then(function (res) {
      assert(res.statusCode === 200);
      assert(res.body.toString() === 'json body');
    });
  });
  test(env + ' - POST form', function () {
    const fd = new FormData();
    fd.append('foo', 'baz');
    return request('POST', 'http://localhost:3000/form', {form: fd}).then(function (res) {
      assert(res.statusCode === 200);
      assert(res.body.toString() === 'form body');
    });
  });


  test(env + ' - invalid method', function () {
    return request({}, 'http://localhost:3000').then(function (res) {
      throw new Error('Expected an error');
    }, function (err) {
      assert(err instanceof TypeError);
    });
  });
  test(env + ' - invalid url', function () {
    return request('GET', {}).then(function (res) {
      throw new Error('Expected an error');
    }, function (err) {
      assert(err instanceof TypeError);
    });
  });
  test(env + ' - invalid options', function () {
    return request('GET', 'http://localhost:3000', 'options').then(function (res) {
      throw new Error('Expected an error');
    }, function (err) {
      assert(err instanceof TypeError);
    });
  });
}
Esempio n. 18
0
'use strict';

var assert = require('assert');
var test = require('testit');
var Promise = require('promise');
var createServer = require('./mock-server');
var mockDOM = require('./mock-dom');

test('./lib/handle-qs.js', function () {
  var handleQs = require('../lib/handle-qs.js').default;

  assert(handleQs('http://example.com/', {}) === 'http://example.com/');
  assert(handleQs('http://example.com/?foo=bar', {}) === 'http://example.com/?foo=bar');
  assert(handleQs('http://example.com/', {foo: 'bar'}) === 'http://example.com/?foo=bar');
  assert(handleQs('http://example.com/', {foo: {bar: 'baz'}}) === 'http://example.com/?foo%5Bbar%5D=baz');
  assert(handleQs('http://example.com/', {foo: 'bar', bing: 'bong'}) === 'http://example.com/?foo=bar&bing=bong');
  assert(handleQs('http://example.com/?foo=bar', {bing: 'bong'}) === 'http://example.com/?foo=bar&bing=bong');
  assert(handleQs('http://example.com/?foo=bar#ding', {bing: 'bong'}) === 'http://example.com/?foo=bar&bing=bong#ding');
});

var server = createServer();

function testEnv(env) {
  var request, FormData;
  test(env + ' - GET', function () {
    request = require(env === 'browser' ? '../lib/browser.js' : '../');
    FormData = request.FormData;
    return request('GET', 'http://localhost:3000').then(function (res) {
      assert(res.statusCode === 200);
      assert(res.headers['foo'] === 'bar');
      assert(res.body.toString() === 'body');
import assert from 'assert';
import test from 'testit';

test('node-release', () => {
  const nodeRelease = require('../../src/bots/node-release').default;
  return nodeRelease({dryRun: true}).then(result => {
    assert(Array.isArray(result), 'Expected an array');
    assert(result.every(calls => Array.isArray(calls)), 'Expected an array of arrays');
  });
});
Esempio n. 20
0
var assert = require('assert');

var step = require('testit');
var npm = require('npm-fetch');
var unpack = require('tar-pack').unpack;
var mkdirp = require('mkdirp').sync;
var rimraf = require('rimraf').sync;
var UglifyJS = require('uglify-js');
var semver = require('semver');

var completedCleanup = false;
var completedDownload = false;
var completedVersion = false;
step('cleanup', function () {
  rimraf(__dirname + '/src');
  rimraf(__dirname + '/lib');
  mkdirp(__dirname + '/lib');
  completedCleanup = true;
});

step('download codemirror', function (callback) {
  if (!completedCleanup) throw new Error('skipped because cleanup was unsucessful');
  npm('codemirror', '*').pipe(unpack(__dirname + '/src', callback));
  completedDownload = true;
}, '60 seconds');

step('get version', function () {
  if (!completedDownload) throw new Error('skipped because download was unsucessful');
  var version = JSON.parse(read('./src/package.json')).version;
  var pkg = JSON.parse(read('./package.json'));
  assert(pkg.version === version || semver.gt(version, pkg.version), version + ' is too low, must be greater than or equal to ' + pkg.version);
  pkg.version = version;
Esempio n. 21
0
File: index.js Progetto: hugs/cabbie
  LOCAL = cp.fork(require.resolve('./server.js'));
  location = 'http://localhost:1338/demo-page.html';
} else {
  location = 'http://rawgithub.com/ForbesLindesay/cabbie/master/test/demo-page.html';
}

function delay(time) {
  return new Promise(function (resolve) {
    setTimeout(resolve, require('ms')(time + ''));
  });
}

test('it throws an error if you try and get a browser with an invalid mode', function () {
  try {
    var browser = getBrowser({mode: 'foo'});
  } catch (ex) {
    assert(ex instanceof Error);
  }
});

function testBrowser(browser, promise) {
  test('it lets you specify a sauce job name', function () {
    return promise(browser
                   .sauceJobUpdate({
                     name: 'synchronous',
                     build: process.env.TRAVIS_JOB_ID
                   }));
  });
  test('it lets you set timeouts', function () {
    return promise(browser.setTimeouts({
      'implicit': '10s',
Esempio n. 22
0
File: index.js Progetto: hugs/cabbie
function testBrowser(browser, promise) {
  test('it lets you specify a sauce job name', function () {
    return promise(browser
                   .sauceJobUpdate({
                     name: 'synchronous',
                     build: process.env.TRAVIS_JOB_ID
                   }));
  });
  test('it lets you set timeouts', function () {
    return promise(browser.setTimeouts({
      'implicit': '10s',
      'async': '10s'
    }));
  });
  test('it lets you navigate to a domain', function () {
    return promise(browser.navigateTo(location)).then(function () {
      return promise(browser.getElement('h1'));
    });
  });
  test('you can get an element', function () {
    return promise(browser.getElement('h1'));
  });
  test('you can test whether an element is visible', function () {
    return promise(browser.getElement('h1')).then(function (element) {
      return promise(element.isVisible());
    }).then(function (visible) {
      assert(visible === true);
      return promise(browser.getElement('#hidden'));
    }).then(function (element) {
      return promise(element.isVisible());
    }).then(function (visible) {
      assert(visible === false);
    });
  });
  test('you can get an attribute of an element', function () {
    return promise(browser.getElement('#has-attribute')).then(function (element) {
      return promise(element.get('data-attribute'));
    }).then(function (name) {
      assert(name === 'value');
    });
  });
  test('you can type text into an element', function () {
    return promise(browser.getElement('[name="q"]')).then(function (element) {
      return promise(element.type('hello')).then(function () {
        return promise(element.type([' ', 'world']));
      }).then(function () {
        return promise(element.get('value'));
      }).then(function (value) {
        assert(value === 'hello world');
        return promise(element.clear());
      }).then(function () {
        return promise(element.get('value'));
      }).then(function (value) {
        assert(value === '');
      });
    });
  });
  test('you can get the text content of an element', function () {
    return promise(browser.getElement('#has-text')).then(function (element) {
      return promise(element.text()).then(function (text) {
        assert(text === 'test content');
      });
    });
  });
  test('it lets you click on a button', function () {
    return promise(browser.getElement('#clickable')).then(function (button) {
      return promise(button.click()).then(function () {
        return button.text();
      }).then(function (text) {
        assert(text === 'clicked');
      });
    });
  });
  if (!LOCAL) {
    // TODO: for some reason setting cookies doesn't seem to work locally
    test('it lets you set cookies, read them back, and clear them', function() {
      return promise(browser.setCookie({name: 'test-cookie0', value: 'test-cookie0-value'})).then(function () {
        return browser.setCookie({name: 'test-cookie1', value: 'test-cookie1-value'});
      }).then(function () {
        return browser.setCookie({name: 'test-cookie2', value: 'test-cookie2-value'});
      }).then(function () {
        return browser.getCookie('test-cookie0');
      }).then(function(cookie) {
        assert(cookie !== null);
        assert(cookie.name === 'test-cookie0');
        assert(cookie.value === 'test-cookie0-value');
      }).then(function() {
        return browser.getCookies();
      }).then(function(cookies) {
        assert(cookies.length === 3);
      }).then(function() {
        return browser.getCookie('no-such-cookie');
      }).then(function(cookie) {
        assert(cookie === null);
      }).then(function() {
        return browser.clearCookie('test-cookie2');
      }).then(function() {
        return browser.getCookies();
      }).then(function(cookies) {
        assert(cookies.length === 2);
      }).then(function() {
        return browser.clearCookies();
      }).then(function() {
        return browser.getCookies();
      }).then(function(cookies) {
        assert(cookies.length === 0);
      });
    });
  }

  test('it lets you dispose the browser', function () {
    return promise(browser.dispose({passed: true}));
  });
}
Esempio n. 23
0
'use strict';

var assert = require('assert');
var test = require('testit');

test('data exists', function () {
  var data = require('../');
  var sections = ['collection', 'cursor', 'database', 'replication', 'sharding', 'subprocess', 'connection', 'native', 'objectid'];
  sections.forEach(function (section) {
    assert(Array.isArray(data[section]));
    assert(data[section].length > 0);
    data[section].forEach(function (method) {
      assert(method.name && typeof method.name === 'string');
      assert(method.description && typeof method.description === 'string');
      assert(method.href && typeof method.href === 'string');
    })
  })
})
Esempio n. 24
0
}

test('bonus-features/partial-application.jade', function () {
  var fn = jade.compileFile(__dirname + '/bonus-features/partial-application.jade');
  fs.writeFileSync(__dirname + '/output/partial-application.js', jade.compileFileClient(__dirname + '/bonus-features/partial-application.jade'));
  function click() {
    throw new Error('click should never actually get called');
  }
  var i = 0;
  var view = { click: click };
  click.bind = function (self, val) {
    if (i === 0) {
      assert(self === view);
      assert(arguments.length === 1);
    } else if (i === 1) {
      assert(self === null);
      assert(val === 'Click Me 0!');
    } else if (i === 2) {
      assert(self === view);
      assert(val === 'Click Me 1!');
    } else if (i === 3) {
      assert(self === view);
      assert(val === 'Click Me 2!');
    }
    i++;
    return click;
  };
  fn({ view: view });
  assert(i === 4);
});
Esempio n. 25
0
test('throat(n)', function () {
  test('throat(1) acts as a lock', function (done) {
    var lock = throat(1)
    var a = job(), b = job(), c = job();
    var resA = lock(a, 123)
    var resB = lock(b, 456)
    var resC = lock(c, 789)
    assert(a.isRun)
    assert(!b.isRun)
    assert(!c.isRun)
    a.complete(sentA)
    resA.then(function (resA) {
      assert(resA === sentA)
      assert(a.isRun)
      assert(b.isRun)
      assert(!c.isRun)
      b.fail(sentB)
      return resB
        .then(function () {
          throw new Error('b should have been rejected')
        }, function (errB) {
          assert(errB === sentB)
        })
    })
    .then(function () {
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      assert.deepEqual(a.args, [123]);
      assert.deepEqual(b.args, [456]);
      assert.deepEqual(c.args, [789]);
      c.complete(sentC)
      return resC
    })
    .then(function (resC) {
      assert(resC === sentC)
    })
    .nodeify(done)
  })
  test('throat(2) lets two processes acquire the same lock', function (done) {
    var lock = throat(2)
    var a = job(), b = job(), c = job();
    var resA = lock(a)
    var resB = lock(b)
    var resC = lock(c)
    assert(a.isRun)
    assert(b.isRun)
    assert(!c.isRun)
    a.complete(sentA)
    resA.then(function (resA) {
      assert(resA === sentA)
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      b.fail(sentB)
      return resB
        .then(function () {
          throw new Error('b should have been rejected')
        }, function (errB) {
          assert(errB === sentB)
        })
    })
    .then(function () {
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      c.complete(sentC)
      return resC
    })
    .then(function (resC) {
      assert(resC === sentC)
    })
    .nodeify(done)
  })
  test('throat(3) lets three processes acquire the same lock', function (done) {
    var lock = throat(3)
    var a = job(), b = job(), c = job();
    var resA = lock(a)
    var resB = lock(b)
    var resC = lock(c)
    assert(a.isRun)
    assert(b.isRun)
    assert(c.isRun)
    a.complete(sentA)
    resA.then(function (resA) {
      assert(resA === sentA)
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      b.fail(sentB)
      return resB
        .then(function () {
          throw new Error('b should have been rejected')
        }, function (errB) {
          assert(errB === sentB)
        })
    })
    .then(function () {
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      c.complete(sentC)
      return resC
    })
    .then(function (resC) {
      assert(resC === sentC)
    })
    .nodeify(done)
  })
})
Esempio n. 26
0
const join = require('path').join
const test = require('testit')

const inputFile = 'test/input.twig'
const locals = fs.readFileSync(join(__dirname, 'locals.json')).toString().trim()
const expected = fs.readFileSync(join(__dirname, 'expected.html')).toString().trim()

function assertEqual(output, expected) {
  console.log('   Output:\t' + JSON.stringify(output))
  console.log('   Expected:\t' + JSON.stringify(expected))
  assert.equal(output, expected)
}

test('bin/jstransformer twig ' + inputFile, done => {
  const args = [
    'twig',
    inputFile,
    '--locals=' + locals
  ]
  childProcess.execFile('bin/jstransformer', args, (err, stdout) => {
    if (err) {
      done(err)
    } else {
      assertEqual(stdout.toString().trim(), expected)
      done()
    }
  })
})

// TODO: Add a test for piping information.
Esempio n. 27
0
File: build.js Progetto: AISteam/AIS
var relative = require('path').relative;
var join = require('path').join;
var dirname = require('path').dirname;
var fs = require('fs');

var step = require('testit');
var npm = require('npm-fetch');
var unpack = require('tar-pack').unpack;
var mkdirp = require('mkdirp').sync;
var rimraf = require('rimraf').sync;
var UglifyJS = require('uglify-js');


step('cleanup', function (callback) {
  rimraf(__dirname + '/src');
  rimraf(__dirname + '/lib');
  mkdirp(__dirname + '/lib');
  npm('codemirror', '*').pipe(unpack(__dirname + '/src', callback));
}, '60 seconds');

step('get version', function () {
  var version = JSON.parse(read('./src/package.json')).version;
  var pkg = JSON.parse(read('./package.json'));
  pkg.version = version;
  write('./package.json', JSON.stringify(pkg, null, '  '));
});

step('plugins', function () {
  write('./lib/overlay.js', 'var CodeMirror = require("./codemirror.js");\n' + read('./src/addon/mode/overlay.js'));
});

step('generate codemirror', function () {
Esempio n. 28
0
    }).on('error', reject).end();
  });
}
function gunzip(body) {
  return new Promise(function (resolve, reject) {
    zlib.gunzip(body, function (err, res) {
      if (err) reject(err);
      else resolve(res);
    }.bind(this));
  });
}
test('raw-request', function () {
  return request('/', {}).then(function (res) {
    assert(res.statusCode === 200);
    assert(res.body.toString() === HTML_STRING);
    assert(res.headers.vary === 'Accept-Encoding');
    assert(res.headers.etag === '76f7dd7da1deaa8cec3648c1f4790852');
    assert(res.headers['content-length'] === '16530');
    assert(res.headers['content-type'] === 'text/html');
  });
});
test('gzip-request', function () {
  return request('/', {'accept-Encoding': 'gzip'}).then(function (res) {
    assert(res.statusCode === 200);
    assert(res.headers.vary === 'Accept-Encoding');
    assert(res.headers.etag === '76f7dd7da1deaa8cec3648c1f4790852');
    assert(res.headers['content-length'] === '4525');
    assert(res.headers['content-type'] === 'text/html');
    assert(res.headers['content-encoding'] === 'gzip');
    return gunzip(res.body);
  }).then(function (body) {
    assert(body.toString() === HTML_STRING);
Esempio n. 29
0
test('throat(n)', function () {
  test('throat(1) acts as a lock', function (done) {
    var lock = throat(1)
    var a = job(), b = job(), c = job();
    var resA = lock(a, 123)
    var resB = lock(b, 456)
    var resC = lock(c, 789)
    assert(a.isRun)
    assert(!b.isRun)
    assert(!c.isRun)
    a.complete(sentA)
    resA.then(function (resA) {
      assert(resA === sentA)
      assert(a.isRun)
      assert(b.isRun)
      assert(!c.isRun)
      b.fail(sentB)
      return resB
        .then(function () {
          throw new Error('b should have been rejected')
        }, function (errB) {
          assert(errB === sentB)
        })
    })
    .then(function () {
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      assert.deepEqual(a.args, [123]);
      assert.deepEqual(b.args, [456]);
      assert.deepEqual(c.args, [789]);
      c.complete(sentC)
      return resC
    })
    .then(function (resC) {
      assert(resC === sentC)
    })
    .nodeify(done)
  })
  test('throat(2) lets two processes acquire the same lock', function (done) {
    var lock = throat(2)
    var a = job(), b = job(), c = job();
    var resA = lock(a)
    var resB = lock(b)
    var resC = lock(c)
    assert(a.isRun)
    assert(b.isRun)
    assert(!c.isRun)
    a.complete(sentA)
    resA.then(function (resA) {
      assert(resA === sentA)
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      b.fail(sentB)
      return resB
        .then(function () {
          throw new Error('b should have been rejected')
        }, function (errB) {
          assert(errB === sentB)
        })
    })
    .then(function () {
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      c.complete(sentC)
      return resC
    })
    .then(function (resC) {
      assert(resC === sentC)
    })
    .nodeify(done)
  })
  test('throat(3) lets three processes acquire the same lock', function (done) {
    var lock = throat(3)
    var a = job(), b = job(), c = job();
    var resA = lock(a)
    var resB = lock(b)
    var resC = lock(c)
    assert(a.isRun)
    assert(b.isRun)
    assert(c.isRun)
    a.complete(sentA)
    resA.then(function (resA) {
      assert(resA === sentA)
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      b.fail(sentB)
      return resB
        .then(function () {
          throw new Error('b should have been rejected')
        }, function (errB) {
          assert(errB === sentB)
        })
    })
    .then(function () {
      assert(a.isRun)
      assert(b.isRun)
      assert(c.isRun)
      c.complete(sentC)
      return resC
    })
    .then(function (resC) {
      assert(resC === sentC)
    })
    .nodeify(done)
  })
})
Esempio n. 30
0
function withOptions(opts, fn) {
  testit('options: ' + utils.inspect(opts), function () {
    options = opts;
    fn();
  });
}