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

前端 未结 1 1400
一向
一向 2020-12-12 02:49

I am attempting to use the Intern test framework to automate testing of a simple REST API implemented with node.js and StrongLoop. StrongLoop provides an explorer web page

相关标签:
1条回答
  • 2020-12-12 03: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.

    0 讨论(0)
提交回复
热议问题