How to use the tap.match function in tap

To help you get started, we’ve selected a few tap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tapjs / stack-utils / test / at.js View on Github external
'use strict';
// some capture edge cases not already covered by other tests

const StackUtils = require('../');
const t = require('tap');

const stack = new StackUtils();

// a capture with no function, not much to it, actually
const base = __filename.slice(process.cwd().length + 1).replace(/\\/g, '/');
t.match(stack.at(), { line: Number, column: Number, file: base });

// a capture from a native site
const arr = [ 0 ];
const captures = arr.map(function xyz () {
  return stack.at(xyz);
});
t.match(captures, [ {
  type: 'Array',
  function: 'map'
} ]);
github npm / pacote / test / util / git / opts.js View on Github external
const t = require('tap')
const gitOpts = require('../../../lib/util/git/opts.js')
const gitEnv = require('../../../lib/util/git/env.js')

t.match(gitOpts().env, gitEnv(), 'got the git env by default')

t.test('as root', t => {
  process.getuid = () => 0
  t.match(gitOpts({
    foo: 'bar',
    env: { override: 'for some reason' },
  }, {
    uid: 420,
    gid: 69,
    abc: 'def',
  }), {
    foo: 'bar',
    env: { override: 'for some reason' },
    uid: 420,
    gid: 69,
    abc: undefined,
github YahooArchive / mendel / test / tree-hash-walker.js View on Github external
Copyrights licensed under the MIT License.
   See the accompanying LICENSE file for terms. */

var t = require('tap');

var MendelHashWalker = require('../packages/mendel-core/tree-hash-walker');
t.equal(MendelHashWalker().constructor, MendelHashWalker, 'constructor');

var validHash = 'bWVuZGVsAQD_AQAGH7IIQx23k7vTZFt6FgWKHiokEg';
var walker = new MendelHashWalker(validHash);
t.equal(walker.error, null, 'Initialized without errors');

walker.decoded.branches = [3];
var module = {data:[null, null, null, {id:'3'}]};

t.match(walker._resolveBranch(module), {
    index: 3,
    resolved: module.data[3],
}, 'pulls module based on decoded branches');

module = {data:[{id:'foo'}, {id:'bar'}]};

t.match(walker._resolveBranch(module), {
    index: undefined,
    resolved: {},
}, 'won\'t throw with wrong data');

t.match(walker.error, new Error());
t.equal(walker.error.message, 'Tree has more paths than hash',
    'error message');
t.equal(walker.error.code, 'TRVRSL',
    'error code');
github YahooArchive / mendel / test / require-transform.js View on Github external
var src = [
    'var foo = require(\'foo\');',
    'var bar = require(\'some/dir/variation1/bar\');',
    'var baz = require(\'some/dir/variation2/baz\');',
    'var qux = require(\'some/dir/base/qux\');',
].join('\n');

var mendelifiedModules = ['bar', 'baz', 'qux'];
var out = requireTransform('./', src, variationDirs, false);

mendelifiedModules.forEach(function(mod) {
    t.match(out, '__mendel_require__(\'' + mod + '\')', 'mendelified require');
    t.notMatch(out, 'require(\'' + mod + '\')', 'node require');
});

t.match(out, 'require(\'foo\')', 'node require');
t.notMatch(out, '__mendel_require__(\'foo\')', 'mendelified require');

t.equal(out.indexOf(wrapper[0]), -1, 'wrapper prelude not present');
t.equal(out.indexOf(wrapper[1]), -1, 'wrapper epilogue not present');

out = requireTransform('./', src, variationDirs, true);
t.equal(out.indexOf(wrapper[0]), 0, 'wrapper prelude pos');
t.equal(out.indexOf(wrapper[1]), out.length - wrapper[1].length, 'wrapper epilogue pos');
github fastify / fastify-autoload / test / error.js View on Github external
app.ready(function (err) {
  t.type(err, SyntaxError)
  t.match(err.message, /Unexpected token '?\}'? at .*\/test\/error\/lib\/a.js:6/)
})
github YahooArchive / mendel / test / variations.js View on Github external
experiment_B: null,
        experiment_C: ['experiment_A'],
    },
};
expected = [{
    id: 'experiment_A',
    chain: ['experiment_A', '_default'],
}, {
    id: 'experiment_B',
    chain: ['experiment_B', '_default'],
}, {
    id: 'experiment_C',
    chain: ['experiment_C', 'experiment_A', '_default'],
}];

t.match(parseVariations(config), expected,
    'flat directory structure example');
github YahooArchive / mendel / test / config.js View on Github external
}, 'skip file config option for CLI use');

t.match(config({
    basedir: path.resolve(where),
    outdir: path.resolve(where, 'myoutdir'),
    bundlesoutdir: path.resolve(where, 'myoutdir/le-bundles'),
    serveroutdir: path.resolve(where, 'myoutdir/le-node'),
}), {
    basedir: path.resolve(where),
    outdir: path.resolve(where, 'myoutdir'),
    bundlesoutdir: path.resolve(where, 'myoutdir/le-bundles'),
    serveroutdir: path.resolve(where, 'myoutdir/le-node'),
}, 'leaves absolite paths untouched');

where = './config-samples/3/';
t.match(config(where), {
    basedir: path.resolve(__dirname),
    outdir: path.resolve(__dirname, 'config-samples/mendel'),
}, 'ignores package.json that don\'t contain \'mendel\' entry');

opts = {
    outdir: '../build',
    bundleName: 'testBundle',
};
t.match(config(opts), {
    basedir: path.resolve(__dirname),
    outdir: path.resolve(__dirname, '../build'),
    bundleName: 'testBundle',
}, 'custom bundleName and outdir');

where = './config-samples';
t.match(config(where), {
github YahooArchive / mendel / test / variations.js View on Github external
t.match(parseVariations({}), [],
    'fails gracefully without variations');


var config = {
    base: 'test_base',
    variations: {
        folder_A: null,
        doNotExist: null,
    },
};
var expected = [{
    id: 'folder_A',
    chain: ['folder_A', 'test_base'],
}];
t.match(parseVariations(config), expected,
    'makes sure folders exists, honors config.base');

config.basetree = 'tree1';
expected[0].chain[1] = 'tree1';

t.match(parseVariations(config), expected,
    'config.basetree preceedes config.base');

delete config.basetree;
delete config.base;
expected[0].chain[1] = rootDir;

t.match(parseVariations(config), expected,
    'fallback to basedir to current dir');

rootDir = path.resolve(__dirname, './variation-samples/1/');
github YahooArchive / mendel / test / variations.js View on Github external
experiment_C: ['folder_C'],
        experiment_D: ['folder_C', 'folder_A'],
    },
};
expected = [{
    id: 'experiment_A',
    chain: ['folder_A', 'base'],
}, {
    id: 'experiment_C',
    chain: ['folder_C', 'base'],
}, {
    id: 'experiment_D',
    chain: ['experiment_D', 'folder_C', 'folder_A', 'base'],
}];

t.match(parseVariations(config), expected,
    'grouped variation dirs complex example');

rootDir = path.resolve(__dirname, './variation-samples/2/');
process.chdir(rootDir);

config =  {
    base: 'default',
    basedir: 'src',
    basetree: '_default',
    variations: {
        experiment_A: null,
        experiment_B: null,
        experiment_C: ['experiment_A'],
    },
};
expected = [{
github YahooArchive / mendel / test / config.js View on Github external
process.chdir(path.resolve(__dirname));

where = './config-samples/1/';
t.match(config(where), {basedir: path.resolve(where)},
    'find .mendelrc, basedir defaults to it\'s path');

t.match(config({
    basedir: path.resolve(where),
    config: false,
}), {
    bundles: [],
}, 'skip file config option for CLI use');

t.match(config({
    basedir: path.resolve(where),
    outdir: path.resolve(where, 'myoutdir'),
    bundlesoutdir: path.resolve(where, 'myoutdir/le-bundles'),
    serveroutdir: path.resolve(where, 'myoutdir/le-node'),
}), {
    basedir: path.resolve(where),
    outdir: path.resolve(where, 'myoutdir'),
    bundlesoutdir: path.resolve(where, 'myoutdir/le-bundles'),
    serveroutdir: path.resolve(where, 'myoutdir/le-node'),
}, 'leaves absolite paths untouched');

where = './config-samples/3/';
t.match(config(where), {
    basedir: path.resolve(__dirname),
    outdir: path.resolve(__dirname, 'config-samples/mendel'),
}, 'ignores package.json that don\'t contain \'mendel\' entry');