2

I am new to Intern and struggling with trying to get a simple test to run in my environment. I was able to get the tutorial test to run but I've tried to set up a test where the test file is located inside my app directory hierarchy. The module being tested is located here:

sandbox/web/libs/ev/grids/FilterGrid.js

The test file is located here:

sandbox/web/libs/ev/tests/FilterGrid.js

My intern config file is located here:

sandbox/tests/intern.js

My loader and suites objects looks like this:

loader: {
    packages: [
        { name: 'dojo', location: 'web/libs/dojo' },
        { name: 'dijit', location: 'web/libs/dijit },
        { name: 'dgrid', location: 'web/libs/dgrid' },
        { name: 'put-selector', location: 'web/libs/put-selector' },
        { name: 'xstyle', location: 'web/libs/xstyle' },
        { name: 'ev', location: 'web/libs/ev' }
    ]
},
suites: ['ev/tests/FilterGrid'],

When the loader tries to load this, I get:

Defaulting to "console" reporter
ReferenceError: document is not defined
    at /home/bholm/Projects/src/sandbox/web/libs/dojo/selector/_loader.js:5:15
    at execModule (/home/bholm/Projects/src/sandbox/node_modules/intern/node_module
        /dojo/dojo.js:512:54)
    at /home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:579:7
    at guardCheckComplete (/home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:563:4)
    at checkComplete (/home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:571:27)
    at onLoadCallback (/home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:653:7)
    at /home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:746:5
    at fs.js:266:14
    at Object.oncomplete (fs.js:107:15)

Does the unit tests using Intern need a DOM document defined?? I also notice that Intern lists dojo2_core as it's dependency. So it's using unreleased code?

Any help with this would be appreciated!

teaman
  • 469
  • 7
  • 18

1 Answers1

3

It looks like you’re trying to load some code using the Node.js client that requires a browser environment. This won’t work. You should only load the ev/tests/FilterGrid test suite in a browser. You can do this by modifying your Intern configuration file to look something like this:

define([ 'intern/node_modules/dojo/has' ], function (has) {
  var suites = [];

  if (has('host-browser')) {
    suites.push('ev/tests/FilterGrid');
  }

  return {
    // ...your existing configuration...
    suites: suites,
    // ...
  };
});
C Snover
  • 17,908
  • 5
  • 29
  • 39
  • That helps! However there is a missing piece of info. Does the node_modules dir have to live in the web root? Seems it would in order to run client.html in the browser. We didn't want node.js etc. in the web root so we have node_modules dir as a sibling of the web root (web in my example above). If the answer is no, then how does the config get setup to run browser tests with node_modules outside the web root? – teaman Jun 24 '13 at 23:20
  • The short answer is “yes”. The longer answer is “no, if you use the runner, but the runner will always use the directory two paths up from wherever Intern is installed as the directory being served, so it is effectively the same as installing it in your web root”. – C Snover Jun 25 '13 at 00:50
  • I think it would be helpful then to know what are the key file/directory positional relationships to each other. "Key" meaning web root vs intern.js (config file) vs modules being tested vs unit test files. Is there flexibility in what that is? WHat "has" to be where and what can be moved and a mapping path set in the config. Speaking of, the mapping property in the config file intern.js is not well defined or exampled, IMHO. Just trying to understand how flexible Intern is and why it seems so inflexible in the hierarchy. – teaman Jun 25 '13 at 17:01