Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #225 from buzinas/benchmark
Browse files Browse the repository at this point in the history
Benchmark tests
  • Loading branch information
jmlopez-rod authored May 22, 2017
2 parents f7d6aa3 + aad88fb commit 9135a0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var Promise = require('es6-promise').Promise;

var SINGLE_TEST = argv.single ? parseTestName(argv.single) : null;
process.env.SINGLE_TEST = JSON.stringify(SINGLE_TEST);
process.env.BENCHMARK = argv.benchmark;

var SRC_FOLDER = SINGLE_TEST ? singleRule(SINGLE_TEST.name) : 'src/**/*.ts';
var TEST_FOLDER = SINGLE_TEST ? singleTest(SINGLE_TEST.name) : 'dist/test/**/*.js';
Expand Down Expand Up @@ -94,9 +95,10 @@ gulp.task('build', argv.lint === false ? [] : ['lint'], function build(done) {
});

gulp.task('test', ['build'], function test() {
var opt = argv.benchmark ? { 'noTimeouts': true } : {};
return gulp
.src(TEST_FOLDER)
.pipe(mocha());
.pipe(mocha(opt));
});

gulp.task('watch', function watch() {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"author": "Vitor Buzinaro <[email protected]>",
"license": "MIT",
"devDependencies": {
"@types/benchmark": "^1.0.30",
"@types/node": "^7.0.12",
"benchmark": "^2.1.3",
"chai": "^3.5.0",
"es6-promise": "^4.0.4",
"gulp": "^3.9.1",
Expand Down
20 changes: 18 additions & 2 deletions src/test/rules/ruleTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { assert, expect } from 'chai';
import * as Lint from 'tslint';
import * as fs from 'fs';
import * as path from 'path';
import * as BenchMark from 'benchmark';

const dedent = Lint.Utils.dedent;
const empty = '░';
Expand Down Expand Up @@ -133,7 +134,7 @@ class Test {
this.testFixer = testFixer;
}

public runTest(): void {
public runTest(skipErrorCheck: boolean = false): void {
const options: Lint.ILinterOptions = {
fix: false,
formatter: 'json',
Expand All @@ -143,6 +144,10 @@ class Test {

const linter = new Lint.Linter(options);
linter.lint(this.name, this.code, this.options);

// May need to exit early when doing benchmarks since we only care about the linting process.
if (skipErrorCheck) return;

const failures = JSON.parse(linter.getResult().output);
this.compareErrors(
this.errors || [],
Expand Down Expand Up @@ -318,13 +323,24 @@ class RuleTester {
const singleTest = JSON.parse(process.env.SINGLE_TEST || 'null');
const runGroup = singleTest === null || singleTest.group === null;
const runIndex = singleTest === null || singleTest.num === null;
const benchmark = process.env.BENCHMARK !== 'undefined';
describe(this.ruleName, () => {
this.groups.forEach((group) => {
if (runGroup || group.name === singleTest.group) {
it(group.description, () => {
it(`${group.name} - ${group.description}`, () => {
if (benchmark) {
console.log('');
}
group.tests.forEach((test, index) => {
if (runIndex || singleTest.num === index) {
test.runTest();
if (benchmark) {
const suite = new BenchMark.Suite();
suite
.add(` [${index}]:`, () => test.runTest(true))
.on('cycle', (event: any) => console.log(String(event.target)))
.run({ async: false });
}
}
});
});
Expand Down

0 comments on commit 9135a0a

Please sign in to comment.