1

ビルド サーバーでヘッドレス ジャスミン テストを実行し、結果を junit 形式で出力するように rake タスクをセットアップしました。タスクは次のとおりです。

namespace :jasmine do                                                                             
  desc "Runs Jasmine tests headlessly and writes out junit xml."                                  
  task :headless_junit do |t, args|                                                               
    run_jasmine_tests(Dir.pwd)                                                                    
  end                                                                                             
end                                                                                               

def run_jasmine_tests(output_dir)                                                                 
  require 'headless'                                                                              
  require 'jasmine'                                                                               
  require 'rspec'                                                                                 
  require 'rspec/core/rake_task'                                                                  

  output_file = "#{output_dir}/jasmine_results.xml"                                               

  Headless.ly do                                                                                  
    RSpec::Core::RakeTask.new(:jasmine_continuous_integration_runner) do |t|                      
      t.rspec_opts = ['--format', 'RspecJunitFormatter', '--out', output_file ]                   
      t.verbose = true                                                                            
      t.rspec_opts += ["-r #{File.expand_path(File.join(::Rails.root, 'config', 'environment'))}"]
      t.pattern = [Jasmine.runner_filepath]                                                       
    end                                                                                           

    Rake::Task['jasmine_continuous_integration_runner'].invoke                                    
  end                                                                                             

end                                                                                               

これを実行すると、次のエラーが発生します。

TypeError: jasmine.getEnv(...).currentSpec is null in http://localhost:34002/assets/jquery.js?body=true (line 1129)
expect@http://localhost:34002/assets/jquery.js?body=true:1129                                                      
@http://localhost:34002/__spec__/activity_catalog_search_filters_spec.js:15                                        
jasmine.Block.prototype.execute@http://localhost:34002/__jasmine__/jasmine.js:1064                                 
jasmine.Queue.prototype.next_@http://localhost:34002/__jasmine__/jasmine.js:2096
jasmine.Queue.prototype.next_/onComplete/<@http://localhost:34002/__jasmine__/jasmine.js:2086
... LOTS MORE ...

Rails 3.2.13、jasmine 1.3.2、headless 1.0.1、rspec 2.14.1、Jasmine-jQuery 1.5.8 を使用しています。

この男が抱えている問題に似ていると思います: TypeError: jasmine.getEnv().currentSpec is null

4

1 に答える 1

1

jQuery.get問題は、URL を dom にロードするために使用していたテストにあったことが判明しました。空の文字列が URL として渡されていましたが (テスト ライターはロードされたものをあまり気にしていなかったので)、jQuery が現在のページをフェッチし (jasmine テスト自体)、それを dom にロードしました。大混乱が続いた。

より興味深い (そしておそらくより役立つ) ことは、それをどのように把握したかということです。ファンシーレーキタスクは問題ではなかったことがわかりました。ヘッドレス テストで Firefox を使用しているだけで、通常は手動で chrome にロードしますが、このエラーは発生していないようです。Firefox でエラーを再現した場合、デバッガーで原因を突き止めるのは簡単でした。

つまり、ci テストが失敗し、それを再現できない場合は、Firefox で手動で読み込んでみてください。

于 2013-10-22T13:20:47.910 に答える