Skip to content

Commit

Permalink
messages and cmd line test command
Browse files Browse the repository at this point in the history
  • Loading branch information
bttmly committed Feb 24, 2015
1 parent 7ae1c34 commit dd3089d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 18 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
test:
./node_modules/.bin/_mocha ./test/**/*.js

lint:
./node_modules/.bin/jshint ./**/*.js

test-example:
./node_modules/.bin/_mocha ./example/test/**/*-test.js

Expand All @@ -11,9 +14,9 @@ example-i:
./bin/perturb -r ./example -i

dogfood:
./bin/perturb -r ./
./bin/_perturb -r ./ -c 'make lint && make test'

dogfood-i:
./bin/perturb -r ./ -i
./bin/_perturb -r ./ -i

.PHONY: test example
.PHONY: test example
8 changes: 5 additions & 3 deletions bin/_perturb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env node

"use strict";

Expand Down Expand Up @@ -26,6 +26,7 @@ program
.option("-s, --sourceDir <sourceDir>", "source directory relative to root directory")
.option("-x, --testGlob <testGlob>", "glob for selecting files in test directory")
.option("-y, --sourceGlob <sourceGlob>", "glob for selecting files in source directory")
.option("-c, --testCmd <testCmd>", "test command")
.option("-i, --interception", "use interception strategy (no disk I/O)")
.option("-v, --verbose", "lots of logging")
.parse(process.argv);
Expand All @@ -40,7 +41,8 @@ var config = assignNoUndefined({}, {
sourceDir: program.sourceDir,
testGlob: program.testGlob,
sourceGlob: program.sourceGlob,
interception: program.interception
testCmd: program.testCmd,
interception: program.interception,
});

// this will become the default reporter
Expand All @@ -50,4 +52,4 @@ function reporter (err, data) {
console.log(data.meta);
}

perturb(config, reporter);
perturb(config, reporter);
16 changes: 9 additions & 7 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var JS_TYPES = util.constObj({
bool: "boolean",
str: "string",
num: "number",
obj: "object"
obj: "object",
});

var BINARY_OPERATOR_SWAPS = util.constObj({
Expand All @@ -24,7 +24,7 @@ var BINARY_OPERATOR_SWAPS = util.constObj({
"==": "!=",
"!=": "==",
"===": "!==",
"!==": "==="
"!==": "===",
});

var NODE_TYPES = util.mapMirror([
Expand Down Expand Up @@ -68,12 +68,12 @@ var NODE_TYPES = util.mapMirror([
"VariableDeclaration",
"VariableDeclarator",
"WhileStatement",
"WithStatement"
"WithStatement",
]);

var FUNC_NODES = util.mapMirror([
NODE_TYPES.FunctionDeclaration,
NODE_TYPES.FunctionExpression
NODE_TYPES.FunctionExpression,
]);

var NODES_WITH_TEST = util.mapMirror([
Expand All @@ -88,11 +88,13 @@ var NODES_WITH_TEST = util.mapMirror([
var ERRORS = util.constObj({
NotKeyedIterable: "Node must be an Immutable.js keyed iterable",
WrongNodeType: "Node is of wrong type. Actual: %s; Expected: %s",
TestsFailed: "Test command failed. Tests must be passing for perturb to work properly."
TestsFailed: "Test command failed. Tests must be passing for perturb to work properly.",
});

var MESSAGES = util.constObj({

TestsPassed: "Test command exited with `0`. Continuing...",
ExecutingTests: "executing `%s` ...",
DefaultTest: "npm test",
});

module.exports = {
Expand All @@ -103,5 +105,5 @@ module.exports = {
ISSUES_URL: ISSUES_URL,
JS_TYPES: JS_TYPES,
ERRORS: ERRORS,
MESSAGES: MESSAGES
MESSAGES: MESSAGES,
};
8 changes: 5 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Error.stackTraceLimit = 100;
process.setMaxListeners(0);

var EventEmitter = require("events").EventEmitter;
// var EventEmitter = require("events").EventEmitter;
var path = require("path");
var exec = require("child_process").exec;

Expand All @@ -21,6 +21,7 @@ var constants = require("./constants");

var JS_TYPES = constants.JS_TYPES;
var ERRORS = constants.ERRORS;
var MESSAGES = constants.MESSAGES;

var join = path.join;

Expand All @@ -30,10 +31,11 @@ var PERTURB_DIR = ".perturb";
var DEFAULT_GLOB = "/**/*.js";

module.exports = function (settings, cb) {
var cmd = settings.testCommand || "npm test";
console.log("executing `", cmd, "` ...");
var cmd = settings.testCmd || MESSAGES.DefaultTest;
console.log(MESSAGES.ExecutingTests, cmd);
exec(cmd, function (err) {
if (err && err.code > 0) return cb(new Error(ERRORS.TestsFailed));
console.log(MESSAGES.TestsPassed);
perturb(settings, cb);
});
};
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {

runner: function () {
return function runner (failures) {
// console.log(failures);
console.log(failures);
};
},

Expand All @@ -25,4 +25,4 @@ module.exports = {
};
}

};
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"chai": "^1.10.0",
"growl": "^1.8.1",
"jshint": "^2.6.0",
"sync-exec": "^0.4.0",
"watch": "^0.13.0"
},
Expand Down
24 changes: 24 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

function isPrimitiveValue (value) {
var t = typeof value;
return (
value !== null && (
t === "symbol" ||
t === "string" ||
t === "number" ||
t === "boolean"
)
);
}

function objIsShallow (obj) {
if (isPrimitiveValue(obj)) return false;
return Object.keys(obj).every(function (key) {
return isPrimitiveValue(obj[key]);
});
}

module.exports = {
objIsShallow: objIsShallow
};

0 comments on commit dd3089d

Please sign in to comment.