我在用着CasperJS
运行自动化前端测试,但在我的测试中使用其他 npm 模块时遇到了问题。我知道patchRequire
但是我相信这只能在测试环境之外调用,因为测试运行程序补丁会自动需要。我确实包含了它,但结果是一样的。它说找不到该模块。我已经确认下划线模块已安装在node_modules
在项目根文件夹中。
Code
'use strict'
_ = require 'underscore'
testConfig =
testPageUrl: ''
testSearchTerm: 'the'
config = _.extend testConfig, require 'common/config'
JavaScript 代码
'use strict';
_ = require('underscore');
testConfig = {
testPageUrl: '',
testSearchTerm: 'the'
};
config = _.extend(testConfig, require('common/config'));
Error
CasperError:找不到模块下划线
所以我最终找到的解决方案是创建代理模块,导入 npm 模块并将其导出到 casper 脚本。
./proxies/underscore.js:
module.exports = require('underscore');
./tests/test.js
var _ = require('../proxies/underscore');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)