karma-sinon-chai fails after moving to Windows

那年仲夏 提交于 2019-12-11 20:36:14

问题


I have unit tests running under Karma, and am using the sinon-chai library.

Everything was working fine on Mac, but now I have moved to Windows the following error is occuring:

C:\Users\mchambe4\dev\simple\client>node ./node_modules/gulp/bin/gulp.js unit-tests-dev
[16:29:31] Using gulpfile ~\dev\simple\client\gulpfile.js
[16:29:31] Starting 'unit-tests-dev'...
[16:29:31] Starting Karma server...
WARN [karma]: Port 9876 in use
INFO [karma]: Karma v0.12.37 server started at http://localhost:9877/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Connected on socket fMujwCqRPdmidI3BtCYV with id 16821903
PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR
  ReferenceError: Can't find variable: chai
  at C:/Users/mchambe4/dev/simple/client/node_modules/karma-sinon-chai/node_modules/sinon-chai/lib/sinon-chai.js:17

From that file:

if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
    // NodeJS
    module.exports = sinonChai;  // <---- should go in here
} else if (typeof define === "function" && define.amd) {
    // AMD
    define(function () {
        return sinonChai;
    });
} else {
    // Other environment (usually <script> tag): plug in to global chai instance directly.
    chai.use(sinonChai);         // <---- actually ends up here
}

I would expect the condition on the first line to return true because I am running in Node, but for some reason neither 'require' or module are defined, so it ends up at the point indicated above.

Any ideas?


回答1:


Downgrading karma-sinon-chai from 1.0.0 to 0.3.2 fixed this problem for us. A github issue has already been filed, I assume this will be fixed very quickly. https://github.com/kmees/karma-sinon-chai/issues/21

npm install karma-sinon-chai@0.3.2 --save-dev


来源:https://stackoverflow.com/questions/31469889/karma-sinon-chai-fails-after-moving-to-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!