Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to require modules for testing NodeJS with Intern JS?

I'm getting the error Attempt to require unloaded module xxxxxx with the following intern.js test (myfile.js below does a 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() {
      ...

The directory structure is

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

How do I properly require a file? There's no examples on how to do it with the BDD test interface. There are examples of doing it with the other style like in How do I load the node.js http module from within an intern.js test? but that doesn't use BDD.

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

like image 641
user779159 Avatar asked Nov 28 '25 05:11

user779159


1 Answers

require works the same with any of the Intern interfaces. The tricky part is that the AMD require (which you're using in the code above) is not the same as Node's require (which is what you need to use to load Node modules).

If myfiles.js is a node module, you'll need to use Dojo's node plugin to load it, like:

var myfile = require('intern/dojo/node!../myfile');
like image 61
jason0x43 Avatar answered Nov 29 '25 18:11

jason0x43



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!