I am trying to test Intern to see if it would be a good fit for a testing framework. I am trying to test 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 located at 'js-test-projects/intern'. I am using the 1.0.0 branch of Intern. Whenever I try to include the file and run the test I don't get any output after "Defaulting to console reporter". Here is the test file.
define([
'intern!tdd',
'intern/chai!assert',
'dojo/node!../lib/HelloWorld'
], function (tdd, assert, HelloWorld) {
console.log(HelloWorld);
});
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
来源:https://stackoverflow.com/questions/16466115/cant-get-intern-to-run-node-js-module