Browse files

messing around with adding some home grown performance tests

  • Loading branch information...
1 parent 0b99a09 commit 6e06f54362a29325ac1cc11bae18a0893e8aef47 @brentlintner brentlintner committed Aug 19, 2011
Showing with 104 additions and 11 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 Jakefile
  3. +35 −0 build/ptest.js
  4. +1 −1 build/test.js
  5. +20 −0 test/system/genfiles
  6. +34 −0 test/system/perf.js
  7. +8 −8 test/{ → unit}/cli.js
  8. +2 −2 test/{ → unit}/hint.js
View
1 .gitignore
@@ -1,2 +1,3 @@
tags
node_modules
+test/system/.files
View
3 Jakefile
@@ -1,5 +1,8 @@
desc('run tests');
task('test', [], require('./build/test'));
+desc('run performance/system tests');
+task('ptest', [], require('./build/ptest'));
+
desc('lint code');
task('lint', [], require('./build/lint'));
View
35 build/ptest.js
@@ -0,0 +1,35 @@
+module.exports = function () {
+ var jasmine = require('jasmine-node'),
+ childProcess = require('child_process'),
+ path = require('path'),
+ verbose = false,
+ colored = true,
+ key;
+
+ for (key in jasmine) {
+ if (Object.prototype.hasOwnProperty.call(jasmine, key)) {
+ global[key] = jasmine[key];
+ }
+ }
+
+ process.argv.forEach(function (arg) {
+ switch (arg) {
+ case '--no-color':
+ colored = false;
+ break;
+ case '--silent':
+ verbose = false;
+ break;
+ }
+ });
+
+ function _test() {
+ jasmine.executeSpecsInFolder(__dirname + "/../test/system/", null, verbose, colored);
+ }
+
+ if (path.existsSync(__dirname + "/../test/system/.files")) {
+ _test();
+ } else {
+ childProcess.exec(__dirname + "/../test/system/genfiles test/system/.files", _test);
+ }
+};
View
2 build/test.js
@@ -21,6 +21,6 @@ module.exports = function () {
}
});
- jasmine.executeSpecsInFolder(__dirname + "/../test/", function (runner, log) {
+ jasmine.executeSpecsInFolder(__dirname + "/../test/unit/", function (runner, log) {
}, verbose, colored);
};
View
20 test/system/genfiles
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+mkdir "$1"
+
+for i in {1..5}
+do
+ mkdir "$1/$i"
+ for q in {1..10}
+ do
+ mkdir "$1/$i/$q"
+ for d in {1..20}
+ do
+ touch "$1/$i/$q/$d.js"
+ for b in {1..50}
+ do
+ echo "var v$b = 'abcd';" >> "$1/$i/$q.js"
+ done
+ done
+ done
+done
View
34 test/system/perf.js
@@ -0,0 +1,34 @@
+describe("file/directory walking performance", function () {
+ var path = require('path');
+
+ beforeEach(function checkGeneratedFS() {
+ if (!path.existsSync(__dirname + "/.files")) {
+ throw "no .files folder!";
+ }
+ });
+
+ describe("by default", function () {
+ it("performs reasonably", function () {
+ var finished = false,
+ time = new Date().getTime();
+
+ require('child_process').exec(__dirname + "/../../bin/hint " + __dirname + "/.files", function (b) {
+ if (b) {
+ console.log(b.message);
+ throw b;
+ }
+
+ var stamp = new Date().getTime() - time;
+
+ console.log("Took ~" + stamp + "ms");
+ expect(stamp <= 6000).toBe(true); // usually ~5s
+
+ finished = true;
+ });
+
+ waitsFor(function () {
+ return finished;
+ }, "time out", 10000);
+ });
+ });
+});
View
16 test/cli.js → test/unit/cli.js
@@ -1,23 +1,23 @@
var sys = require('sys'),
fs = require('fs'),
path = require('path'),
- cli = require('./../lib/cli'),
- hint = require('./../lib/hint');
+ cli = require('./../../lib/cli'),
+ hint = require('./../../lib/hint');
describe("cli", function () {
beforeEach(function () {
spyOn(hint, "hint");
});
it("interprets --help with no args", function () {
- var txt = require('fs').readFileSync(__dirname + "/../HELP", "utf-8");
+ var txt = require('fs').readFileSync(__dirname + "/../../HELP", "utf-8");
spyOn(sys, "print");
cli.interpret(["node", "hint"]);
expect(sys.print.mostRecentCall.args[0]).toEqual(txt);
});
it("interprets --help", function () {
- var txt = require('fs').readFileSync(__dirname + "/../HELP", "utf-8");
+ var txt = require('fs').readFileSync(__dirname + "/../../HELP", "utf-8");
spyOn(sys, "print");
cli.interpret(["node", "hint", "file.js", "--help"]);
expect(sys.print.mostRecentCall.args[0]).toEqual(txt);
@@ -43,9 +43,9 @@ describe("cli", function () {
});
it("interprets --reporter", function () {
- var reporter = require("./../example/reporter").reporter;
+ var reporter = require("./../../example/reporter").reporter;
spyOn(process, "cwd").andReturn(__dirname + "/../");
- cli.interpret(["node", "hint", "file.js", "file.js", "--reporter", "example/reporter.js"]);
+ cli.interpret(["node", "hint", "file.js", "file.js", "--reporter", "../example/reporter.js"]);
expect(hint.hint.mostRecentCall.args[2]).toEqual(reporter);
});
@@ -92,13 +92,13 @@ describe("cli", function () {
});
it("interprets --jslint-reporter and uses the jslint xml reporter", function () {
- var reporter = require("./../lib/reporters/jslint_xml").reporter;
+ var reporter = require("./../../lib/reporters/jslint_xml").reporter;
cli.interpret(["node", "file.js", "file.js", "--jslint-reporter"]);
expect(hint.hint.mostRecentCall.args[2]).toEqual(reporter);
});
it("interprets --show-non-errors and uses the non error reporter", function () {
- var reporter = require("./../lib/reporters/non_error.js").reporter;
+ var reporter = require("./../../lib/reporters/non_error.js").reporter;
cli.interpret(["node", "file.js", "file.js", "--show-non-errors"]);
expect(hint.hint.mostRecentCall.args[2]).toEqual(reporter);
});
View
4 test/hint.js → test/unit/hint.js
@@ -1,7 +1,7 @@
var sys = require('sys'),
fs = require('fs'),
- jshint = require('./../packages/jshint/jshint.js'),
- hint = require('./../lib/hint');
+ jshint = require('./../../packages/jshint/jshint.js'),
+ hint = require('./../../lib/hint');
describe("hint", function () {
function mockJSHINT(success, data) {

0 comments on commit 6e06f54

Please sign in to comment.