用CasperJS不能要求下划线

我使用CasperJS来运行自动化的前端testing,但在我的testing中遇到了使用其他npm模块的问题。 我知道patchRequire但我相信只能在testing环境之外被调用,因为testing运行器补丁需要自动执行。 我包括它,但结果是一样的。 它说它无法find模块。 我已经确认下划线模块安装在项目根文件夹中的node_modules中。

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

错误

CasperError:找不到模块下划线

所以我最终发现的解决scheme是创build代理模块,导入npm模块并将其导出到casper脚本。

./proxies/underscore.js:

 module.exports = require('underscore'); 

./tests/test.js

 var _ = require('../proxies/underscore');