无法启动Karma测试:未捕获错误:模块名称“http”尚未加载

时间:2016-02-22 05:50:04

标签: angularjs node.js requirejs karma-jasmine

我在运行业力测试时遇到此错误

 params =  {"category"=>{"title"=>"Digital Marketing", "Apple"=>"0", "iPhone"=>"0", "iPad"=>"1", "Mac"=>"0", "Android"=>"0", "Samsung"=>"0", "Microsoft"=>"0", "Windows"=>"0", "Google"=>"0"}}

 if params['category']['iPad'].present?
   @category = "Ipad checked"
   end
 => "Ipad checked" 

 @category
 => "Ipad checked" 
 

它位于Uncaught Error: Module name "http" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded at C:/projects/xxx_Phase_II/xxx/xxx-web/src/test/javascript/config/node_modules/requirejs/require.js:140 第一行,其中

dev-rest-proxy.js

我的var http = require('http'); 看起来像这样

package.json

我的{ "name": "myApp", "description": "myApp Web UI", "engines": { "node": ">= 0.8.4" }, "dependencies": { "express": ">=3.x", "karma": ">=0.13", "request": ">=2.27.0" }, "scripts": { "pretest": "start node server.js", "karma": "node ./node_modules/karma/bin/karma start ./karma.unit.conf.js", "test": "node ./node_modules/karma/bin/karma start ./karma.e2e.conf.js" }, "version": "0.1.0", "devDependencies": { "jasmine-core": "^2.4.1", "jasmine-jquery": "^2.1.1", "karma-chrome-launcher": "^0.2.2", "karma-jasmine": "^0.3.7", "karma-requirejs": "^0.2.5", "dev-rest-proxy": "^0.3.0" } } 看起来像这样:

karma.unit.config.js

1 个答案:

答案 0 :(得分:0)

我修好了。我在files中提供的模式过于宽泛,因为它包括节点服务器端文件,如dev-rest-proxy.js。我的karma.unit.config.js有:

        files: [
           'app/vendor/**/**/*.js'
        ], 

所以它会包含这个文件:

app/vendor/node_modules/dev-rest-proxy/dev-rest-proxy.js

dev-rest-proxy是后端节点的东西,不应该加载到浏览器上,即它引用代码/模块,如' http'这纯粹是服务器端脚本。

我错过的重要线索是错误信息本身:

Module name “http” has not been loaded

http是节点的服务器端模块。