Permalink
Browse files

Jasmin Support (& Colors)

  • Loading branch information...
1 parent d055eec commit 8879f3442e701ebdca5cc132a1787417db8fe9d3 David Bankier committed Jul 2, 2012
Showing with 2,977 additions and 27 deletions.
  1. +24 −0 .project
  2. +28 −3 README.md
  3. +1 −1 app/Resources/api/Log.js
  4. +38 −0 app/Resources/api/Spec.js
  5. +8 −3 app/Resources/api/TiShadow.js
  6. +89 −0 app/Resources/api/TiShadowReporter.js
  7. +2,529 −0 app/Resources/lib/jasmine-1.2.0.js
  8. +1 −0 example/.gitignore
  9. +1 −0 example/README
  10. BIN example/Resources/android/appicon.png
  11. BIN example/Resources/android/default.png
  12. BIN example/Resources/android/images/res-long-land-hdpi/default.png
  13. BIN example/Resources/android/images/res-long-land-ldpi/default.png
  14. BIN example/Resources/android/images/res-long-port-hdpi/default.png
  15. BIN example/Resources/android/images/res-long-port-ldpi/default.png
  16. BIN example/Resources/android/images/res-notlong-land-hdpi/default.png
  17. BIN example/Resources/android/images/res-notlong-land-ldpi/default.png
  18. BIN example/Resources/android/images/res-notlong-land-mdpi/default.png
  19. BIN example/Resources/android/images/res-notlong-port-hdpi/default.png
  20. BIN example/Resources/android/images/res-notlong-port-ldpi/default.png
  21. BIN example/Resources/android/images/res-notlong-port-mdpi/default.png
  22. +16 −0 example/Resources/app.js
  23. BIN example/Resources/iphone/Default-Landscape.png
  24. BIN example/Resources/iphone/Default-Portrait.png
  25. BIN example/Resources/iphone/Default.png
  26. BIN example/Resources/iphone/Default@2x.png
  27. BIN example/Resources/iphone/appicon.png
  28. +138 −0 example/Resources/spec/sample_spec.js
  29. +8 −0 example/manifest
  30. BIN example/spec.png
  31. +44 −0 example/tiapp.xml
  32. +16 −16 server/app.js
  33. +8 −3 server/bin/tishadow
  34. +26 −0 server/logger.js
  35. +2 −1 server/package.json
View
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>TiShadow</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.appcelerator.titanium.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.aptana.ide.core.unifiedBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.appcelerator.titanium.mobile.nature</nature>
+ <nature>com.aptana.projects.webnature</nature>
+ <nature>com.aptana.ruby.core.rubynature</nature>
+ </natures>
+</projectDescription>
View
@@ -178,7 +178,34 @@ Testing / Assertions
**RECENTLY ADDED**
-TiShadow now supports the use of assertions and the results are
+TiShadow now support [Jasmine](http://pivotal.github.com/jasmine/) BDD tests.
+Insipration taken from these two projects: [titanium-jasmine](https://github.com/guilhermechapiewski/titanium-jasmine/) and [jasmine-titanium](https://github.com/akahigeg/jasmine-titanium)
+
+Include your specs in the `Resources/specs` path of your project. Ensure
+the files are ending in `_spec.js`. (Note: simply write the spec without any including/requiring the jasmine library.)
+
+To execute the tests enter the following command:
+
+```bash
+ tishadow spec
+```
+
+Alternatively the following command is also supported if there are only
+minor changes:
+
+```bash
+ tishadow spec update
+```
+
+The test results will be returned to the server output:
+![Spec Output](http://github.com/dbankier/TiShadow/raw/master/example/spec.png)
+
+See the included example project.
+
+
+_Alternatively (yet not preferred)_
+
+TiShadow also supports the use of assertions and the results are
returned either to the browser or server logs.
For example:
@@ -196,8 +223,6 @@ The following assertion are supported:
Also the equivalent not assertions are available as well, e.g.
'notEqual', 'isNotString', 'isNotNumber', etc.
-
-Better testing tools are on their way.
Launch From Web
View
@@ -1,4 +1,4 @@
-['info','error','debug','trace','warn','pass','fail'].forEach(function(level){
+['info','error','debug','trace','warn','pass','fail','test'].forEach(function(level){
exports[level] = function(message) {
Ti.App.fireEvent("tishadow:socket_log", {
level: level.toUpperCase(),
View
@@ -0,0 +1,38 @@
+var p = require('/api/PlatformRequire');
+var log = require('/api/Log');
+var jasmine = require('/lib/jasmine-1.2.0').jasmine;
+var TiShadowReporter = require('/api/TiShadowReporter');
+
+jasmine.getEnv().addReporter(new TiShadowReporter());
+
+
+function loadSpecs(name, base, filter) {
+ var dir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + name + "/spec/" + base);
+ var files = dir.getDirectoryListing();
+ if (!files) {
+ return;
+ };
+ files.forEach(function(file) {
+ if (file.match(/_spec.js$/)) {
+ p.require(Ti.Filesystem.applicationDataDirectory + name, "/spec/" + base + "/" + (file.replace(".js", "")));
+ } else if (filter === {} || filter[file]) {
+ loadSpecs(name, base + "/" + file, filter);
+ }
+ });
+}
+
+exports.run = function (name) {
+ var filter_file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + name + "/spec/specs");
+ var filter = {};
+ if (filter_file.exists()) {
+ filter_file.read().text.split("\n").forEach(function(dir) {
+ filter[dir.trim()] = 1;
+ });
+ }
+ p.clearCache();
+ loadSpecs(name, "", filter);
+ jasmine.getEnv().execute();
+}
+
+
+
@@ -2,6 +2,7 @@ var log = require('/api/Log');
var zipfile = Ti.Platform.osname === "android" ? require("com.yydigital.zip"): require("zipfile");
var p = require('/api/PlatformRequire');
var assert = require('/api/Assert');
+var Spec = require("/api/Spec");
var current;
Ti.App.addEventListener("tishadow:message", function(message) {
@@ -41,7 +42,7 @@ exports.launchApp = function(name) {
}
};
-function loadRemoteZip(name, url) {
+function loadRemoteZip(name, url, spec) {
var xhr = Ti.Network.createHTTPClient();
xhr.setTimeout(1000);
xhr.onload=function(e) {
@@ -61,7 +62,11 @@ function loadRemoteZip(name, url) {
var dataDir = Ti.Platform.osname === "android" ? Ti.Filesystem.applicationDataDirectory : Ti.Filesystem.applicationDataDirectory.slice(0,Ti.Filesystem.applicationDataDirectory.length - 1).replace('file://localhost','').replace(/%20/g,' ');
zipfile.extract(dataDir+'/' + name + '.zip', dataDir + "/" + path_name);
// Launch
- exports.launchApp(path_name);
+ if (spec) {
+ Spec.run(path_name);
+ } else {
+ exports.launchApp(path_name);
+ }
} catch (err) {
log.error(err.toString());
}
@@ -74,7 +79,7 @@ function loadRemoteZip(name, url) {
}
Ti.App.addEventListener("tishadow:bundle", function(o) {
- loadRemoteZip(o.name, "http://" + Ti.App.Properties.getString("address") + ":3000/bundle");
+ loadRemoteZip(o.name, "http://" + Ti.App.Properties.getString("address") + ":3000/bundle", o.spec);
});
// Clears all apps from cache
@@ -0,0 +1,89 @@
+var log = require("/api/Log");
+
+var TiShadowReporter = function() {
+}
+
+var ansi = {
+ green: '\033[32m',
+ red: '\033[31m',
+ yellow: '\033[33m',
+ none: '\033[0m',
+ white: '\033[37m',
+ bold_on:'\033[1m',
+ bold_off:'\033[22m',
+}
+
+function summaryLine(passed, failed, type) {
+ if (failed === 0) {
+ log.pass(""+ passed + " " + type + "(s) completed.");
+ } else {
+ log.fail("x "+ failed + " of " + (passed + failed) + " " + type + "(s) failed.");
+ }
+}
+
+
+TiShadowReporter.prototype = {
+ reportRunnerStarting: function () {
+ log.test("Runner Started");
+ this.total = {
+ passed: 0,
+ failed: 0
+ };
+ this.level = 0;
+ this.current = {
+ description: "",
+ parent: null
+ };
+
+ },
+ reportRunnerResults: function () {
+ log.test("");
+ summaryLine(this.total.passed, this.total.failed, "spec");
+ log.test("Runner Finished");
+ },
+ reportSpecStarting: function (spec) {
+ if (spec.suite.description !== this.current.description) {
+ if (spec.suite.description === this.current.parent) {
+ this.current.parent = null;
+ log.test("");
+ } else {
+ log.test("");
+ log.test(ansi.bold_on + (this.level === 0 ? "" : " ") + spec.suite.description + ansi.bold_off);
+ if (this.level !== 0 && this.current.parent === null) {
+ this.current.parent = this.current.description;
+ };
+ this.level++;
+ }
+ this.current.description = spec.suite.description;
+ }
+ },
+ reportSpecResults: function(spec) {
+ if (spec.results().passed()) {
+ log.test(ansi.green + "" + ansi.none + spec.description);
+ this.total.passed += 1;
+ } else {
+ this.total.failed += 1;
+ }
+ var results = spec.results().getItems();
+ results.forEach(function(result) {
+ if (result.type === "log") {
+ log.test(result.toString());
+ } else if (result.type === 'expect' && (result.passed != null) && !result.passed()) {
+ log.fail(ansi.red + " X " + ansi.none + spec.description);
+ log.fail(ansi.red + " => " + result.message + ansi.none);
+ }
+ });
+ },
+ reportSuiteResults: function(suite) {
+ var results = suite.results();
+ if (!suite.parentSuite) {
+ summaryLine(results.passedCount, results.totalCount-results.passedCount, "test");
+ }
+ this.level--;
+ },
+ log: function(str) {
+ log.info(" " + str);
+ }
+}
+
+module.exports = TiShadowReporter;
Oops, something went wrong.

0 comments on commit 8879f34

Please sign in to comment.