How do I require modules to test NodeJS with Intern JS?

I am getting an error Attempt to require unloaded module xxxxxx

with the following intern.js test (myfile.js below executes require('xxxxxx')

) for testing NodeJS.

define(function(require) {
  var bdd = require('intern!bdd');
  var myfile = require('../myfile.js');
  bdd.describe('the thing being tested', function() {
    bdd.it('do the test', function() {
      ...

      

Directory structure

intern.js
myfile.js
test
|-- test.js

      

How do I need the file correctly? There are no examples on how to do this with the BDD testing interface. There are examples on how to do this with a different style, such as in How to load node.js http module from intern.js test? but it doesn't, t use BDD.

Does it have anything to do with the properties I need to set in the intern.js file?

+3


source to share


2 answers


require

works the same with any Intern interface. The tricky part is that AMD requires (which you use in the code above) is not the same as Node require (which is what you need to use to load Node modules).

If it myfiles.js

is a Node module, you will need to use the Dojo plugin node

to load it, for example:



var myfile = require('intern/dojo/node!../myfile');

      

+4


source


Step 1 do it in definition

define([
   'intern!xyzModule',
   'intern/chai!abcModule',
],function(xyz,abc){

}

      

The above is equal to



var xyz = require(intern!xyzModule);
var abc = require(intern!abcModule);

      

but in some cases it fails to load using the required so that it can use the above method happened to me.

0


source







All Articles