@c4312/matcha
Version:
A caffeine driven, simple command line for benchmarking
126 lines • 5.36 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const runner_1 = require("./runner");
const gather_1 = require("./reporters/gather");
const chai_1 = require("chai");
const util_1 = require("util");
const grep_1 = require("./middleware/grep");
const timeout = util_1.promisify(setTimeout);
// There's really no other test setup I could use for a project
// called matcha but mocha and chai
describe('runner', () => {
it('sets options correctly', () => __awaiter(void 0, void 0, void 0, function* () {
let results = [];
yield runner_1.benchmark({
reporter: new gather_1.GatherReporter(),
runFunction(name, options) {
const { maxTime, initCount } = options;
results.push([name, { maxTime, initCount }]);
return Promise.resolve();
},
prepare(api) {
api.set('maxTime', 1);
api.bench('a', () => { });
api.bench('aaa', () => { });
api.suite('aSuite', () => {
api.set('initCount', 100);
api.bench('c', () => { });
});
},
});
chai_1.expect(results).to.deep.equal([
['a', { maxTime: 1, initCount: undefined }],
['aaa', { maxTime: 1, initCount: undefined }],
['aSuite#c', { maxTime: 1, initCount: 100 }],
]);
}));
it('greps for tests', () => __awaiter(void 0, void 0, void 0, function* () {
let results = [];
yield runner_1.benchmark({
middleware: [grep_1.grepMiddleware(/^a/)],
reporter: new gather_1.GatherReporter(),
runFunction(name) {
results.push(name);
return Promise.resolve();
},
prepare(api) {
api.bench('a', () => { });
api.bench('b', () => { });
api.bench('aaa', () => { });
api.bench('ba', () => { });
},
});
chai_1.expect(results).to.deep.equal(['a', 'aaa']);
}));
it('handles lifecycle correctly', () => __awaiter(void 0, void 0, void 0, function* () {
let results = [];
yield runner_1.benchmark({
reporter: new gather_1.GatherReporter(),
runFunction() {
results.push('bench');
return Promise.resolve();
},
prepare(api) {
api.set('setup', () => {
results.push('in a');
return timeout(1);
});
api.set('teardown', () => {
results.push('out a');
return timeout(1);
});
api.suite('b', () => {
api.set('setup', () => {
results.push('in b');
});
api.set('teardown', () => {
results.push('out b');
});
api.suite('c', () => {
api.set('setup', callback => {
results.push('in c');
setTimeout(() => callback(null), 1);
});
api.set('teardown', callback => {
results.push('out c');
setTimeout(() => callback(null), 1);
});
api.bench('', () => { });
});
});
},
});
chai_1.expect(results).to.deep.equal(['in a', 'in b', 'in c', 'bench', 'out c', 'out b', 'out a']);
}));
it('runs e2e', function () {
return __awaiter(this, void 0, void 0, function* () {
this.timeout(10000);
const reporter = new gather_1.GatherReporter();
const obj1 = { a: 1, b: 2, c: 3 };
const obj2 = Object.assign({}, obj1);
yield runner_1.benchmark({
reporter,
prepare(api) {
api.set('maxTime', 0.5);
api.bench('deepEqual', () => chai_1.expect(obj1).to.deep.equal(obj2));
api.bench('strictEqual', () => chai_1.expect(obj1).to.equal(obj1));
},
});
chai_1.expect(reporter.results).to.have.lengthOf(2);
for (const result of reporter.results) {
chai_1.expect(result.error).to.be.undefined;
chai_1.expect(result.hz).to.be.greaterThan(1);
}
});
});
});
//# sourceMappingURL=runner.test.js.map