Skip to content

Commit

Permalink
Run jshint with tests now
Browse files Browse the repository at this point in the history
  • Loading branch information
wagenet committed Mar 7, 2012
1 parent 606d65a commit 93193d6
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ rvm:
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- "npm install -g jshint"
script: "rake test[all] && rake jshint"
script: "rake test[all]"
14 changes: 14 additions & 0 deletions Assetfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class EmberLicenseFilter < Rake::Pipeline::Filter
end
end

class JSHintRC < Rake::Pipeline::Filter
def generate_output(inputs, output)
inputs.each do |input|
file = File.read(input.fullpath)
jshintrc = File.read(".jshintrc")
output.write "var JSHINTRC = #{jshintrc};\n\n#{file}"
end
end
end

distros = {
:runtime => %w(ember-metal ember-runtime),
:full => %w(handlebars ember-metal ember-runtime ember-views ember-states metamorph ember-handlebars)
Expand All @@ -44,6 +54,10 @@ input "packages" do

concat "ember-tests.js"
end

match "ember-tests.js" do
filter JSHintRC
end
end

input "packages" do
Expand Down
21 changes: 5 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,6 @@ namespace :docs do
end
end

desc "Run jshint"
task :jshint do
unless system("which jshint > /dev/null 2>&1")
abort "Please install jshint. `npm install -g jshint`"
end

if system("jshint packages/ember*")
puts "The JavaScript is clean".green
else
puts "The JavaScript is dirty".red
exit(1)
end
end


desc "Run tests with phantomjs"
task :test, [:suite] => :dist do |t, args|
unless system("which phantomjs > /dev/null 2>&1")
Expand All @@ -311,7 +296,11 @@ task :test, [:suite] => :dist do |t, args|

suites = {
:default => ["package=all"],
:all => ["package=all", "package=all&jquery=1.6.4", "package=all&extendprototypes=true", "package=all&extendprototypes=true&jquery=1.6.4"]
:all => ["package=all",
"package=all&jquery=1.6.4&nojshint=true",
"package=all&extendprototypes=true&nojshint=true",
"package=all&extendprototypes=true&jquery=1.6.4&nojshint=true",
"package=all&dist=build"]
}

suite = args[:suite] || :default
Expand Down
82 changes: 65 additions & 17 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,39 @@
<title>QUnit Test Suite</title>
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit/qunit.js"></script>
<script type="text/javascript" src="jshint.js"></script>
<script type="text/javascript" src="minispade.js"></script>

<script type="text/javascript">
// Handle JSHint
QUnit.config.urlConfig.push('nojshint');

var noJsHint = location.search.match(/nojshint=([^&]+)/);
jsHint = !(noJsHint && decodeURIComponent(noJsHint[1]));

var jsHintReporter = function (file, errors) {
var len = errors.length,
str = '',
error;

errors.forEach(function (error) {
str += file + ': line ' + error.line + ', col ' +
error.character + ', ' + error.reason + '\n';
});

if (str) {
return str + "\n" + len + ' error' + ((len === 1) ? '' : 's');
}
}


// Handle extending prototypes
QUnit.config.urlConfig.push('extendprototypes');

window.ENV = window.ENV || {};
var extendPrototypes = location.search.match(/extendprototypes=([^&]+)/);
ENV['EXTEND_PROTOTYPES'] = !!(extendPrototypes && decodeURIComponent(extendPrototypes[1]));
</script>
</head>
<body>
<h1 id="qunit-header">QUnit Test Suite</h1>
Expand All @@ -30,30 +63,30 @@ <h2 id="qunit-userAgent"></h2>
if (console && console.warn) { console.warn("Unable to load jQuery "+jQueryVersion+". Using default."); }
document.write(unescape('%3Cscript src="jquery-1.7.1.js"%3E%3C/script%3E'));
}
// Close the script tag to make sure document.write happens
</script>

<script type="text/javascript">
// Handle extending prototypes
QUnit.config.urlConfig.push('extendprototypes');

window.ENV = window.ENV || {};
var extendPrototypes = location.search.match(/extendprototypes=([^&]+)/);
ENV['EXTEND_PROTOTYPES'] = !!(extendPrototypes && decodeURIComponent(extendPrototypes[1]));
</script>

<script type="text/javascript" src="minispade.js"></script>

<script>
// Load ember distribution from query vars
var distMatch = location.search.match(/dist=([^&]+)/),
dist = distMatch && distMatch[1],
emberPath = "../dist/ember"+(dist ? '-' + dist : '')+".js";
document.write(unescape('%3Cscript src="'+emberPath+'"%3E%3C/script%3E'));
dist = (distMatch && distMatch[1]) || 'spade';

var distros = {
spade: 'ember-spade.js',
build: 'ember.js',
runtime: 'ember-runtime.js'
};

var emberFile = distros[dist];
if (!emberFile) { throw 'Unknown dist'; }

document.write(unescape('%3Cscript src="../dist/'+emberFile+'"%3E%3C/script%3E'));
// Close the script tag to make sure document.write happens
</script>

<script type="text/javascript" src="ember-tests.js"></script>

<script>
<script type="text/javascript">

// hack qunit to not suck for Ember objects
var originalTypeof = QUnit.jsDump.typeOf;
Expand Down Expand Up @@ -111,8 +144,23 @@ <h2 id="qunit-userAgent"></h2>
if (!minispade.modules.hasOwnProperty(moduleName)) { continue; }

match = moduleName.match(re);
if (match && match[1] === '~tests') {
minispade.require(moduleName);
if (match) {
if (match[1] === '~tests') {
// Only require the actual tests since we already required the module
minispade.require(moduleName);
}

if (jsHint) {
// JSHint all modules in this package, tests and code
// (closure to preserve variable values)
(function() {
var jshintModule = moduleName;
test(jshintModule+' should pass jshint', function() {
var result = JSHINT(minispade.modules[jshintModule], JSHINTRC);
ok(result, jshintModule+" should pass jshint.\n" + jsHintReporter(jshintModule, JSHINT.errors));
});
})();
}
}
}
}
Expand Down

0 comments on commit 93193d6

Please sign in to comment.