Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log(
` expected:\n${chalk.blue(
indentLines(8, JSON.stringify(data.expected, null, 2))
)}`
);
console.log(
` actual :\n${chalk.blue(
indentLines(8, JSON.stringify(data.actual, null, 2))
)}`
);
}
console.log("");
}
}
});
const harness = tape.getHarness({
exit: false,
stream: parser,
objectMode: true,
});
let testFiles = specifiedFiles;
if (testFiles.length === 0) {
if (chatty) {
console.log(chalk.blue(`looking for tests in ${srcDir}`));
}
testFiles = glob("**/*[.-]spec.ts", { cwd: srcDir });
if (!thorough) {
// exclude files containing slow.spec if not during a thorough run
testFiles = testFiles.filter(f => !/slow\.spec/.test(f));
}
}
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();
});
const t = require('tape');
const sc = require('skale').context();
const data = [['hello', 1], ['hello', 1], ['world', 1]];
const nPartitions = 2;
const init = 0;
function reducer(a, b) {return a + b;}
function combiner(a, b) {return a + b;}
t.test('aggregateByKey', function (t) {
t.plan(1);
sc.parallelize(data, nPartitions)
.aggregateByKey(reducer, combiner, init)
.collect(function(err, res) {
t.deepEqual(res, [['hello', 2], ['world', 1]]);
sc.end();
});
});
// TODO: test passing args in combiner / reducer
// TODO: test using worker contex in combiner / reducer
var aXorBCtor = xorStreamCtor(streamACtor, streamBCtor)
test('compare longer file to shorter file', function (t) {
// this fails right now
t.plan(2)
var xorB = xorStream(aXorBCtor(), streamBCtor())
streamEqual(streamACtor(), xorB, function (err, equal) {
t.error(err, 'streams compared without error')
t.ok(equal, 'equal pairity output')
})
})
test.skip('compare shorter file to longer file', function (t) {
t.plan(2)
var xorA = xorStream(aXorBCtor(), streamACtor())
streamEqual(streamBCtor(), xorA, function (err, equal) {
t.error(err, 'streams compared without error')
t.ok(equal, 'equal pairity output')
})
})
test('compare stings', function (t) {
t.plan(2)
var strA = crypto.randomBytes(1000).toString('hex')
var strB = crypto.randomBytes(1000).toString('hex')
}
};
var webjack = require('../dist/webjack');
function read (file) {
return fs.readFileSync('./test/fixtures/' + file, 'utf8').trim();
}
function write (file, data) { /* jshint ignore:line */
return fs.writeFileSync('./test/fixtures/' + file, data + '\n', 'utf8');
}
test.skip('webjack has tests', function (t) {
// read('something.html')
t.equal(true, true);
t.end();
});
test('webjack module is exported', function (t) {
var conn = new webjack.Connection({audioCtx: AudioContext, navigator : navigator});
t.equal(typeof conn === 'object', true);
t.end();
});
t('Caching resource', t => {
let a = Audio('./chopin.mp3').on('load', (audio) => {
})
let b = Audio('./chopin.mp3').on('load', (audio) => {
})
assert.equal(Object.keys(Audio.cache).length === 1)
});
t.only('save', t => {
let a = Audio(lena, (err, a) => {
a.save('lena.wav', (err, a) => {
if (!isBrowser) {
let p = __dirname + path.sep + 'lena.wav'
assert.ok(fs.existsSync(p))
fs.unlinkSync(p);
}
t.end()
})
})
})
// t('create from buffer', t => {
// Audio(lena).volume(.5).play(() => {
// console.log('end');
* into tap-spec via node pipes rather than stdin / stdout.
*
* I found large auxiliary output (like console.log'ing a large table)
* would encounter buffering issues when using stdin / stdout.
*
* Never isolated exact cause, but creating and managing stream in
* Node explicitly seems to work.
*
* Unfortunately that tickles another issue: in-process streams
* wouldn't print summary information:
* See: https://github.com/scottcorgan/tap-spec/issues/37
* and https://github.com/scottcorgan/tap-spec/issues/37#issuecomment-268949364
* for my workaround.
*/
let htest = test.createHarness()
htest.createStream()
.pipe(formatter)
.pipe(process.stdout)
/*
htest.createStream()
.pipe(tapSpec())
.pipe(process.stdout)
*/
// A fetch polyfill using ReadFile that assumes url is relative:
function readFileAsync (file, options) {
return new Promise(function (resolve, reject) {
fs.readFile(file, options, function (err, data) {
if (err) {
}
$target.appendChild($line);
window.scrollTo(0, document.body.clientHeight);
}
['log', 'error', 'info'].forEach(k => {
var original = console[k];
console[k] = function (...args) {
addLine(k, [...args].join(' '));
original.call(console, ...args);
};
});
// Wait for tape to finish
const tapeResults = require("tape").getHarness()._results;
tapeResults.on("done", function (): void {
const payload = {
total: tapeResults.count,
passed: tapeResults.pass,
failed: tapeResults.fail,
};
const xhr = new XMLHttpRequest();
xhr.open("POST", `http://localhost:5001?id=${id}`, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Origin", location.origin);
xhr.send(JSON.stringify(payload));
xhr.onerror = function () {
console.error(`collector ${id} failed:`, xhr.status, xhr.responseText);
console.error(xhr.getAllResponseHeaders());
};