[英]'Cannot find module' error using karma-browserify on Windows
I'm attempting to set up unit testing on an Angular/Browserify project using Karma, Karma-Jasmine, and Karma-Browserify. 我正在尝试使用Karma,Karma-Jasmine和Karma-Browserify在Angular / Browserify项目上设置单元测试。 I'm on a Windows machine, for reference. 我在Windows机器上,供参考。 karma-cli
is on my global npm path, and karma
, karma-jasmine
, karma-browserify
, and browserify
are all local npm installs, using -D
. karma-cli
在我的全局npm路径上, karma
, karma-jasmine
, karma-browserify
和browserify
都是使用-D
本地npm安装。
I'm trying to pull in a single spec file, which looks like: 我正在尝试引入一个spec文件,看起来像:
var PhoneListCtrl = require('../../../public/js/app/controllers/phone-list');
describe('PhoneListCtrl', function() {
var scope,
ctrl;
beforeEach(function() {
scope = {};
ctrl = new PhoneListCtrl(scope);
});
it('should create "phones" model with 3 phones', function() {
expect(scope).not.toBe(undefined);
});
});
And I get the following error every time: 我每次都会收到以下错误:
Uncaught Error: Cannot find module 'Cc/gGH'
I get this exact same error after cloning the following repos, installing karma and all plugins, and attempting to run their example test suites: 克隆下面的repos,安装karma和所有插件,并尝试运行他们的示例测试套件后,我得到了完全相同的错误:
https://github.com/xdissent/karma-browserify https://github.com/xdissent/karma-browserify
https://github.com/waye929/angular-browserify https://github.com/waye929/angular-browserify
What on earth am I doing wrong? 我究竟做错了什么? The test spec module is found correctly, and karma seems to be finding all necessary plugins/preprocessors, but it appears that karma-browserify is tripping on the require
statement in a spec every time, for reasons I cannot fathom. 正确找到了测试规范模块,并且业力似乎正在寻找所有必要的插件/预处理器,但似乎karma-browserify每次都会在规范中触发require
语句,原因我无法理解。
I've uninstalled and reinstalled karma and all related plugins numerous times now, to no avail. 我已经多次卸载并重新安装业力和所有相关插件,但无济于事。
I managed to find a solution. 我设法找到了解决方案。 The issue was caused by karma-browserify
's own module name hashing function, which is incompatible with newer versions of browserify
. 该问题是由karma-browserify
自己的模块名称散列函数引起的,该函数与较新版本的browserify
不兼容。 There's a fork that deals with it by using browserify
's hashing function: 有一个fork使用browserify
的散列函数来处理它:
https://github.com/voidlock/karma-browserify/commit/3afe3b7485f2e4723bba5ad1c5a730d560b8c234 https://github.com/voidlock/karma-browserify/commit/3afe3b7485f2e4723bba5ad1c5a730d560b8c234
There's a pull request pending but in the meantime you can use the fork by placing 有拉动请求待定,但在此期间你可以通过放置使用fork
"karma-browserify": "https://github.com/voidlock/karma-browserify/tarball/use-browserify-hash-function"
in your package.json
(dev)dependencies section. 在package.json
(dev)依赖项部分中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.