Skip to content

Commit

Permalink
Merge pull request #38 from KrisSiegel/3.0.0
Browse files Browse the repository at this point in the history
3.0.0
  • Loading branch information
KrisSiegel committed Nov 8, 2015
2 parents fce68b2 + f8b92c1 commit 3aaa3df
Show file tree
Hide file tree
Showing 39 changed files with 1,904 additions and 535 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# msngr.js specific
benchRunner.html
benchRunner.min.html
specRunner.html
specRunner.min.html
crossWindowVerifier.html
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
language: node_js
sudo: false
node_js:
- "5.0"
- "4.2"
- "4.1"
- "4.0"
- "0.12"
- "0.11"
Expand Down
180 changes: 138 additions & 42 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module.exports = (function(grunt) {
"src/module.exports.js",
"!**/*.aspec.js",
"!**/*.cspec.js",
"!**/*.nspec.js"
"!**/*.nspec.js",
"!**/*.bench.js"
];

grunt.initConfig({
Expand All @@ -38,11 +39,7 @@ module.exports = (function(grunt) {
},
uglify: {
minify: {
options: {
mangle: false,
preserveComments: false,
compress: {}
},
options: { },
files: {
"./msngr.min.js": paths
}
Expand Down Expand Up @@ -112,74 +109,171 @@ module.exports = (function(grunt) {
grunt.log.subhead("Unit testing with node.js");
});

grunt.registerTask("header:nodeBenching", function() {
grunt.log.subhead("Benchmarking with node.js");
});

grunt.registerTask("header:clientTesting", function() {
grunt.log.subhead("Client-side unit testing with phantom.js");
});

/*
The setRunner task modifies the specRuner.html file, dynamically, with the
unit tests within the project to allow test running with phantomjs.
*/
grunt.registerTask("setRunner", "Set the client side spec runner", function() {
var makeScript = function(path) {
return "<script type='text/javascript' src='" + path + "'></script>";
};
var jsPaths = ["./", "./src/", "./docs/"];
var fetchJsFiles = function(filters) {
var fs = require("fs");
var path = require("path");
var results = [];

var tests = [];
var testPaths = ["./", "./src/", "./docs/"];

for (var k = 0; k < testPaths.length; ++k) {
var dirs = fs.readdirSync(testPaths[k]);
for (var k = 0; k < jsPaths.length; ++k) {
var dirs = fs.readdirSync(jsPaths[k]);

for (var i = 0; i < dirs.length; ++i) {
if (fs.statSync(testPaths[k] + dirs[i]).isDirectory()) {
var files = fs.readdirSync(testPaths[k] + dirs[i]);
if (fs.statSync(jsPaths[k] + dirs[i]).isDirectory()) {
var files = fs.readdirSync(jsPaths[k] + dirs[i]);
for (var j = 0; j < files.length; ++j) {
var p = path.join("./", testPaths[k], dirs[i], files[j]);
if (tests.indexOf(p) === -1) {
tests.push(p);
var p = path.join("./", jsPaths[k], dirs[i], files[j]);
if (results.indexOf(p) === -1) {
results.push(p);
}
}
} else {
var p = path.join("./", testPaths[k], dirs[i]);
if (tests.indexOf(p) === -1) {
tests.push(p);
var p = path.join("./", jsPaths[k], dirs[i]);
if (results.indexOf(p) === -1) {
results.push(p);
}
}
}
}

var scriptHtml = "";

if (tests !== undefined && tests.length > 0) {
var file = tests.shift();
while (tests.length > 0) {
if (file.indexOf(".cspec.js") !== -1 || file.indexOf(".aspec.js") !== -1) {
scriptHtml += makeScript(file) + "\n";
var filteredResults = [];
for (var i = 0; i < results.length; ++i) {
var include = false;
for (var k = 0; k < filters.length; ++k) {
if (results[i].indexOf(filters[k]) !== -1) {
include = true;
break;
}
file = tests.shift();
}
if (include) {
filteredResults.push(results[i]);
}
}

var runnerHtml = fs.readFileSync("./specRunner.html", {
return filteredResults;
};

var setRunner = function(runner, files) {
var fs = require("fs");
var makeScript = function(path) {
return "<script type='text/javascript' src='" + path + "'></script>";
};

var scriptHtml = "";

if (files !== undefined && files.length > 0) {
var file = files.shift();
while (file) {
scriptHtml += makeScript(file) + "\n";
file = files.shift();
}
}
var runnerFileName = "./" + runner;
var runnerHtml = fs.readFileSync(runnerFileName, {
encoding: "utf8"
});
var scriptStart = runnerHtml.indexOf("<!-- Start Unit Tests -->");
var scriptEnd = runnerHtml.indexOf("<!-- End Unit Tests -->");
var scriptStart = runnerHtml.indexOf("<!-- Start JS Files -->");
var scriptEnd = runnerHtml.indexOf("<!-- End JS Files -->");

var newHtml = runnerHtml.substring(0, scriptStart);
newHtml += "<!-- Start Unit Tests -->";
newHtml += "<!-- Start JS Files -->";
newHtml += scriptHtml;
newHtml += runnerHtml.substring(scriptEnd);

fs.writeFileSync("./specRunner.html", newHtml, {
fs.writeFileSync(runnerFileName, newHtml, {
encoding: "utf8"
});
fs.writeFileSync("./specRunner.min.html", newHtml, {
fs.writeFileSync(runnerFileName, newHtml, {
encoding: "utf8"
});
};

/*
The setRunner task modifies the specRuner.html file, dynamically, with the
unit tests within the project to allow test running with phantomjs.
*/
grunt.registerTask("setRunner", "Set the client side spec runner", function() {
var tests = fetchJsFiles([".cspec.js", ".aspec.js"]);
setRunner("specRunner.html", tests.concat([]));
setRunner("specRunner.min.html", tests.concat([]));
});

grunt.registerTask("run-benchmarks", "Finds all benchmarks and executes them", function() {
var async = require("async");
var done = this.async();
var benchmarks = fetchJsFiles([".bench.js"]);
setRunner("benchRunner.html", benchmarks.concat([]));
setRunner("benchRunner.min.html", benchmarks.concat([]));
var meths = [];
for (var i = 0; i < benchmarks.length; ++i) {
meths.push(function(p) {
return require(p);
}("./" + benchmarks[i]));
}
async.series(meths, function (err, results) {
done();
});
});

grunt.registerTask("start-reflective-server", "Creates a test service with some dummy endpoints for testing", function() {
var http = require("http");
var server = http.createServer(function(request, response) {
var body = "";
request.on("data", function(chunk) {
body = body + chunk;
});

request.on("end", function() {
var result = {
method: request.method,
headers: request.headers,
path: request.url,
body: body
};

var headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "origin, content-type, accept",
"Access-Control-Allow-Methods": "GET,POST,PUT,DELETE,OPTIONS,HEAD"
};

try {
var objBody = JSON.parse(body);
if (objBody.headers != undefined && Object.keys(objBody.headers).length > 0) {
for (var key in objBody.headers) {
headers[key] = objBody.headers[key];
}
}

if (objBody.body != undefined) {
result.body = objBody.body;
}
} catch (ex) {
// Couldn't care less as opposed to the commonly misused "could care less"
// in which you actually do care a little. No, I couldn't care less because
// this error just means there are no commands to reflect :)
}

if (headers["content-type"] === undefined) {
headers["content-type"] = "application/json";
}

response.writeHead(200, headers);
response.end(JSON.stringify(result, null, 2));
});
});

server.listen("8009", "127.0.0.1", function(e) {
console.log("Reflective http server started");
});
});

/*
Expand All @@ -190,6 +284,8 @@ module.exports = (function(grunt) {

grunt.registerTask("build", "Cleans, sets version and builds msngr.js", ["header:building", "clean", "verisionify", "concat", "uglify:minify", "setRunner"]);

grunt.registerTask("test", "Cleans, sets version, builds and runs mocha unit tests through node.js and phantom.js", ["build", "header:nodeTesting", "mochaTest", "header:clientTesting", "mocha_phantomjs"]);
grunt.registerTask("test", "Cleans, sets version, builds and runs mocha unit tests through node.js and phantom.js", ["build", "header:nodeTesting", "start-reflective-server", "mochaTest", "header:clientTesting", "mocha_phantomjs"]);

grunt.registerTask("benchmark", "Cleans, sets version, builds and runs benchmarks through node.js", ["build", "header:nodeBenching", "run-benchmarks"]);

});
62 changes: 0 additions & 62 deletions README.cspec.js

This file was deleted.

20 changes: 1 addition & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,13 @@ While msngr.js isn't very large the documentation has been split up for easy rea

[Full API](docs/api.md) - This is the full, exposed API that msngr makes available. This includes the methods that can be used (it does not cover internal methods or objects since those are subject to change) and examples for each.

[Messaging patterns](docs/messaging patterns.md) - Explains how to use the basic messaging features of msngr.js with some typical patterns.

[Web browser niceties](docs/web browser niceties.md) - This covers binding msngr.js to elements and events, unbinding them, how to gather up values from various types of elements and cross-window communication.

[Extending and hacking](docs/extending and hacking.md) - Want to extend the capabilities of msngr.js? It's actually quite easy and this document covers it. Using msngr.js deep in a production system then suddenly find *something* that you need to change to avoid catastrophe? Hacking msngr.js is also covered for those times when you need *unorthodox* solutions :)

[Contributing](docs/contributing.md) - Want to contributed to msngr.js? There are a couple of things you should know before you submit that pull request to better ensure it gets accepted :)

## Roadmap
The current release of msngr.js works in node.js for server-side messaging as well as the web browser. The web browser has some extra features like messaging between windows and binding to DOM elements but future features will receive more focus on the core of msngr.js with more node.js fun!

### What's Next?
Below is what's being worked on for future 2.x releases.

* Web Socket Messaging - Easy web socket communication with messages between a server and client.

* Feature detection - Support verifying what certain features can work in the environment they're in (e.g. older web browsers). When they cannot log a warning and disable the feature (warnings will be toggle-able).

* Better browser support - Currently msngr.js should work in most current web browsers but some features may not work well in older versions of Internet Explorer and really old versions of Firefox. Additional testing and tweaking needs to be conducted for older browser support and to provide a baseline for what is or isn't supported.

* Benchmarking and optimization - Now that the majority of msngr.js's structure is written and fairly solidified we need to begin benchmarking along with profiling and optimization. Optimization had previously been ignored while the API was finalized and while msngr.js is really fast it needs to be *scientifically* fast.

### What's Next Next?
At this point further planning will occur once more community feedback comes through. I have a few ideas involving integration into other messaging systems, some streaming ideas and a few optional extensions that provide message based APIs for other libraries but I'm hesitant to *only* go in one direction should other needs arise.

## Getting in contact
For questions, news, and whatever else that doesn't fit in GitHub issues you can follow me [@KrisSiegel](https://twitter.com/KrisSiegel)

Copyright © 2014-2015 Kris Siegel
22 changes: 22 additions & 0 deletions benchRunner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html>
<head>
<title>Benchmarks</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="node_modules/async/dist/async.min.js"></script>
<script src="node_modules/benchmark/benchmark.js"></script>
<script type='text/javascript'>
var benchmark = Benchmark;
</script>
<script type='text/javascript' src="msngr.js"></script>
<!-- Start JS Files -->
<!-- End JS Files -->
</head>
<body>
<div id="benchess"></div>
<script type='text/javascript'>
async.series(window.benchmarkers, function (err, results) {
console.log("Done executing benchmarks");
});
</script>
</body>
</html>
22 changes: 22 additions & 0 deletions benchRunner.min.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html>
<head>
<title>Benchmarks</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="node_modules/async/dist/async.min.js"></script>
<script src="node_modules/benchmark/benchmark.js"></script>
<script type='text/javascript'>
var benchmark = Benchmark;
</script>
<script type='text/javascript' src="msngr.min.js"></script>
<!-- Start JS Files -->
<!-- End JS Files -->
</head>
<body>
<div id="benchess"></div>
<script type='text/javascript'>
async.series(window.benchmarkers, function (err, results) {
console.log("Done executing benchmarks");
});
</script>
</body>
</html>
Loading

0 comments on commit 3aaa3df

Please sign in to comment.