// validate error function (err) { test.same(error, [ err ], 'an error array should be returned') test.equal(err.userId, 1, 'error should be decorated with `userId`') test.equal(err.channel, 'foo', 'error should be decorated with `channel`') test.equal(err.target, 'bar', 'error should be decorated with `target`') test.equal(counter, 13, 'callback should be called in the next tick') },
function testOption (envVar, tmpVal, expect) { delete process.env[envVar] process.env[envVar] = tmpVal t.same(options(), expect) delete process.env[envVar] }
tap.test('config uses passed in headers', async test => { var headers = { foo: 'bar', 'User-Agent': 'something' } var options = { headers } var reqOptions = await config(options) tap.same(reqOptions.headers, headers, 'headers are the same') return test.done() })
tap.test('users defined headers takes prescient', async test => { var headers = { foo: 'bar', 'User-Agent': 'something', 'Content-Type': 'json' } var options = { headers, data: 'http://html5.validator.nu' } var reqOptions = await config(options) tap.same(reqOptions.headers, headers, 'user headers take prescient') return test.done() })
iface.LongProcess({ timeout: 1000 }, function(err, result) { tap.notSame(err, null); tap.same(result, null); done(); bus.disconnect(); });
function () { n.unregister(1, 'foo', 'bar', callback()) test.same(db, { '1': { foo: [] } }, 'target should be removed') test.equal(counter, 2, 'callback should be called in the next tick') },
var t = require('tap') var req = require('..') t.ok( setEqual(req({ cwd: __dirname + '/fixture1/dir' }), [2, 1]), 'basic functionality' ) t.ok( setEqual(req({ cwd: './test/fixture1/dir' }), [2, 1]), 'relative require' ) t.same( req(['**/*.js', '!b.data.js'], { cwd: __dirname + '/fixture1/dir'}), [1], 'globs' ) t.same(req({ cwd: __dirname + '/fixture_nonexistent' }), [], 'modules missing') t.test('glob without cwd', function(t) { var result3 = req('test/fixture1/**/*.data.js') t.ok(setEqual(result3, [3, 2, 1])) t.end() }) t.test("return path", function(t) { var result = req({ cwd: __dirname + '/fixture1/dir', returnPath: true }) t.ok(setEqual(result, [['b.data.js', 2], ['a.data.js', 1]], orderEqual)) t.end()
(() => { var v = v3.copy(); tap.notEqual(v3, v, "Copy with no arguments should clone"); tap.equal(v3.x, v.x, " -- but with same properties"); tap.equal(v3.y, v.y, " -- but with same properties"); })(); (() => { var v = new Vector2(); v3.copy(v); // Should this be swapped around?? tap.notEqual(v3, v, "Copy should be a different instance"); tap.equal(v3.x, v.x, " -- but with same properties"); tap.equal(v3.y, v.y, " -- but with same properties"); })(); tap.same(v2.toString(), "(3,4)", "toString"); (() => { var v = new Vector2(3, 7); var v_ = v.plus(v3); tap.notEqual(v_, v, "plus results in new instance"); tap.equal(v3.x + 3, v_.x, "plus"); tap.equal(v3.y + 7, v_.y, "plus"); var v = new Vector2(3, 7).add(v3); tap.equal(v3.x + 3, v.x, "add"); tap.equal(v3.y + 7, v.y, "add"); })(); (() => { var v = new Vector2(3, 7);
var t = require('tap') Object.defineProperty(process, 'platform', { value: 'win32' }) const ini = require('../ini.js') const res = ini.encode({foo: { bar: 'baz' }}) t.equal(res, "[foo]\r\nbar=baz\r\n") t.equal(ini.encode({bar: 'baz'}, 'foo'), '[foo]\r\nbar=baz\r\n') t.same(ini.decode('=just junk!\r\n[foo]\r\nbar\r\n'), { foo: { bar: true }}) t.same(ini.decode('[x]\r\ny=1\r\ny[]=2\r\n'), { x: { y: [1, 2] } }) t.equal(ini.unsafe(''), '') t.equal(ini.unsafe('x;y'), 'x') t.equal(ini.unsafe('x # y'), 'x') t.equal(ini.unsafe('x "\\'), 'x "\\')
var tap = require('tap'), sarnie = require('..'), parser = require('../lib/parser'), FIXTURES = require('./fixtures'); require('array.from').shim(); // It should return the string unaltered if the array has a single element tap.same(parser(sarnie(['albero'], '(', '|', ')'), '(', '|', ')'), ['albero']); // Strings without a common radix tap.same(parser(sarnie(['a', 'b', 'c'], '(', '|', ')'), '(', '|', ')'), ['a', 'b', 'c']); tap.same(parser(sarnie(FIXTURES.ARRAYS.ALBERO_FIORE, '(', '|', ')'), '(', '|', ')'), Array.from(FIXTURES.ARRAYS.ALBERO_FIORE).sort()); // Strings with a common radix tap.same(parser(sarnie(FIXTURES.ARRAYS.ALB_A_ER_GO_O_TO, '(', '|', ')'), '(', '|', ')'), Array.from(FIXTURES.ARRAYS.ALB_A_ER_GO_O_TO).sort()); tap.same(parser(sarnie(FIXTURES.ARRAYS.PESCA_TORE_H_ERIA_IERA, '(', '|', ')'), '(', '|', ')'), Array.from(FIXTURES.ARRAYS.PESCA_TORE_H_ERIA_IERA).sort()); tap.same(parser(sarnie(FIXTURES.ARRAYS.MARE_INA_IO_IA, '(', '|', ')'), '(', '|', ')'), Array.from(FIXTURES.ARRAYS.MARE_INA_IO_IA).sort()); // Mixed strings tap.same(parser(sarnie(FIXTURES.ARRAYS.ALB_A_ER_GO_O_TO .concat(FIXTURES.ARRAYS.PESCA_TORE_H_ERIA_IERA), '(', '|', ')'), '(', '|', ')'), Array.from(FIXTURES.ARRAYS.ALB_A_ER_GO_O_TO.concat(FIXTURES.ARRAYS.PESCA_TORE_H_ERIA_IERA).sort())); // Order of input doesn't matter tap.same(parser(sarnie(FIXTURES.ARRAYS.ALBERO_FIORE, '(', '|', ')'), '(', '|', ')'), parser(sarnie(Array.from(FIXTURES.ARRAYS.ALBERO_FIORE).reverse(), '(', '|', ')'), '(', '|', ')'));
'use strict'; // Testcase for returning report as a string via API call if (process.argv[2] === 'child') { const nodereport = require('../'); console.log(nodereport.getReport()); } else { const common = require('./common.js'); const spawnSync = require('child_process').spawnSync; const tap = require('tap'); const args = [__filename, 'child']; const child = spawnSync(process.execPath, args); tap.plan(3); tap.strictSame(child.stderr.toString(), '', 'Checking no messages on stderr'); const reportFiles = common.findReports(child.pid); tap.same(reportFiles, [], 'Checking no report files were written'); tap.test('Validating report content', (t) => { common.validateContent(child.stdout, t, { pid: child.pid, commandline: process.execPath + ' ' + args.join(' ') }); }); }
var tap = require('tap'), sarnie = require('..'), FIXTURES = require('./fixtures'); require('array.from').shim(); // It doesn't mutate the input array var reversed = Array.from(FIXTURES.ARRAYS.ALBERO_FIORE).reverse(); sarnie(reversed, '(', '|', ')'); tap.same(reversed, Array.from(FIXTURES.ARRAYS.ALBERO_FIORE).reverse()); reversed = Array.from(FIXTURES.ARRAYS.ALB_A_ER_GO_O_TO).reverse(); sarnie(reversed, '(', '|', ')'); tap.same(reversed, Array.from(FIXTURES.ARRAYS.ALB_A_ER_GO_O_TO).reverse()); // It should return the string unaltered if the array has a single element tap.equal(sarnie(['albero'], '(', '|', ')'), 'albero'); // Strings without a common radix tap.equal(sarnie(['a', 'b', 'c'], '(', '|', ')'), 'a|b|c'); tap.equal(sarnie(FIXTURES.ARRAYS.ALBERO_FIORE, '(', '|', ')'), 'albero|fiore'); // Strings with a common radix tap.equal(sarnie(FIXTURES.ARRAYS.ALB_A_ER_GO_O_TO, '(', '|', ')'), 'alb(a|er(go|o|to))'); tap.equal(sarnie(FIXTURES.ARRAYS.PESCA_TORE_H_ERIA_IERA, '(', '|', ')'), 'pesc(a(|tore)|h(eria|iera))'); tap.equal(sarnie(FIXTURES.ARRAYS.MARE_INA_IO_IA, '(', '|', ')'), 'mar(e|i(a|na(|io)|o))'); // Mixed strings tap.equal(sarnie(FIXTURES.ARRAYS.ALB_A_ER_GO_O_TO.concat(FIXTURES.ARRAYS.PESCA_TORE_H_ERIA_IERA), '(', '|', ')'), 'alb(a|er(go|o|to))|pesc(a(|tore)|h(eria|iera))'); // Order of input doesn't matter
fileUtilities.importSingleFile(fileRecord4,function(resp){ tap.same( resp.tema,expectedTema4,'tema estratto correttamente da fileRecord3') tap.same(resp.recordFile,expectedFile4,'recordFIle3 generato correttamente') })
wang: false }, expectedFile2 = { data: new Date('2016-01-26'), scuola:'MI', fase: 'Fase B', fogueo_istruttori:false, fogueo: true, titolo:'Fogueo Temi Fase A', relatore:'_', estensione:'.mp3', nomeFile:'2016-01-26 - MI - Fase B - Fogueo Temi Fase A - _.mp3', wang: false }, fileUtilities = require('../utilities/fileUtilities') tap.same(Tag.buildRecordFile(Tag.splitName(file1)),expected,'file1 tags:ok') tap.same(Tag.buildRecordFile(Tag.splitName(file2)),expected2,'file2 tags:ok') tap.true(Tag.checkTemaFase(file2),'è un tema di fase') tap.false(Tag.checkTemaFase(file1),'non è un tema di fase') tap.true(Tag.checkTemaFase(file3),'è un tema di fase') tap.same(Tag.splitTema('/8_Fase B/B25_Pratica Yin Yang'),['B25','Pratica Yin Yang','8_Fase B/B25_Pratica Yin Yang/'],'split tema') tap.same(Tag.buildTema(Tag.splitTema('/8_Fase B/B25_Pratica Yin Yang')),{code:'B25',titolo:'Pratica Yin Yang',fase:'B',relativePath:'8_Fase B/B25_Pratica Yin Yang/'},'Tema') fileUtilities.importSingleFile(fileRecord,function(resp){ tap.same(resp.tema, expectedTema,'tema estratto correttamente da fileRecord') tap.same(resp.recordFile,expectedFile,'recordFIle0 generato correttamente') }) fileUtilities.importSingleFile(fileRecord2,function(resp){ tap.same(resp.tema, expectedTema2,'tema estratto correttamente da fileRecord2') tap.same(resp.recordFile,expectedFile2,'recordFIle2 generato correttamente') })
function runTests (Map) { t.throws(Map) var m = new Map() t.equal(m.size, 0) m.set(1, '1 string') t.equal(m.get(1), '1 string') t.equal(m.size, 1) m.size = 1000 t.equal(m.size, 1) m.size = 0 t.equal(m.size, 1) m = new Map([[1, 'number 1'], ['1', 'string 1']]) t.equal(m.get(1), 'number 1') t.equal(m.get('1'), 'string 1') t.equal(m.size, 2) m = new Map(m) t.equal(m.get(1), 'number 1') t.equal(m.get('1'), 'string 1') t.equal(m.size, 2) var akey = {} var bkey = {} m.set(akey, { some: 'data' }) m.set(bkey, { some: 'other data' }) t.same(m.get(akey), { some: 'data' }) t.same(m.get(bkey), { some: 'other data' }) t.equal(m.size, 4) var x = /x/ var y = /x/ m.set(x, 'x regex') m.set(y, 'y regex') t.equal(m.get(x), 'x regex') m.set(x, 'x again') t.equal(m.get(x), 'x again') t.equal(m.size, 6) m.set(NaN, 'not a number') t.equal(m.get(NaN), 'not a number') m.set(NaN, 'it is a ' + typeof NaN) t.equal(m.get(NaN), 'it is a number') m.set('NaN', 'stringie nan') t.equal(m.get(NaN), 'it is a number') t.equal(m.get('NaN'), 'stringie nan') t.equal(m.size, 8) m.delete(NaN) t.equal(m.get(NaN), undefined) t.equal(m.size, 7) var expect = [ { value: 'number 1', key: 1 }, { value: 'string 1', key: '1' }, { value: { some: 'data' }, key: {} }, { value: { some: 'other data' }, key: {} }, { value: 'x again', key: /x/ }, { value: 'y regex', key: /x/ }, { value: 'stringie nan', key: 'NaN' } ] var actual = [] m.forEach(function (value, key) { actual.push({ value: value, key: key }) }) t.same(actual, expect) m.clear() t.equal(m.size, 0) }
const t = require('tap') const options = require('../lib/cli-options') t.plan(2) t.same(options(['node', '-e', "'console.log(testing)'", 'dotenv_config_encoding=utf8']), { encoding: 'utf8' }) t.same(options(['node', '-e', "'console.log(testing)'", 'dotenv_config_path=/custom/path/to/your/env/vars']), { path: '/custom/path/to/your/env/vars' })
delete process.env[envVar] process.env[envVar] = tmpVal t.same(options(), expect) delete process.env[envVar] } t.plan(4) // returns empty object when no options set in process.env delete process.env.DOTENV_CONFIG_ENCODING delete process.env.DOTENV_CONFIG_PATH delete process.env.DOTENV_CONFIG_DEBUG t.same(options(), {}) // sets encoding option testOption('DOTENV_CONFIG_ENCODING', 'latin1', { encoding: 'latin1' }) // sets path option testOption('DOTENV_CONFIG_PATH', '~/.env.test', { path: '~/.env.test' }) // sets debug option testOption('DOTENV_CONFIG_DEBUG', 'true', { debug: 'true' }) // restore existing env process.env.DOTENV_CONFIG_ENCODING = e process.env.DOTENV_CONFIG_PATH = p process.env.DOTENV_CONFIG_DEBUG = d
// validate error function (err) { test.same(error, [ err ], 'an error array should be returned') test.equal(counter, 15, 'callback should be called in the next tick') },
t.similar(inserter.toArray(), [8,2,3,5,4,1]) t.similar(swiped.toArray(), [9,7]) swiped = Yallist(9,8,7) inserter.pushNode(swiped.head.next) t.similar(inserter.toArray(), [8,2,3,5,4,1,8]) t.similar(swiped.toArray(), [9,7]) swiped.unshiftNode(Yallist.Node(99)) t.similar(swiped.toArray(), [99,9,7]) swiped.pushNode(Yallist.Node(66)) t.similar(swiped.toArray(), [99,9,7,66]) var e = Yallist() e.unshiftNode(Yallist.Node(1)) t.same(e.toArray(), [1]) e = Yallist() e.pushNode(Yallist.Node(1)) t.same(e.toArray(), [1]) // steal them back, don't break the lists swiped.unshiftNode(inserter.head) t.same(swiped, Yallist(8,99,9,7,66)) t.same(inserter, Yallist(2,3,5,4,1,8)) swiped.unshiftNode(inserter.tail) t.same(inserter, Yallist(2,3,5,4,1)) t.same(swiped, Yallist(8,8,99,9,7,66)) t.throws(function remove_foreign_node () { e.removeNode(swiped.head)
function () { n.unregister(1, 'foo', 'baz', callback()) test.same(db, { '1': { foo: [ 'bar' ] } }, 'absent target should not affect anything') test.equal(counter, 1, 'callback should be called in the next tick') },
"use strict" module.exports = partial const tap = require("tap") const curry = require("./curry") const add = (a,b, c) => a + b + c function partial(f, ...args) { return curry(f).bind(f, ...args) } tap.equal( curry(add)(1)(2)(3), 6, "should be equal to 6") let a = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] const take = (n, list, accu = []) => { if(list.length === 0 || n === 0) return accu accu.push(list[0]) return take( n - 1, list.slice(1), accu ) } const take5 = partial(take, 5) tap.same(take5(a), take(5, a), "A dyadic function should return the same as a partial monadic function made of that dyadic function.")
a.rename(fixtures.b.name); tap.equals(Entity.inspect(a).version, 1, 'Instance version should be 1'); tap.equals(a.name, fixtures.b.name, `Instance name should be ${fixtures.b.name}`); a.save(); tap.equals(Entity.inspect(a).version, 2, 'Instance version should be 2'); tap.equals(Entity.inspect(a).history.length, 2, 'Instance history should contain 2 entries'); a.touch(); tap.equals(Entity.inspect(a).version, 2, 'Instance version should be 2'); tap.equals(Entity.inspect(a).history.length, 2, 'Instance history should contain 2 entries'); tap.same(Entity.snapshot(a), { name: fixtures.b.name, email: fixtures.a.email, foo: 'bar', }, 'Instance snapshot should...'); // tap.test('Instance should emit "saved" event', t => { // i.on('saved', () => { // t.equals(Entity.version(i), 1, 'Instance version should be 1'); // t.equals(Entity.history(i).length, 1, 'Instance history should have one event'); // // t.same(Entity.snapshot(i), { // // version: 1, // // changeset: i, // // }, 'Instance snapshot should...'); // t.end(); // }); // i.save(); // });