How do I load the node.js http module from within an intern.js test?

折月煮酒 提交于 2019-11-28 14:15:12

Intern runs its tests in an AMD environment, so require is the AMD loader's require, not Node's, hence your error.

To load Node modules, use the intern/dojo/node! AMD plugin and include them in your module's dependencies, e.g.:

define([
    ...,
    'intern/dojo/node!http'
], function (..., http) {
    // Now http contains the exports of Node's http module
});

This is documented in Intern's User Guide under Testing CommonJS Modules.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!