Search code examples
requirejsamdintern

Can alternative AMD loaders be used in functional testing with intern?


The useLoader configuration for specifying another AMD loader to use does not seem to be used in functional test modules.

I want to load a JSON file into a javascript object to use in my functional test suite by using a requireJS JSON plugin (https://gist.github.com/millermedeiros/1255010) but it does not work due to what I assume is the plugin looking for requireJS specific constructs:

TypeError: Cannot read property 'isBuild' of undefined
  at Object.load  </home/dev/public_html/gold_widgets_15644/web/assets/js/json.js:27:24>
  at injectPlugin  <node_modules/intern/node_modules/dojo/dojo.js:608:12>
  at <node_modules/intern/node_modules/dojo/dojo.js:543:7>
  at Array.forEach  <native>
  at forEach  <node_modules/intern/node_modules/dojo/dojo.js:220:19>
  at execModule  <node_modules/intern/node_modules/dojo/dojo.js:535:5>
  at <node_modules/intern/node_modules/dojo/dojo.js:582:7>
  at guardCheckComplete  <node_modules/intern/node_modules/dojo/dojo.js:566:4>
  at checkComplete  <node_modules/intern/node_modules/dojo/dojo.js:574:27>
  at onLoadCallback  <node_modules/intern/node_modules/dojo/dojo.js:656:7>

What's the best way to include json from a file in a functional testing module if alternative AMD module loaders such as requireJS are not supported in functional tests?

Should one just use node's fs library in conjunction with JSON.parse?


Solution

  • You're correct, functional tests run with the default loader. A functional test just drives the browser -- it doesn't run in the same environment as the application under test.

    You can use both AMD and CommonJS libraries in your functional tests. For example, you can install the Dojo npm module and add it to the packages list in your test config to use dojo/text (and any other Dojo utility functions). You can also load Node's fs module using the dojo/node module included with Intern, like:

    define([ 'intern/dojo/node!fs', ... ], function (fs, ...) {
        ...
    });