2013-10-31 73 views
8

我已經設置了一些測試使用咕嚕和茉莉花,但我遇到了一個問題,當我嘗試在終端中運行測試。我看到這個錯誤:咕嚕茉莉測試失敗在終端,但不是瀏覽器

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

當我運行在我看到我所有的測試都通過瀏覽器,沒有任何形式的錯誤規範亞軍文件顯示。

有誰知道可能是這個問題的原因是什麼?

這裏是我的Gruntfile:

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' ]); 

}; 

感謝您的幫助。

回答

1

我遇到了同樣的問題。在我的情況下,罪魁禍首似乎是select2庫,但我必須使用消除過程來弄清楚。

嘗試通過phantomjs直接加載_SpecRunner.html,而不是通過咕嚕聲。我使用了一個基本的包裝腳本,它基本上與您在PhantomJS主頁上看到的基本相同,這樣我就可以一個接一個地將跑步者中的腳本標籤一個接一個地打碎,直到我有些東西沒有拋出語法錯誤。

如果您使用--force運行grunt任務,還可能會獲得有關錯誤來源的更多詳細信息。

我無法確定錯誤的根本原因。

+0

感謝您的答案,但經過幾個小時的努力,我終於找到了工作。從來沒有找到我剛剛從頭開始的問題。 –

+0

您可以在這裏發佈您的修改@DavidJones,運行到相同的問題。 – smk

0

對於我來說,加入正確host選項來Gruntfile.js固定在控制檯測試(測試瀏覽器已經工作)。

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'] 
      } 
     } 
    } 
} 

沒有host選項,它看上去就像Phantomjs從file:///users/path/to/local/files請求含量(顯然)不是(在本地工作時)瀏覽器可以請求內容的服務器。