Javascript Grunt jasmine测试在终端中失败,但在浏览器中失败

Javascript Grunt jasmine测试在终端中失败,但在浏览器中失败,javascript,jasmine,gruntjs,Javascript,Jasmine,Gruntjs,我已经使用grunt和jasmine设置了一些测试,但是当我尝试在终端中运行测试时遇到了一个问题。我看到这个错误: >> Error caught from phantom. More info can be found by opening the Spec Runner in a browser. 在浏览器中运行spec runner文件时,我看到所有测试都通过了,并且没有显示任何类型的错误 有人知道这个问题的原因吗 这是我的Grunfile文件: module.exports

我已经使用grunt和jasmine设置了一些测试,但是当我尝试在终端中运行测试时遇到了一个问题。我看到这个错误:

>> Error caught from phantom. More info can be found by opening the Spec Runner in a browser.
在浏览器中运行spec runner文件时,我看到所有测试都通过了,并且没有显示任何类型的错误

有人知道这个问题的原因吗

这是我的Grunfile文件:

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

};

谢谢你的帮助。

我遇到了同样的问题。在我的例子中,罪魁祸首似乎是select2库,但我必须使用一个消除过程来找出这一点

尝试直接通过phantomjs而不是通过grunt加载
\u SpecRunner.html
。我使用了一个基本的包装器脚本,基本上和你在PhantomJS主页上看到的一样,这样我就可以一个接一个地删除runner中的脚本标记,直到我得到了一个不会抛出语法错误的东西

如果使用
--force
运行grunt任务,还可能会获得有关错误源的更多详细信息

我无法确定错误的根本原因

对我来说,在
grunfile.js
中添加正确的
host
选项修复了控制台测试(浏览器测试已经工作)

茉莉花:{ 测试:{ src:['src/.js'], 选项:{ 规格:['spec/*-spec.js'], outfile:'spec.html', 基普朗纳:是的, 主持人:'http://example.com/folder-containing-to-spec-file/', 供应商:['vendor/file.js'] } } } }
如果没有
host
选项,它看起来像是Phantomjs从
file:///users/path/to/local/files
这(显然)不是浏览器可以从中请求内容的服务器(在本地工作时)。

谢谢你的回答,但经过几个小时的尝试,我终于让它工作了。我从来没有发现问题是什么,我只是从零开始。你能在这里发布你的编辑吗@DavidJones,遇到同样的问题。
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']
           }
       }
    }
}