Skip to content

Commit

Permalink
WIP clj17 still
Browse files Browse the repository at this point in the history
  • Loading branch information
slagyr committed Jun 19, 2015
1 parent ed88471 commit 43ec574
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 4 deletions.
6 changes: 3 additions & 3 deletions bin/cljs.clj
Expand Up @@ -2,11 +2,11 @@

(def build-options
{
:optimizations :whitespace
:optimizations :none
:output-to "target/tests.js"
:output-dir "target/classes"
;:cache-analysis true
;:source-map true
:cache-analysis true
:source-map true
:pretty-print true
:verbose true
:watch-fn (fn [] (println "Success!"))})
Expand Down
139 changes: 139 additions & 0 deletions bin/speclj.js
@@ -0,0 +1,139 @@
/*
Speclj Runner
Usage:
phantomjs resources/public/specs/speclj.js [auto]
auto: will only run specs updated after the last run. (default: false)
Each run produced/touches a timestamp file, .specljs-timestamp
*/

var outputDir = "target/classes";
var nsPrefix = "speclj";
var runnerFile = "bin/specs.html";

var fs = require("fs");
var p = require('webpage').create();
var system = require('system');

String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
String.prototype.startsWith = function (str) {
return this.slice(0, str.length) == str;
};

p.onConsoleMessage = function (x) {
fs.write("/dev/stdout", x + "\n", "w");
};

var timestampFile = ".specljs-timestamp";
writeTimestamp = function () {
if(fs.lastModified(timestampFile) != null)
fs.remove(timestampFile);
fs.touch(timestampFile);
};

readTimestamp = function () {
return fs.lastModified(timestampFile);
};

allSpecsFilter = function () {
return true;
};

var autoMode = function () {
return system.args[1] == "auto" && readTimestamp() != null;
};

var logList = function (title, list) {
console.log(title + ":");
for(var i in list)
console.log(i);
};

var relativeRoot = outputDir + "/goog/";
findUpdatedSpecs = function (rdeps, deps) {
var minMillis = readTimestamp().getTime();
var updated = {};
for(var ns in rdeps) {
var file = deps.nameToPath[ns];
var path = relativeRoot + file;
if(fs.lastModified(path).getTime() >= minMillis) {
updated[ns] = true;
}
}
return updated;
};

buildReverseDeps = function (deps) {
var rdeps = {};
for(var ns in deps.nameToPath) {
if(ns.startsWith(nsPrefix)) {
var file = deps.nameToPath[ns];
for(var rdep in deps.requires[file]) {
if(rdep.startsWith(nsPrefix)) {
if(!(rdep in rdeps)) {
rdeps[rdep] = {}
}
rdeps[rdep][ns] = true;
}
}
if(!(ns in rdeps)) {
rdeps[ns] = {}
}
}
}
return rdeps;
};

reduceToSpecs = function (affected) {
var result = {};
for(var ns in affected) {
if(ns.endsWith("_spec")) {
result[ns.replace(/_/g, "-")] = true
}
}
return result;
};

findAffectedSpecs = function () {
var deps = p.evaluate(function () {
return goog.dependencies_;
});
var rdeps = buildReverseDeps(deps);
var updated = findUpdatedSpecs(rdeps, deps);

var result = {};

var walkDeps = function (nses) {
for(var ns in nses) {
if(!(ns in result)) {
result[ns] = true;
walkDeps(rdeps[ns])
}
}
};
walkDeps(updated);

return reduceToSpecs(result);
};

p.open(runnerFile, function (status) {
try {
var specs = autoMode() ? findAffectedSpecs() : null;

var result = p.evaluate(function (specSet) {
return runSpecsPhantom(specSet);
}, specs);

writeTimestamp();
phantom.exit(result);
}
catch(e) {
console.error(e);
phantom.exit(-1);
}

});
65 changes: 65 additions & 0 deletions bin/specs.html
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="iso-8859-1" content="text/html" http-equiv="Content-Type"/>
<title>Airworthy Specs</title>
<link href="../stylesheets/airworthy.css" rel="stylesheet" type="text/css"/>
<script src="../js/es5-shim.js" type="text/javascript"></script>
<script src="../cljs/goog/base.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js" type="text/javascript"></script>
<script src="../cljs/airworthy_dev.js" type="text/javascript"></script>
<script type="text/javascript">
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

for(var name in goog.dependencies_.nameToPath) {
if(name.endsWith("_spec")) {
goog.require(name)
}
}

runSpecsConfigured = function (color, reporter) {
speclj.run.standard.armed = true;
return speclj.run.standard.run_specs(
cljs.core.keyword("color"), color
, cljs.core.keyword("reporters"), [reporter]
);
};

runSpecs = function () {
runSpecsConfigured(false, "documentation");
}

runSpecsPhantom = function (affectedSpecs) {
if(affectedSpecs != null) {
console.log("Only running affected specs:");
var descriptionAtom = speclj.config.active_runner().descriptions;
cljs.core.swap_BANG_(descriptionAtom, function (descriptions) {
return cljs.core.filter(function (description) {
return description.ns in affectedSpecs;
}, descriptions);
});
cljs.core.doall(cljs.core.map(function (description) {
console.log(" ", description.ns);
}, cljs.core.deref(descriptionAtom)));
}
runSpecsConfigured(true, "documentation");
}
</script>
</head>
<body>
<h3 style="margin: 1em">Airworthy CLJS Specs</h3>

<p style="margin: 1em; width: 400px;">
Typically these specs are run using phantomjs on the command line.
But you can run them here if you like.
That is, assuming all the cljs has been compiled in development.
<br/>
Open up the browser console:
</p>
<pre style="margin: 1em; padding: 1em; width: 400px; border: 1px dotted slategray; background-color: lightgray;">
runSpecs()
</pre>
</body>
</html>
3 changes: 2 additions & 1 deletion project.clj
Expand Up @@ -47,7 +47,8 @@
:cljsbuild {:builds {:dev {:source-paths ["src"]
:compiler {:output-to "target/tests.js"
:pretty-print true}
:notify-command ["phantomjs" "bin/specljs" "target/tests.js"]
;:notify-command ["phantomjs" "bin/specljs" "target/tests.js"]
:notify-command ["phantomjs" "bin/speclj.js"]
}}
;:test-commands {"test" ["phantomjs" "bin/specljs" "target/tests.js"]}
}
Expand Down

0 comments on commit 43ec574

Please sign in to comment.