Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';不需要带下划线的CasperJS_Javascript_Node.js_Phantomjs_Casperjs - Fatal编程技术网

Javascript Can';不需要带下划线的CasperJS

Javascript Can';不需要带下划线的CasperJS,javascript,node.js,phantomjs,casperjs,Javascript,Node.js,Phantomjs,Casperjs,我正在使用CasperJS运行自动化前端测试,但在测试中遇到了使用其他npm模块的问题。我知道patchRequire,但是我认为这只能在测试环境之外调用,因为测试运行程序补丁需要自动调用。我确实包括了它,但结果是一样的。它说找不到模块。我已确认下划线模块已安装在项目根文件夹的node\u modules中 代码 'use strict' _ = require 'underscore' testConfig = testPageUrl: '' testSearchTerm:

我正在使用
CasperJS
运行自动化前端测试,但在测试中遇到了使用其他npm模块的问题。我知道
patchRequire
,但是我认为这只能在测试环境之外调用,因为测试运行程序补丁需要自动调用。我确实包括了它,但结果是一样的。它说找不到模块。我已确认下划线模块已安装在项目根文件夹的
node\u 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:找不到模块下划线


所以我最终找到的解决方案是创建代理模块,导入npm模块并将其导出到casper脚本

/proxies/underline.js:

module.exports = require('underscore');
/tests/test.js

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