How to use metatests - 10 common examples

To help you get started, we’ve selected a few metatests 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 metarhia / metasync / test / examples.js View on Github external
};

  const pf3 = (data, callback) => {
    test.pass('must call');
    setTimeout(() => callback(null, { data3: 'result3' }), ASYNC_TIMEOUT);
  };

  metasync.parallel([pf1, pf2, pf3], { arg: 'arg' }, (err, data) => {
    test.error(err);
    test.strictSame(data, expectedData);
  });
});

// Sequential execution

metatests.test('sequential', test => {
  test.plan(5);

  const sf1 = (data, callback) => {
    test.strictSame(data, ['arg']);
    setTimeout(() => callback(null, 'result1'), ASYNC_TIMEOUT);
  };

  const sf2 = (data, callback) => {
    test.pass('must call');
    setTimeout(() => callback(null, 'result2'), ASYNC_TIMEOUT);
  };

  const sf3 = (data, callback) => {
    test.strictSame(data, ['arg', 'result1', 'result2']);
    setTimeout(() => callback(null, 'result3'), ASYNC_TIMEOUT);
  };
github metarhia / metasync / test / examples.js View on Github external
f1();
  }, 1000);
  setTimeout(() => {
    state = 'I';
    f1();
  }, 1100);

  setTimeout(() => {
    test.strictSame(result, expectedResult);
    test.end();
  }, 2000);
});

// Debounce

metatests.test('debounce', test => {
  const expectedResult = ['E', 'I'];
  const result = [];
  let state;

  const fn = () => {
    result.push(state);
  };

  const f1 = metasync.debounce(500, fn, ['I']);

  // to be called one time (E)
  state = 'A';
  f1();
  state = 'B';
  f1();
  state = 'C';
github metarhia / metasync / test / examples.js View on Github external
} else {
          callback(null, item);
        }
      }, item * 10);
    },
    (error, result) => {
      test.isError(error);
      test.strictSame(result, undefined);
      test.end();
    }
  );
});

// Timeout

metatests.test('timeout', test => {
  metasync.timeout(
    200,
    done => {
      setTimeout(done, 300);
    },
    err => {
      const expectedErr = new Error(
        'Metasync: asynchronous function timed out'
      );
      test.isError(err, expectedErr);
      test.end();
    }
  );
});
github metarhia / common / test / curryN.js View on Github external
'use strict';

const metatests = require('metatests');
const common = require('..');

metatests.test('curryN', test => {
  const sum = (x, y, z) => x + y + z;
  const sumC = common.curryN(sum, 2, 1);
  const sumC2 = sumC(2);
  const res = sumC2(3);
  test.strictSame(res, 6);
  test.end();
});
github metarhia / common / test / replicate.js View on Github external
'use strict';

const metatests = require('metatests');
const common = require('..');

metatests.test('replicate', test => {
  const expected = [true, true, true, true, true];
  const result = common.replicate(5, true);
  test.strictSame(result, expected);
  test.end();
});
github metarhia / metasync / test / memoize.js View on Github external
'use strict';

const metasync = require('..');
const metatests = require('metatests');

metatests.test('memoize', test => {
  const storage = {
    file1: Buffer.from('file1'),
    file2: Buffer.from('file2'),
  };

  const getData = (file, callback) => {
    process.nextTick(() => {
      const result = storage[file];
      if (result) callback(null, result);
      else callback(new Error('File not found'));
    });
  };

  const memoizedGetData = metasync.memoize(getData);

  const keys = [];
github metarhia / common / test / zip.js View on Github external
'use strict';

const metatests = require('metatests');
const common = require('..');

metatests.test('zip', test => {
  const data = [[1, 2, 3], ['one', 'two', 'three'], ['один', 'два', 'три']];
  const expected = [[1, 'one', 'один'], [2, 'two', 'два'], [3, 'three', 'три']];
  const res = common.zip(...data);
  test.strictSame(res, expected);
  test.end();
});

metatests.test('zip with no elements', test => {
  const res = common.zip();
  test.strictSame(res, []);
  test.end();
});
github metarhia / globalstorage / test / cursor.transaction.js View on Github external
    ({ name, test }) => (data, done) => metatests.test(name, test(done))
  ))(done);
github metarhia / globalstorage / test / pg.ddl.js View on Github external
.forEach(config =>
    metatests.test(config.name, test => {
      const ms = Metaschema.create(
        [...defaultDomains, ...config.schemas],
        msConfig
      );

      const actualDDL = generateDDL(ms);
      const expectedDDL = defaultDomainsSql + config.expectedSql;

      test.equal(actualDDL, expectedDDL, 'must return correct sql string');
      test.end();
    })
  );
github metarhia / impress / tests / http.js View on Github external
config.tasks.forEach(task => {
  const name = task.get || task.post;
  metatests.test('http request of ' + name, test => {
    const request = getRequest(task);
    if (!request.path) {
      test.bailout();
    }

    const req = api.http.request(request);
    req.on('response', res => {
      test.strictSame(res.statusCode, 200);
      test.end();
    });
    req.on('error', err => {
      test.bailout(err);
    });
    if (task.data) req.write(task.data);
    req.end();
  });

metatests

Simple to use test engine for Metarhia technology stack

MIT
Latest version published 2 years ago

Package Health Score

46 / 100
Full package analysis

Popular metatests functions