Cannot start Intern to start Node.js Module

I am trying to test Intern to make sure it will work well for a test environment. I am trying to check the following code in Intern.

var HelloWorld; HelloWorld = (function () { function HelloWorld (name) { this.name = name || "N/A"; } HelloWorld.prototype.printHello = function() { console.log('Hello, ' + this.name); }; HelloWorld.prototype.changeName = function(name) { if (name === null || name === undefined) { throw new Error('Name is required'); } this.name = name; }; return HelloWorld; })(); exports = module.exports = HelloWorld; 

The file is located in 'js-test-projects / node / lib / HelloWorld.js', and Intern is in 'js-test-projects / intern'. I am using the Intern 1.0.0 branch. Whenever I try to include a file and run a test, I get no result after "Default for console reporter." Here is a test file.

 define([ 'intern!tdd', 'intern/chai!assert', 'dojo/node!../lib/HelloWorld' ], function (tdd, assert, HelloWorld) { console.log(HelloWorld); }); 
+6
source share
1 answer

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. The Intern configuration file should contain information about the node package and any classes that are 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 the Intern version of Dojo, for example:

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

Note. You do not need to use the Dojo intern version to load the HelloWorld node module in this AMD test, this is just a convenient way to do this. If you have another AMD plugin, which is the node -requires node module, that's fine.

4. Finally, to run the tests in Node.js, use the Intern client.js node by running the following command from the intern directory:

 node client.js config=node/tests/intern 
+7
source

Source: https://habr.com/ru/post/944646/


All Articles