Can't get Intern to run Node.js Module

眉间皱痕 提交于 2019-12-05 06:36:14

1. Assuming the following directory structure (based on the question):

js-test-projects/
    node/
        lib/
            HelloWorld.js   - `HelloWorld` Node module
        tests/
            HelloWorld.js   - Tests for `HelloWorld`
            intern.js       - Intern configuration file
    intern/

2. Your Intern configuration file should contain info on the node package and any suites to run:

// ...

// Configuration options for the module loader
loader: {
    // Packages that should be registered with the loader in each testing environment
    packages: [ 'node' ]
},

// Non-functional test suite(s) to run
suites: [ 'node/tests/HelloWorld' ]

// ...

3. Your test file should load HelloWorld using Intern's version of Dojo, like this:

define([
    'intern!tdd',
    'intern/chai!assert',
    'intern/dojo/node!./node/lib/HelloWorld.js'
], function (tdd, assert, HelloWorld) {
    console.log(HelloWorld);
});

Note: You don't have to use Intern's version of Dojo to load the HelloWorld node module in this AMD test, it is just a convenient way to do so. If you have some other AMD plugin that node-requires a node module, that's perfectly fine.

4. Finally, to run the tests in a Node.js environment, use Intern's client.js node runner by issuing the following command from within the intern directory:

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