Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var buster = require('buster');
require('shelljs/global');
buster.testCase('bin', {
setUp: function () {
// assume Jenkins is already up and running on http://localhost:8080
},
tearDown: function () {
},
'build - should exit with code 1 when job does not exist': function () {
var result = exec('nestor build somenonexistingbuild');
assert.equals(result.code, 1);
assert.equals(result.output, 'Job somenonexistingbuild does not exist\n');
},
'console - should exit with code 1 when job does not exist': function () {
var result = exec('nestor console somenonexistingbuild');
assert.equals(result.code, 1);
assert.equals(result.output, 'Job somenonexistingbuild does not exist\n');
},
'stop - should exit with code 1 when job does not exist': function () {
}('categorizr', this, function(name, context) {
// faking a request
context.request = {
headers: {
'user-agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) RockMelt/0.8.34.841 Chrome/6.0.472.63 Safari/534.3'
}
}
var buster = require('buster')
, categorizr = require('./../')
buster.testCase('properties', {
'categorizr loaded': function () {
assert(!!categorizr)
}
, 'isWindow test returns false': function () {
assert(context != null)
assert(context !== context.window)
}
, 'isNode test returns false': function () {
assert(context != null)
assert(context !== context.window)
}
})
}))
var buster = require("buster"),
lib = require('../../libs/db.js');
// the purpose of that test case is to check the proper numbering of prepared
// statements arguments
buster.testCase("sql", {
"ps building": function(){
var conditions = [];
var sql = "select * from message";
conditions.push("to_tsvector($1, content) @@ plainto_tsquery($1,$2)");
conditions.push("room=$1");
conditions.push("author=$1");
conditions.push("truc is null");
conditions.push("field1=$2 or (field2=$1 and field3=$2)");
var postConditions = "order by message.id desc limit $1 offset $2";
var expected = "select * from message where (to_tsvector($1, content) @@ plainto_tsquery($1,$2)) and (room=$3)"+
" and (author=$4) and (truc is null) and (field1=$6 or (field2=$5 and field3=$6)) order by message.id desc limit $7 offset $8";
buster.assert.equals(lib.ps(sql, conditions, postConditions), expected);
}
});
assert(ender.isTablet === false)
assert(ender.isMobile === false)
}
, 'set tvs as desktops': function () {
ender.categorizr('tv')
ender.categorizr('tv', 'desktop')
assert(ender.categorizr() === 'desktop')
assert(ender.isDesktop === true)
assert(ender.isMobile === false)
assert(ender.isTv === false)
assert(ender.isTablet === false)
}
})
buster.testCase('events', {
prepare: function () {
ender.categorizr('mobile')
}
, conclude: function () {
ender(window).unbind('deviceChange')
}
, 'changing deviceType should trigger an event': function (done) {
ender(window).bind('deviceChange', function(device) {
console.log("deviceChange", arguments)
assert(device.type === 'tablet')
done()
})
ender.categorizr('tablet')
}
var buster = require("buster"),
lib = require('../../libs/naming.js');
function trd(input, output){
buster.assert.equals(lib.removeDiacritics(input), output);
}
function tsu(input, regex){
//~ console.log(input, '=>', lib.suggestUsername(input));
buster.assert.match(lib.suggestUsername(input), regex);
}
function tmmc(input, output){
buster.assert.equals(lib.makeMarkdownCompatible(input), output);
}
buster.testCase("naming", {
"remove diacritics": function(){
trd("chaîne", "chaine");
trd("quelques mots accentués ou à cédille en Français", "quelques mots accentues ou a cedille en Francais");
trd("Münshen", "Munshen");
trd(
"Dès lors les voyelles et consonne accompagnées d’un signe diacritique"+
" connues de la langue française sont : à - â - ä - é - è - ê - ë - ï - î - ô - ö - ù - û - ü - ÿ - ç",
"Des lors les voyelles et consonne accompagnees d’un signe diacritique"+
" connues de la langue francaise sont : a - a - a - e - e - e - e - i - i - o - o - u - u - u - y - c"
);
trd(
"À Â Ä Ç É È Ê Ë Î Ï Ô Ö Ù Û Ü",
"A A A C E E E E I I O O U U U"
);
trd("L'Haÿ-les-Roses", "L'Hay-les-Roses");
trd("天空中我失去了我的化油器!", "天空中我失去了我的化油器!");
assert(categorizr.isTablet === false)
assert(categorizr.isMobile === false)
}
, 'set tvs as desktops': function () {
categorizr('tv')
categorizr('tv', 'desktop')
assert(categorizr() === 'desktop')
assert(categorizr.isDesktop === true)
assert(categorizr.isMobile === false)
assert(categorizr.isTv === false)
assert(categorizr.isTablet === false)
}
})
buster.testCase('events', {
'//changing deviceType should not trigger an event': function () {}
})
function expression(expr, result, model, cntx, controller) {
if (expr instanceof Array) {
for (var i = 0, x, length = expr.length; i < length; i++) {
x = expr[i];
expression(x, result, model, cntx, controller);
}
return;
}
var ast = Expression.parse(expr),
value = Expression.eval(ast, model, cntx, controller);
assert.equals(value, result, 'Unexpected Result (' + expr + ')');
}
buster.testCase("Expressions", {
'concat': function() {
expression([ //
'5+"hello"', //
' 5 + "hello"', //
' 5 + "hello" + ""', //
'"" + 5 + "hello"', //
"'' + 5 + 'hello'", "'' + 5 + 'h' + 'e' + \"l\" + 'l' + 'o'", "'' + ('5' + 'h' + 'e') + (\"l\" + 'l' + 'o')", //
"'' + ('5' + ('h' + 'e') + (\"l\" ) + 'l' + 'o')", //
"5 + fn()", //
"5 + fn2()", //
"5 + hello", //
"1 + 2*2 + hello"], '5hello', {
hello: "hello",
fn: function() {
return "hello";
}
[1.99999999, "2", "2", "-2", "0.5", "2"],
[0.047, "0.05", "0.047", "-0.047", "21.277", "0.047"],
[0.0047, "4.7e-3", "0.005", "-0.005", "212.766", "0.0047"],
[0.00047, "4.7e-4", "4.7e-4", "-4.7e-4", "2127.66", "0.0005"],
[0.000047, "4.7e-5", "4.7e-5", "-4.7e-5", "21276.596", "4.7e-5"],
[4.7e-8, "4.7e-8", "4.7e-8", "-4.7e-8", "2.128e+7", "4.7e-8"],
[4.7e-15, "4.7e-15", "4.7e-15", "-4.7e-15", "2.128e+14", "4.7e-15"],
[1e-50,"1.e-50","1.e-50","-1.e-50","1.e+50","1.e-50"],
[1e+50, "1.e+50", "1.e+50", "-1.e+50", "1.e-50", "1.e+50"],
[3.141592653589793, "3.14", "3.142", "-3.142", "0.318", "3.1416"],
[8769956796.082695, "8.77e+9", "8.77e+9", "-8.77e+9", "1.14e-10", "8.77e+9"],
[NaN, "NaN", "NaN", "NaN", "NaN", "NaN"],
[0, "0", "0", "0", "Infinity", "0"]
];
buster.testCase("Formatting - float", tests.reduce((m, t) => {
m[t] = function(){
let v = t[0];
let res = [v, float(v, 2), float(v, 3), float(-v, 3), float(1/v, 3), float(v, 4)];
buster.assert.equals(t, res);
};
return m;
}, {}));
var buster = require('buster');
var assert = buster.assert;
var refute = buster.refute;
var fail = buster.assertions.fail;
var filter = require('../../load/predicate');
buster.testCase('predicate', {
'composePredicates': {
'should compose a function that calls matchPackage predicate when package property is present': function () {
var matchPackage = this.spy();
var matchPattern = this.spy();
var matchExtension = this.spy();
var f = { package: 'foo' };
var predicate = filter.composePredicates(matchPackage, matchPattern, matchExtension, f);
assert.isFunction(predicate);
predicate();
assert.calledOnce(matchPackage);
refute.called(matchPattern);
refute.called(matchExtension);
},
'should compose a function that calls matchPattern predicate when pattern property is present': function () {
var matchPackage = this.spy();