I'm trying to use intern to test a dojo application running under node.js
My intern.js configuration file is something like:
define({
loader: {
packages: [
{ name: 'elenajs', location: 'lib' },
{ name: 'tests', location: 'tests' }
],
map: {
'elenajs': { dojo: 'node_modules/dojo' },
'tests': { dojo: 'node_modules/dojo' }
}
},
suites: [ 'tests/all' ]});
When I try to run a test with node node_modules/intern/client.js config=tests/intern
, I get this error:
Error: node plugin failed to load because environment is not Node.js
.
Normally I would have configured dojo with something like
dojoConfig = {
...
hasCache: {
"host-node": 1, // Ensure we "force" the loader into Node.js mode
"dom": 0 // Ensure that none of the code assumes we have a DOM
},
...
};
How can I solve this with intern?
The issue that you are experiencing is caused by the fact that there is code in Dojo that relies on certain has-rules being set from the Dojo loader, but this doesn’t happen because the Dojo loader isn’t in use. There are a couple of potential workarounds:
Since Intern’s loader sets some of the same rules, you can load
intern/node_modules/dojo/has
and runhas.add('dojo-has-api', true)
before anything else tries to load yourdojo/has
module. This should cause Dojo to use thehas.js
implementation from Intern’s loader (and adopt all the rules it already has set, which currently includeshost-node
). The best place to do this is going to be the Intern configuration file, which would end up being something like this:Before loading any modules that call
has('host-node')
, loaddojo/has
andintern/node_modules/dojo/has
and calldojoHas.add('host-node', internHas('host-node'))
(or I guess you can just hard code it :)). This would require a loader plugin to be used in place of yoursuites
array:And then your
suites
would change tosuites: [ 'tests/preload!tests/all,tests/foo,tests/bar' ]
.Any other has-rules that Dojo code relies on that are set by the Dojo loader will need to be set yourself. Any other rules that Dojo adds from other parts of itself will work correctly.