Permalink
Browse files

jshint and spec tasks working

  • Loading branch information...
1 parent 62a97f3 commit 753e0c0939bdc0c43415b7e41bfef24f86d03c33 James A. Rosen committed Sep 23, 2012
View
@@ -1,2 +1,3 @@
+/.jhw-cache
/components
/node_modules
View
@@ -0,0 +1,37 @@
+{
+ "predef": [
+ "module", "Em", "Ember",
+ "expect", "it", "describe", "xit", "xdescribe", "beforeEach", "afterEach",
+ "jasmine", "spyOn", "runs", "waitsFor"
+ ],
+
+ "bitwise": true,
+ "newcap": false,
+ "eqeqeq": false,
+ "eqnull": true,
+ "immed": true,
+ "nomen": false,
+ "onevar": false,
+ "plusplus": false,
+ "regexp": false,
+ "strict": false,
+ "undef": true,
+ "white": false,
+
+ "debug": false,
+ "es5": false,
+ "evil": false,
+ "forin": false,
+ "laxbreak": false,
+ "sub": false,
+
+ "maxlen": 200,
+ "indent": 2,
+ "maxerr": 50,
+ "passfail": false,
+ "browser": true,
+ "rhino": false,
+ "devel": true,
+ "lastsemic": false,
+ "expr": true
+}
View
@@ -3,6 +3,7 @@ source :rubygems
group :development do
gem 'rake', '~> 0.9'
gem 'execjs', '~> 1.4'
+ gem 'multi_json', '~> 1.3'
end
group :test do
View
@@ -59,4 +59,5 @@ DEPENDENCIES
execjs (~> 1.4)
jasmine (~> 1.2.1)
jasmine-headless-webkit
+ multi_json (~> 1.3)
rake (~> 0.9)
View
@@ -0,0 +1,18 @@
+require 'pathname'
+require 'multi_json'
+
+# Build information:
+
+PROJECT_ROOT = Pathname.new( File.expand_path(File.dirname(__FILE__)) )
+
+VERSION = MultiJson.decode(
+ File.read( PROJECT_ROOT.join('component.json') )
+ )['version']
+
+LIB_FILES = [ 'BarView' ].map do |f|
+ PROJECT_ROOT.join "lib/#{f}.js"
+end
+
+Dir.glob( PROJECT_ROOT.join('lib/**/*.rake') ).each { |task| load task }
+
+task :spec => :jshint
View
@@ -0,0 +1,3 @@
+Ember.ProgressBars = Ember.ProgressBars || {};
+
+Ember.ProgressBars.Bar = Ember.View.extend();
View
@@ -0,0 +1,16 @@
+namespace :jshint do
+
+ task :check do
+ runner = PROJECT_ROOT.join 'node_modules/jshint/bin/hint'
+ config_file = PROJECT_ROOT.join '.jshintrc'
+ sh "#{runner} #{LIB_FILES.join(' ')} --config #{config_file}" do |ok, res|
+ fail 'JSHint found errors in source.' unless ok
+ end
+
+ puts "JSHint checks passed"
+ end
+
+end
+
+desc 'Run JSHint checks'
+task :jshint => 'jshint:check'
View
@@ -0,0 +1,7 @@
+desc "Run tests"
+task :spec do
+ sh "bundle exec jasmine-headless-webkit" do |ok, res|
+ fail "Test failures" unless ok
+ end
+ puts "Tests passed"
+end
@@ -0,0 +1,7 @@
+describe('ProgressBars.Bar', function() {
+
+ it('is an Em.View subclass', function() {
+ expect( Em.View.detect(Em.ProgressBars.Bar) ).toBe(true);
+ });
+
+});
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Jasmine Test Runner</title>
+
+ <!-- These files power Jasmine -->
+ <link rel="stylesheet" type="text/css" href="./support/jasmine.css">
+ <script type="text/javascript" src="./support/jasmine.js"></script>
+ <script type="text/javascript" src="./support/jasmine-html.js"></script>
+ <script type="text/javascript" src="./support/json2.js"></script>
+ <script type="text/javascript" src="../../components/ember/lib/jquery-1.7.2.js"></script>
+ <script type="text/javascript" src="../../components/ember/lib/ember.js"></script>
+ <script type="text/javascript" src="../../lib/BarView.js"></script>
+ <script type="text/javascript" src="./BarView.spec.js"></script>
+
+ </head>
+ <body>
+
+ <script type="text/javascript">
+ jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
+ jasmine.getEnv().execute();
+ </script>
+
+ </body>
+</html>
@@ -0,0 +1,3 @@
+var ENV = {
+ CP_DEFAULT_CACHEABLE: true
+}
@@ -0,0 +1,188 @@
+jasmine.TrivialReporter = function(doc) {
+ this.document = doc || document;
+ this.suiteDivs = {};
+ this.logRunningSpecs = false;
+};
+
+jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
+ var el = document.createElement(type);
+
+ for (var i = 2; i < arguments.length; i++) {
+ var child = arguments[i];
+
+ if (typeof child === 'string') {
+ el.appendChild(document.createTextNode(child));
+ } else {
+ if (child) { el.appendChild(child); }
+ }
+ }
+
+ for (var attr in attrs) {
+ if (attr == "className") {
+ el[attr] = attrs[attr];
+ } else {
+ el.setAttribute(attr, attrs[attr]);
+ }
+ }
+
+ return el;
+};
+
+jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
+ var showPassed, showSkipped;
+
+ this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
+ this.createDom('div', { className: 'banner' },
+ this.createDom('div', { className: 'logo' },
+ this.createDom('a', { href: 'http://pivotal.github.com/jasmine/', target: "_blank" }, "Jasmine"),
+ this.createDom('span', { className: 'version' }, runner.env.versionString())),
+ this.createDom('div', { className: 'options' },
+ "Show ",
+ showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
+ showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
+ )
+ ),
+
+ this.runnerDiv = this.createDom('div', { className: 'runner running' },
+ this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
+ this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
+ this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
+ );
+
+ this.document.body.appendChild(this.outerDiv);
+
+ var suites = runner.suites();
+ for (var i = 0; i < suites.length; i++) {
+ var suite = suites[i];
+ var suiteDiv = this.createDom('div', { className: 'suite' },
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
+ this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
+ this.suiteDivs[suite.id] = suiteDiv;
+ var parentDiv = this.outerDiv;
+ if (suite.parentSuite) {
+ parentDiv = this.suiteDivs[suite.parentSuite.id];
+ }
+ parentDiv.appendChild(suiteDiv);
+ }
+
+ this.startedAt = new Date();
+
+ var self = this;
+ showPassed.onclick = function(evt) {
+ if (showPassed.checked) {
+ self.outerDiv.className += ' show-passed';
+ } else {
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
+ }
+ };
+
+ showSkipped.onclick = function(evt) {
+ if (showSkipped.checked) {
+ self.outerDiv.className += ' show-skipped';
+ } else {
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
+ }
+ };
+};
+
+jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
+ var results = runner.results();
+ var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
+ this.runnerDiv.setAttribute("class", className);
+ //do it twice for IE
+ this.runnerDiv.setAttribute("className", className);
+ var specs = runner.specs();
+ var specCount = 0;
+ for (var i = 0; i < specs.length; i++) {
+ if (this.specFilter(specs[i])) {
+ specCount++;
+ }
+ }
+ var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
+ message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
+ this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
+
+ this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
+};
+
+jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
+ var results = suite.results();
+ var status = results.passed() ? 'passed' : 'failed';
+ if (results.totalCount == 0) { // todo: change this to check results.skipped
+ status = 'skipped';
+ }
+ this.suiteDivs[suite.id].className += " " + status;
+};
+
+jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
+ if (this.logRunningSpecs) {
+ this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
+ }
+};
+
+jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
+ var results = spec.results();
+ var status = results.passed() ? 'passed' : 'failed';
+ if (results.skipped) {
+ status = 'skipped';
+ }
+ var specDiv = this.createDom('div', { className: 'spec ' + status },
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
+ this.createDom('a', {
+ className: 'description',
+ href: '?spec=' + encodeURIComponent(spec.getFullName()),
+ title: spec.getFullName()
+ }, spec.description));
+
+
+ var resultItems = results.getItems();
+ var messagesDiv = this.createDom('div', { className: 'messages' });
+ for (var i = 0; i < resultItems.length; i++) {
+ var result = resultItems[i];
+
+ if (result.type == 'log') {
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
+
+ if (result.trace.stack) {
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
+ }
+ }
+ }
+
+ if (messagesDiv.childNodes.length > 0) {
+ specDiv.appendChild(messagesDiv);
+ }
+
+ this.suiteDivs[spec.suite.id].appendChild(specDiv);
+};
+
+jasmine.TrivialReporter.prototype.log = function() {
+ var console = jasmine.getGlobal().console;
+ if (console && console.log) {
+ if (console.log.apply) {
+ console.log.apply(console, arguments);
+ } else {
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
+ }
+ }
+};
+
+jasmine.TrivialReporter.prototype.getLocation = function() {
+ return this.document.location;
+};
+
+jasmine.TrivialReporter.prototype.specFilter = function(spec) {
+ var paramMap = {};
+ var params = this.getLocation().search.substring(1).split('&');
+ for (var i = 0; i < params.length; i++) {
+ var p = params[i].split('=');
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
+ }
+
+ if (!paramMap["spec"]) return true;
+ return spec.getFullName().indexOf(paramMap["spec"]) == 0;
+};
Oops, something went wrong.

0 comments on commit 753e0c0

Please sign in to comment.