Skip to content

Commit

Permalink
Migrate tests to use [email protected]
Browse files Browse the repository at this point in the history
This only touches './test' directory.

Co-authored-by: Denys Otrishko <[email protected]>
PR-URL: #374
  • Loading branch information
Nicita01 and lundibundi committed Oct 18, 2018
1 parent 15bb5f1 commit 0d07aec
Show file tree
Hide file tree
Showing 31 changed files with 5,944 additions and 1,015 deletions.
6,256 changes: 5,628 additions & 628 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"readmeFilename": "README.md",
"scripts": {
"test": "npm run lint && node tests/all && node test/all",
"test": "npm run lint && metatests test/ && node tests/all.js",
"perf": "tests/load/run.sh",
"lint": "eslint .",
"docs": "metaschema ./metasync.js",
Expand All @@ -53,6 +53,6 @@
"babel-preset-env": "^1.7.0",
"eslint": "^4.19.1",
"metaschema": "^0.0.7",
"metatests": "^0.1.11"
"metatests": "^0.2.1"
}
}
39 changes: 23 additions & 16 deletions test/adapters.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
'use strict';

api.metatests.test('callbackify: Promise to callback-last', (test) => {
const metasync = require('..');
const metatests = require('metatests');

metatests.test('callbackify: Promise to callback-last', (test) => {

const promise = Promise.resolve('result');
const callback = api.metasync.callbackify(promise);
const callback = metasync.callbackify(promise);

callback((err, value) => {
if (err) throw err;
if (err) {
test.error(err, 'must not throw');
}
test.strictSame(value, 'result');
test.end();
});

});

api.metatests.test('callbackify: sync function to callback-last', (test) => {
metatests.test('callbackify: sync function to callback-last', (test) => {

const source = par => par;
const callback = api.metasync.callbackify(source);
const callback = metasync.callbackify(source);

callback('result', (err, value) => {
if (err) throw err;
if (err) {
test.error(err, 'must not throw');
}
test.strictSame(value, 'result');
test.end();
});

});

api.metatests.test('promisify: callback-last to Promise', (test) => {
metatests.test('promisify: callback-last to Promise', (test) => {

const id = 100;
const data = { key: 'value' };
Expand All @@ -36,17 +43,17 @@ api.metatests.test('promisify: callback-last to Promise', (test) => {
callback(null, data);
};

const getDataPromise = api.metasync.promisify(getDataAsync);
const getDataPromise = metasync.promisify(getDataAsync);
getDataPromise(id).then(result => {
test.strictSame(result, data);
test.end();
}).catch(err => {
throw err;
test.error(err, 'must not throw');
});

});

api.metatests.test('promisify: callback-last to Promise throw', (test) => {
metatests.test('promisify: callback-last to Promise throw', (test) => {

const id = 100;

Expand All @@ -55,7 +62,7 @@ api.metatests.test('promisify: callback-last to Promise throw', (test) => {
callback(new Error('Data not found'));
};

const getDataPromise = api.metasync.promisify(getDataAsync);
const getDataPromise = metasync.promisify(getDataAsync);
getDataPromise(id).then(result => {
test.notOk(result);
}).catch(err => {
Expand All @@ -66,7 +73,7 @@ api.metatests.test('promisify: callback-last to Promise throw', (test) => {
});


api.metatests.test('promisify: sync function to Promise', (test) => {
metatests.test('promisify: sync function to Promise', (test) => {

const id = 100;
const data = { key: 'value' };
Expand All @@ -76,17 +83,17 @@ api.metatests.test('promisify: sync function to Promise', (test) => {
return data;
};

const getDataPromise = api.metasync.promisifySync(getDataSync);
const getDataPromise = metasync.promisifySync(getDataSync);
getDataPromise(id).then(result => {
test.strictSame(result, data);
test.end();
}).catch(err => {
throw err;
test.error(err, 'must not throw');
});

});

api.metatests.test('promisify: sync to Promise throw', (test) => {
metatests.test('promisify: sync to Promise throw', (test) => {

const id = 100;

Expand All @@ -95,7 +102,7 @@ api.metatests.test('promisify: sync to Promise throw', (test) => {
return new Error('Data not found');
};

const getDataPromise = api.metasync.promisifySync(getDataSync);
const getDataPromise = metasync.promisifySync(getDataSync);
getDataPromise(id).then(result => {
test.notOk(result);
}).catch(err => {
Expand Down
25 changes: 0 additions & 25 deletions test/all.js

This file was deleted.

15 changes: 9 additions & 6 deletions test/array.each.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
'use strict';

api.metatests.test('successfull each', (test) => {
const metasync = require('..');
const metatests = require('metatests');

metatests.test('successful each', (test) => {
const arr = [1, 2, 3, 4];

const elementsSet = new Set();
const expectedElementsSet = new Set(arr);

api.metasync.each(arr, (el, callback) => process.nextTick(() => {
metasync.each(arr, (el, callback) => process.nextTick(() => {
elementsSet.add(el);
callback(null);
}), (err) => {
Expand All @@ -16,13 +19,13 @@ api.metatests.test('successfull each', (test) => {
});
});

api.metatests.test('each with empty array', (test) => {
metatests.test('each with empty array', (test) => {
const arr = [];

const elementsSet = new Set();
const expectedElementsSet = new Set(arr);

api.metasync.each(arr, (el, callback) => process.nextTick(() => {
metasync.each(arr, (el, callback) => process.nextTick(() => {
elementsSet.add(el);
callback(null);
}), (err) => {
Expand All @@ -32,15 +35,15 @@ api.metatests.test('each with empty array', (test) => {
});
});

api.metatests.test('each with error', (test) => {
metatests.test('each with error', (test) => {
const arr = [1, 2, 3, 4];
let count = 0;

const elementsSet = new Set();
const expectedElementsCount = 2;
const eachError = new Error('Each error');

api.metasync.each(arr, (el, callback) => process.nextTick(() => {
metasync.each(arr, (el, callback) => process.nextTick(() => {
elementsSet.add(el);
count++;
if (count === expectedElementsCount) {
Expand Down
21 changes: 12 additions & 9 deletions test/array.every.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict';

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

const identity = (x, callback) => callback(null, x);

const strictSameResult = (input, expectedResult, test, done) => {
api.metasync.every(input, identity, (err, result) => {
metasync.every(input, identity, (err, result) => {
test.error(err);
test.strictSame(result, expectedResult);

Expand All @@ -13,15 +16,15 @@ const strictSameResult = (input, expectedResult, test, done) => {

const fewStrictSameResult = (inOutPairs, test) => {
let i = 0;
const testsEnd = api.metasync.collect(inOutPairs.length);
const testsEnd = metasync.collect(inOutPairs.length);
testsEnd.done(() => test.end());
const cb = () => testsEnd.pick('item' + i++);
for (const [input, output] of inOutPairs) {
strictSameResult(input, output, test, cb);
}
};

api.metatests.test('every with error', test => {
metatests.test('every with error', test => {
const data = [1, 2, 3];
const everyErr = new Error('Every error');

Expand All @@ -31,21 +34,21 @@ api.metatests.test('every with error', test => {
));
};

api.metasync.every(data, predicate, err => {
metasync.every(data, predicate, err => {
test.strictSame(err, everyErr);
test.end();
});
});

api.metatests.test('every with empty array', test => (
metatests.test('every with empty array', test => (
strictSameResult([], true, test, () => test.end())
));

api.metatests.test('every with one-element arrays', test =>
metatests.test('every with one-element arrays', test =>
fewStrictSameResult([ [[false], false], [[true], true] ], test)
);

api.metatests.test('every with two-element arrays', test =>
metatests.test('every with two-element arrays', test =>
fewStrictSameResult([
[[false, false], false],
[[false, true ], false],
Expand All @@ -54,14 +57,14 @@ api.metatests.test('every with two-element arrays', test =>
], test)
);

api.metatests.test('every', test => {
metatests.test('every', test => {
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];

const predicate = (item, callback) => {
process.nextTick(() => callback(null, item > 0));
};

api.metasync.every(data, predicate, (err, result) => {
metasync.every(data, predicate, (err, result) => {
test.error(err);
test.strictSame(result, true);
test.end();
Expand Down
15 changes: 9 additions & 6 deletions test/array.filter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

api.metatests.test('successful filter', (test) => {
const metasync = require('..');
const metatests = require('metatests');

metatests.test('successful filter', (test) => {
const arr = [
'Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur',
'adipiscing', 'elit', 'sed', 'do', 'eiusmod', 'tempor',
Expand All @@ -11,7 +14,7 @@ api.metatests.test('successful filter', (test) => {
'do', 'ut', 'et', 'magna'
];

api.metasync.filter(arr, (str, callback) => process.nextTick(() => (
metasync.filter(arr, (str, callback) => process.nextTick(() => (
callback(null, str.length < 6)
)), (err, res) => {
test.error(err);
Expand All @@ -20,11 +23,11 @@ api.metatests.test('successful filter', (test) => {
});
});

api.metatests.test('filter with empty array', (test) => {
metatests.test('filter with empty array', (test) => {
const arr = [];
const expectedArr = [];

api.metasync.filter(arr, (str, callback) => process.nextTick(() => (
metasync.filter(arr, (str, callback) => process.nextTick(() => (
callback(null, str.length < 6)
)), (err, res) => {
test.error(err);
Expand All @@ -33,7 +36,7 @@ api.metatests.test('filter with empty array', (test) => {
});
});

api.metatests.test('successful filter', (test) => {
metatests.test('successful filter', (test) => {
const arr = [
'Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur',
'adipiscing', 'elit', 'sed', 'do', 'eiusmod', 'tempor',
Expand All @@ -44,7 +47,7 @@ api.metatests.test('successful filter', (test) => {
'Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'elit', 'sed', 'magna'
];

api.metasync.filter(arr, (str, callback) => process.nextTick(() => {
metasync.filter(arr, (str, callback) => process.nextTick(() => {
if (str.length === 2) {
callback(filterError);
return;
Expand Down
19 changes: 11 additions & 8 deletions test/array.find.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

api.metatests.test('find with error', (test) => {
const metasync = require('..');
const metatests = require('metatests');

metatests.test('find with error', (test) => {
const data = [1, 2, 3];
const expectedErrorMessage = 'Intentional error';
const predicate = (item, callback) => process.nextTick(() => {
Expand All @@ -11,29 +14,29 @@ api.metatests.test('find with error', (test) => {
}
});

api.metasync.find(data, predicate, (err) => {
metasync.find(data, predicate, (err) => {
test.type(err, 'Error', 'err must be an instance of Error');
test.strictSame(err.message, expectedErrorMessage);
test.end();
});
});

api.metatests.test('find', (test) => {
metatests.test('find', (test) => {
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
const expected = 15;
const predicate = (item, callback) => process.nextTick(() => (
callback(null, item % 3 === 0 && item % 5 === 0)
));

api.metasync.find(data, predicate, (err, result) => {
metasync.find(data, predicate, (err, result) => {
test.error(err, 'must not return an error');
test.strictSame(result, expected, `result should be: ${expected}`);
test.end();
});
});

api.metatests.test('with empty array', (test) => {
api.metasync.find([], (el, callback) => (
metatests.test('with empty array', (test) => {
metasync.find([], (el, callback) => (
process.nextTick(() => callback(null, true))
), (err, result) => {
test.error(err);
Expand All @@ -42,9 +45,9 @@ api.metatests.test('with empty array', (test) => {
});
});

api.metatests.test('with array without element which is searching', (test) => {
metatests.test('with array without element which is searching', (test) => {
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
api.metasync.find(data, (el, callback) => (
metasync.find(data, (el, callback) => (
process.nextTick(() => callback(null, el === 20))
), (err, result) => {
test.error(err);
Expand Down
Loading

0 comments on commit 0d07aec

Please sign in to comment.