Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import test from 'tape';
import { SES } from '../src/index';
test('SES environment does not have def/harden as a global', t => {
const s = SES.makeSESRootRealm();
t.equal(typeof s.global.def, 'undefined');
function check() {
return def({}); // eslint-disable-line no-undef
}
t.throws(() => s.evaluate(`${check}; check()`), ReferenceError);
t.end();
});
test('SES environment does not have def/harden as a global despite requireMode', t => {
const s = SES.makeSESRootRealm({ requireMode: 'allow' });
t.equal(typeof s.global.def, 'undefined');
function check() {
return def({}); // eslint-disable-line no-undef
}
t.throws(() => s.evaluate(`${check}; check()`), ReferenceError);
t.true(Date.now() - now >= 5e3, '~> waited at least 5 seconds');
});
test('POST (string body w/ object url)', async t => {
t.plan(7);
const body = 'peter@klaven';
const uri = parse('https://reqres.in/api/login');
await httpie.post(uri, { body }).catch(err => {
t.is(err.message, 'Bad Request');
isResponse(t, err, 400, {
error: 'Missing email or username'
});
});
});
test('custom headers', async t => {
t.plan(2);
let headers = { 'X-FOO': 'BAR123' };
let res = await httpie.get('https://reqres.in/api/users', { headers });
let sent = res.req.getHeader('x-foo');
t.is(res.statusCode, 200, '~> statusCode = 200');
t.is(sent, 'BAR123', '~> sent custom "X-FOO" header');
});
function reviver(key, val) {
if (key.includes('_')) return; // removes
return typeof val === 'number' ? String(val) : val;
}
test('GET (reviver)', async t => {
t.plan(5);
// Tests
// -----
test('utils.pairs() gets pairs property from object', function(t) {
let data = {pairs: [['a'], [1]]};
let actual = pairs(data);
let expect = data.pairs;
t.deepEqual(actual, expect, 'should gets the value of pairs property');
data = {data: [1,2,3]};
t.notOk(pairs(data), 'should returns undefined is property is not in object');
t.end();
});
test('utils.containedIn() checks if collection contains item', function(t) {
let collection = [0,1,2,3,4];
t.ok(containedIn(collection, 2), 'should returns true if item is in collection');
t.notOk(containedIn(collection, 5), 'should returns false if item is not in collection');
t.end();
});
test('utils.rangeFrom0() create a range of indexes from 0', function(t) {
let actual = rangeFrom0(5);
let expect = [0,1,2,3,4];
t.deepEqual(actual, expect, 'should returns an array of indexes from 0');
t.end();
});
t.end()
})
test('add -- Handles if input is a string', t => {
t.is(add(1, '2'), 3)
t.end()
})
test('add -- Handles if both inputs are strings', t => {
t.is(add('1', '10'), 11)
t.end()
})
test('add -- Is curried', t => {
const adder = add(3)
t.is(adder(4), 7)
t.is(adder('4'), 7)
t.end()
})
test('add -- Handles more than just 2 params', t => {
t.same(add(1, 2, 3, 4), 10)
t.same(add(2, 3, 4, 5, 6), 20)
t.end()
})
import test from 'tape';
import _ from 'lodash';
test('compose ignores non objects', assert => {
const stamp = compose(0, 'a', null, undefined, {}, NaN, /regexp/);
const subject = _.values(stamp.compose).filter(_.negate(_.isEmpty)).length;
const expected = 0;
assert.equal(subject, expected,
'should not add any descriptor data');
assert.end();
});
test('compose in order', assert => {
const initOrder = [];
const getInitDescriptor = (value) => {
return {initializers: [() => initOrder.push(value)]};
};
var output = arcgisToGeoJSON(input);
t.deepEqual(output.coordinates, [
[
[41.8359375, 71.015625],
[21.796875, 36.5625],
[56.953125, 33.75],
[41.8359375, 71.015625]
]
]);
t.equal(output.type, 'Polygon');
});
test('should parse an ArcGIS Multipoint in a GeoJSON MultiPoint', function (t) {
t.plan(1);
var input = {
'points': [
[41.8359375, 71.015625],
[56.953125, 33.75],
[21.796875, 36.5625]
],
'spatialReference': {
'wkid': 4326
}
};
var output = arcgisToGeoJSON(input);
t.deepEqual(output.coordinates, [
}
proc(genFn()).done.catch(err => assert.fail(err))
const expected = ['call 1', 'call err'];
setTimeout(() => {
assert.deepEqual(actual, expected,
"processor must fullfill cps call effects"
);
assert.end();
}, DELAY)
});
test('processor array of effects handling', assert => {
assert.plan(1);
let actual;
const def = deferred()
let cpsCb = {}
const cps = (val, cb) => cpsCb = {val, cb}
const input = cb => {
Promise.resolve(1)
.then(() => def.resolve(1))
.then(() => cpsCb.cb(null, cpsCb.val))
.then(() => cb({type: 'action'}))
return () => {}
}
import isnumber from "../src/isnumber";
import test from "tape";
test("isnumber", function(t) {
t.plan(7);
t.equal(isnumber(1), true);
t.equal(isnumber(1.0), true);
t.equal(isnumber(1.5), true);
t.equal(isnumber("foo"), false);
t.equal(isnumber(NaN), false);
t.equal(isnumber(Number.POSITIVE_INFINITY), false);
t.equal(isnumber(Number.NEGATIVE_INFINITY), false);
});
test("Object3DMatrixContext(ctx: Context, initialState: Object) -> Function",
({ok, end}) => {
ok('function' == typeof Object3DMatrixContext(ctx, {}),
"Object3DMatrixContext constructor returns function.")
end()
})
test("Object3DMatrixContext(ctx: Context) can be called with 'new' operator",
({ok, end}) => {
ok(new Object3DMatrixContext(ctx), "Without error.")
end()
})
test("Object3DMatrixContext(ctx: Context) can be called without 'new' operator",
({ok, end}) => {
ok(Object3DMatrixContext(ctx), "Without error.")
end()
})
test("Object3DMatrixContext(ctx: Context) exposes localMatrix and " +
"transformMatrix context variables.",
({ok, plan, end}) => {
plan(6)
const context = Object3DMatrixContext(ctx)
context(({localMatrix, transformMatrix}) => {
ok(localMatrix, "localMatrix context variable is defined.")
ok(isTypedArray(localMatrix), "localMatrix context variable is typed array.")
ok(16 == localMatrix.length, "localMatrix context variable has 16 components.")
let promise = chunkify.reduce(['A', 'B', 'C', 'D'], fn, {chunk: 3, delay: 10});
t.equals(fn.callCount, 2);
return promise
},
after_tick(promise) {
t.equals(fn.callCount, 3);
promise.then((result) => {
t.deepEquals(result, 'a+b+c+d');
t.end()
})
}
});
});
test('should resolve with the reduced result from a given memo', t => {
let fn = sinon.spy((memo, letter, index, array) => {
return `${memo.toLowerCase()}+${letter.toLowerCase()}`
});
tick({
delay: 11,
before_tick() {
let promise = chunkify.reduce(
['A', 'B', 'C', 'D'], fn, {chunk: 3, delay: 10, memo: 'MEMO'});
t.equals(fn.callCount, 3);
return promise
},
after_tick(promise) {
t.equals(fn.callCount, 4);