单元测试错误输出“致命错误:写完后”

时间:2014-06-17 04:01:29

标签: javascript unit-testing karma-runner browserify karma-jasmine

我正在使用grunt-karma在PhantomJS浏览器中运行用Jasmine编写的单元测试。我正在测试的代码使用browserify。

当我运行grunt karma时,它会加载我的模块,然后使用Fatal error: write after end输出错误。终端输出如下:

Camerons-MacBook-Pro:Bookmarklet cameronnokes$ grunt karma
Running "karma:unit" (karma) task
DEBUG [config]: autoWatch set to false, because of singleRun
DEBUG [plugin]: Loading karma-* from /Users/cameronnokes/Repositories/Bookmarklet/node_modules
DEBUG [plugin]: Loading plugin /Users/cameronnokes/Repositories/Bookmarklet/node_modules/karma-browserify.
DEBUG [plugin]: Loading plugin /Users/cameronnokes/Repositories/Bookmarklet/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /Users/cameronnokes/Repositories/Bookmarklet/node_modules/karma-phantomjs-launcher.
DEBUG [preprocessor.browserify (framework)]: Writing to temp file: "22844b46ae091ac715aedfae5d2497cb".
INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
DEBUG [temp-dir]: Creating temp dir at /var/folders/vs/zn48bjc56pj8b606y4db_k5m0000gn/T/karma-98875158
DEBUG [launcher]: /usr/local/bin/phantomjs /var/folders/vs/zn48bjc56pj8b606y4db_k5m0000gn/T/karma-98875158/capture.js
DEBUG [preprocessor.browserify]: Processing "/Users/cameronnokes/Repositories/Bookmarklet/test/test/content.test.js".
DEBUG [preprocessor.browserify]: Processing "/Users/cameronnokes/Repositories/Bookmarklet/test/test/messaging.test.js".
DEBUG [preprocessor.browserify]: Processing "/Users/cameronnokes/Repositories/Bookmarklet/test/test/store.test.js".
DEBUG [preprocessor.browserify]: Processing "/Users/cameronnokes/Repositories/Bookmarklet/test/test/tracking.test.js".
Fatal error: write after end

谷歌搜索此错误不会产生任何影响。有没有人对这里发生的事情有任何想法? (如果您需要我提供更多信息,请告诉我。)

1 个答案:

答案 0 :(得分:2)

当browserify解析规范文件时,第二次调用require时出现相同的错误。

根据this thread的建议,尝试升级您的浏览器安装:

npm install --save-dev browserify@^4.0.0

显示已安装的browserify版本:

$ npm list browserify
app/
├── browserify@4.2.3
├─┬ gulp-browserify@0.4.6
│ └── browserify@3.46.1
└─┬ watchify@1.0.6
  └── browserify@5.13.1