2013-10-31 14 views
8

私はgruntとjasmineを使っていくつかのテストを設定しましたが、ターミナルでテストを実行しようとすると問題に遭遇します。私はすべての私のテストに合格し、いかなる種類のエラーが表示されていないことを確認し、ブラウザでのスペックランナーファイルを実行するとターミナルではグラスジャスミンテストは失敗しますが、ブラウザでは失敗します

>> Error caught from phantom. More info can be found by opening the Spec Runner in a browser. 

:私はこのエラーを参照してください。

誰でもこの問題の原因が分かっていますか?任意の助け

module.exports = function(grunt) { 

    grunt.initConfig({ 

pkg: grunt.file.readJSON('package.json'), 

/** 
* Uglify task to minify all javscript files 
* seperating out all script files into a development directory 
* and then having all 'production' scripts within a product directory 
* 
* Note: Will need a bit of work to target the plugins folder 
*  independently to the main apps - as we may have unminified 
*  versions - aswell as our Backbone views. 
*/ 
uglify: { 
    options: { 
    mangle: false 
    }, 
    files: { 
     src: 'assets/scripts/development/*.js', // source files mask 
     dest: 'assets/scripts/production/', // destination folder 
     expand: true, // allow dynamic building 
     flatten: true, // remove all unnecessary nesting 
     ext: '.min.js' // replace .js to .min.js 
    } 
}, 

/** 
* Sass module compiles all SASS files 
* This quickly avoids having to open and save 
* every single css file if a conflict is present 
*/ 
sass: { 
    dist: { 
    files: [{ 
     expand: true, 
     cwd: 'assets/styles/sass/', 
     src: ['*.scss'], 
     dest: 'assets/styles/', 
     ext: '.css' 
    }] 
    } 
}, 

/** 
* Image minification for compressing images 
* accross the project and moving them into their own folder 
* all references once production has gone through points to those 
*/ 
imagemin: { 
    png: { 
     options: { 
      optimizationLevel: 7 
     }, 
     files: [ 
      { 
       expand: true, 
       cwd: 'assets/images/', 
       src: ['**/*.png'], 
       dest: 'assets/images/compressed/', 
       ext: '.png' 
      } 
     ] 
    }, 
    jpg: { 
     options: { 
      progressive: true 
     }, 
     files: [ 
      { 
       expand: true, 
       cwd: 'assets/images/', 
       src: ['**/*.jpg'], 
       dest: 'assets/images/compressed/', 
       ext: '.jpg' 
      } 
     ] 
    } 
}, 

/** 
* PHP Code Standards fixer 
* Runs through the app (main code base for each project) 
* to ensure conforms to a standard 
*/ 
phpcsfixer: { 
    app: { 
     dir: 'app' 
    }, 
    options: { 
     bin: 'php-cs-fixer', 
     ignoreExitCode: true, 
     level: 'all', 
     quiet: false, 
     diff: true, 
     verbose: true 
    } 
}, 

jasmine : { 
    src : 'assets/scripts/views/*.js', 
    options : { 
    specs : 'assets/scripts/tests/*.js' 
     } 
    } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-jasmine'); 
    grunt.loadNpmTasks('grunt-php-cs-fixer'); 
    grunt.loadNpmTasks('grunt-contrib-imagemin'); 
    grunt.loadNpmTasks('grunt-contrib-sass'); 
    // Load the plugin that provides the "uglify" task. 
    grunt.loadNpmTasks('grunt-contrib-uglify'); 

    // Default task(s). 
    grunt.registerTask('default', [ 'uglify', 'sass' ]); 

    //Jasmine unit tests 
    grunt.registerTask('test', [ 'jasmine' ]); 

}; 

ありがとう:

は、ここに私のGruntfileです。

答えて

1

同じ問題が発生しました。私の場合、犯人はselect2ライブラリだったようですが、私はこれを理解するために消去プロセスを使わなければなりませんでした。

_SpecRunner.htmlを読み込んでみてください。私はPhantomJSのホームページに表示されているものと本質的に同じ基本ラッパスクリプトを使用しています。そのため、構文エラーが発生しない限り、ランナーのスクリプトタグを1つずつ切り離すことができます。

また、--forceでgruntタスクを実行すると、エラーの原因に関する詳細が表示されることがあります。

エラーの根本原因を特定できませんでした。

+0

お返事ありがとうございます。でも、試してみた後、ついにそれが動作しました。私が始めたばかりの問題が何であったかは、決して見つけられませんでした。 –

+0

あなたはここに@DavidJonesの編集を投稿してもらえますか?同じ問題が発生しました。 – smk

0

正しいhostオプションをGruntfile.jsに追加すると、コンソールテスト(すでに動作しているブラウザテスト)が修正されました。 hostオプションを指定しない

jasmine: { 
    test: { 
     src: ['src/<%= pkg.name %>.js'], 
      options: { 
       specs: ['spec/*-spec.js'], 
       outfile: 'spec.html', 
       keepRunner: true, 
       host: 'http://example.com/folder-containing-to-spec-file/', 
       vendor: ['vendor/file.js'] 
      } 
     } 
    } 
} 

Phantomjsは(明らかに)(ローカルで作業する場合)、ブラウザからコンテンツを要求することができ、サーバーではありませんどのfile:///users/path/to/local/filesからコンテンツを要求したように、それが見えました。

関連する問題