Skip to content

Commit

Permalink
makefile; rm unused deps; better reporter injection
Browse files Browse the repository at this point in the history
  • Loading branch information
bttmly committed Feb 11, 2015
1 parent 99e89d0 commit 8ba4a0b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test:
NODE_ENV='testing' ./node_modules/.bin/_mocha ./test/**/*.js

test-example:
NODE_ENV='testing' ./node_modules/.bin/_mocha ./example/test/**/*-test.js

example:
NODE_ENV='testing' ./bin/perturb -r ./example

example-i:
NODE_ENV='testing' ./bin/perturb -r ./example -i

dogfood:
NODE_ENV='testing' ./bin/perturb -r ./

dogfood-i:
NODE_ENV='testing' ./bin/perturb -r ./ -i

.PHONY: test example
5 changes: 3 additions & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ var NODES_WITH_TEST = util.mapMirror([
]);

var ERRORS = util.constObj({
mutableNode: "Node must be an Immutable.js keyed iterable",
wrongNodeType: "Node is of wrong type. Actual: %s; Expected: %s"
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."
});

module.exports = {
Expand Down
14 changes: 10 additions & 4 deletions lib/handle-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ var NODE_TYPES = constants.NODE_TYPES;
var JS_TYPES = constants.JS_TYPES;

// called on nodes during labeling to skip
var SKIP_TRAVERSE = {
var SKIP_TRAVERSE = util.constObj({

// skip specific recursing down specific property names (just 'loc' for now)
skipByKey: (function () {
var KEYS_TO_SKIP = util.constObj({
"loc": true
Expand All @@ -30,20 +32,24 @@ var SKIP_TRAVERSE = {
};
})(),

// skip mutating require calls when the argument is a plain string
skipRequire: function skipRequire (node) {
return (
node.type === NODE_TYPES.CallExpression &&
node.callee.name === "require"
node.callee.name === "require" &&
node.arguments[0].type === NODE_TYPES.Literal &&
typeof node.arguments[0].type === JS_TYPES.str
);
},

// skip mutating a "use strict" invocation
skipUseStrict: function skipUseStrict (node) {
return (
node.type === NODE_TYPES.ExpressionStatement &&
node.expression.value === "use strict"
);
}
};
});

var ESPRIMA_SETTINGS = util.constObj({
loc: true,
Expand All @@ -56,7 +62,7 @@ var ENC_UTF8 = util.constObj({

module.exports = handleMatch;
function handleMatch (match, done) {

var config = global.__perturb__;

async.parallel({
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var util = require("./util");
var constants = require("./constants");

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

var join = path.join;

Expand All @@ -33,12 +34,11 @@ module.exports = function (settings, cb) {
var cmd = settings.testCommand || "npm test";
console.log("executing `", cmd, "` ...");
exec(cmd, function (err) {
if (err) throw new Error("Test command failed. Tests must be passing for perturb to work properly.");
if (err) throw new Error(ERRORS.testsFailed);
perturb(settings, cb);
});
};


function perturb (settings, cb) {

if (typeof settings === JS_TYPES.str) {
Expand Down Expand Up @@ -94,7 +94,7 @@ function perturb (settings, cb) {
meta.matchesProcessed = matches.length;

// swap this out for a reporter
console.log(assign(config, {
config.configReporter(assign(config, {
originalDir: oRoot,
originalSourceDir: oSource,
originalTestDir: oTest,
Expand Down
16 changes: 1 addition & 15 deletions lib/mutators.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,7 @@ var NODE_TYPES = constants.NODE_TYPES;
var JS_TYPES = constants.JS_TYPES;
var FUNC_NODES = constants.FUNC_NODES;
var NODES_WITH_TEST = constants.NODES_WITH_TEST;

var BINARY_OPERATOR_SWAPS = util.constObj(
[
["+", "-"],
["*", "/"],
[">", "<="],
["<", ">="],
["==", "!="],
["===", "!=="]
].reduce(function (obj, tuple) {
obj[tuple[0]] = tuple[1];
obj[tuple[1]] = tuple[0];
return obj;
}, {})
);
var BINARY_OPERATOR_SWAPS = constants.BINARY_OPERATOR_SWAPS;

var NODE_ATTRS = util.mapMirror([
"operator",
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"glob": "^4.3.2",
"immutable": "^3.5.0",
"intercept-require": "^1.0.0",
"lodash.bindall": "^3.0.0",
"lodash.find": "^3.0.0",
"lodash.last": "^3.0.0",
"lodash.partial": "^3.0.0",
Expand All @@ -38,10 +37,10 @@
"example": "NODE_ENV='testing' ./bin/perturb -r ./example",
"example-i": "NODE_ENV='testing' ./bin/perturb -r ./example -i",
"test-example": "mocha ./example/test/**/*-test.js",
"dogfood": "NODE_ENV='testing' ./bin/perturb -r ./",
"dogfood-i": "NODE_ENV='testing' ./bin/perturb -r ./ -i",
"test": "mocha ./test/**/*.js"
"dogfood": "make dogfood",
"dogfood-i": "make dogfood-i",
"test": "make test"
},
"author": "Nick Bottomley (github.com/nickb1080)",
"license": "MIT"
}
}

0 comments on commit 8ba4a0b

Please sign in to comment.