Permalink
Browse files

update submodule gem

add js tests
  • Loading branch information...
1 parent 8e7b042 commit 85fdfcc3acbed7b760be2dac7c7dc5895beee087 @stereobooster committed May 22, 2012
Showing with 83 additions and 8 deletions.
  1. +38 −6 Rakefile
  2. +1 −2 html_minifier.gemspec
  3. +44 −0 spec/qunit_helper.js
View
@@ -5,22 +5,54 @@ require "bundler/gem_tasks"
end
require 'submodule'
-class HtmlMinifierSubmodule < Submodule::Task
- # def test
- # end
- def after_pull
+Submodule::Task.new do |t|
+ t.branch = "gh-pages"
+
+ t.test do
+ js = []
+ js << File.open(File.expand_path("../lib/js/console.js", __FILE__), "r:UTF-8").read
+ %w{htmlparser htmllint htmlminifier}.each do |i|
+ js << File.open("src/#{i}.js", "r:UTF-8").read
+ end
+ js << File.open("tests/qunit.js", "r:UTF-8").read
+ js << File.open(File.expand_path("../spec/qunit_helper.js", __FILE__), "r:UTF-8").read
+ %w{minify_test lint_test}.each do |i|
+ js << File.open("tests/#{i}.js", "r:UTF-8").read
+ end
+
+ require "execjs"
+ context = ExecJS.compile js.join("\n")
+ result = context.exec "return QUnit.result();"
+ if result["assertions"].respond_to?(:each)
+ puts "Failures:"
+ i = 1
+ result["assertions"].each do |test, details|
+ puts " #{i}) #{test}"
+ puts " Failure/Error: #{details[0]}"
+ puts " expected: #{details[1].inspect}"
+ puts " got: #{details[2].inspect}"
+ i+=1
+ end
+ end
+ # (#{result['pass_asserions']}) (#{result['fail_asserions']})
+ puts "Pass: #{result['pass']}, Fail: #{result['fail']}"
+ if result["fail"] > 0
+ abort
+ end
+ end
+
+ t.after_pull do
%w{htmlparser htmllint htmlminifier}.each do |i|
cp "vendor/html-minifier/src#{i}.js", "lib/js/#{i}.js"
sh "git add lib/js/#{i}.js"
end
end
end
-HtmlMinifierSubmodule.new
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new
-task :default => :spec
+task :default => [:spec, "submodule:test"]
#desc "Generate code coverage"
# RSpec::Core::RakeTask.new(:coverage) do |t|
View
@@ -16,9 +16,8 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- # specify any dependencies here; for example:
s.add_development_dependency "rspec"
- s.add_development_dependency "submodule", ">=0.0.3"
+ s.add_development_dependency "submodule", ">= 0.1.0"
s.add_runtime_dependency "rake"
s.add_dependency "multi_json", ">= 1.3"
View
@@ -0,0 +1,44 @@
+(function(QUnit) {
+
+ QUnit.init();
+ QUnit.config.blocking = false;
+ QUnit.config.autorun = true;
+ QUnit.config.updateRate = 0;
+
+ var assertions,
+ result = {
+ pass: 0,
+ fail: 0,
+ pass_asserions: 0,
+ fail_asserions: 0,
+ assertions: {},
+ tests: 0
+ };
+
+ QUnit.testDone(function (r) {
+ if (r.failed > 0) {
+ result.fail += 1;
+ result.assertions[(r.module ? r.module + ':' : '') + r.name] = assertions;
+ assertions = null;
+ } else {
+ result.pass += 1;
+ }
+ result.fail_asserions += r.failed;
+ result.pass_asserions += r.passed;
+ result.tests++;
+ });
+
+ QUnit.log(function (r) {
+ if (!r.result) {
+ assertions = [r.message, r.actual, r.expected];
+ }
+ });
+
+ QUnit.result = function () {
+ // run the tests
+ // QUnit.begin();
+ // QUnit.start();
+ return result;
+ };
+
+}( QUnit ));

0 comments on commit 85fdfcc

Please sign in to comment.