4232561a38
ui: Repo layer integration tests for methods that touch the API Includes a `repo` test helper to make repetitive tasks easier, plus a injectable reporter for sending performance metrics to a centralized metrics system Also noticed somewhere in the ember models that I'd like to improve, but left for the moment to make sure I concentrate on one task at a time, more or less: The tests currently asserts against the existing JSON tree, which doesn't seem to be a very nice tree. The work at hand here is to refactor what is there, so test for the not nice tree to ensure we don't get any regression, and add a skipped test so I can come back here later
27 lines
839 B
JavaScript
27 lines
839 B
JavaScript
/* eslint no-console: "off" */
|
|
const log = function(results, measurement, tags) {
|
|
console.log(measurement, results, tags);
|
|
};
|
|
export default function(len = 10000, report = log, performance = window.performance) {
|
|
return function(cb, measurement, tags) {
|
|
let actual;
|
|
return new Array(len)
|
|
.fill(true)
|
|
.reduce(function(prev, item, i) {
|
|
return prev.then(function(ms) {
|
|
return new Promise(function(resolve) {
|
|
const start = performance.now();
|
|
cb().then(function(res) {
|
|
actual = res;
|
|
resolve(ms + (performance.now() - start));
|
|
});
|
|
});
|
|
});
|
|
}, Promise.resolve(0))
|
|
.then(function(total) {
|
|
report({ avg: total / len, total: total, count: len }, measurement, tags);
|
|
return actual;
|
|
});
|
|
};
|
|
}
|