1

The Intern 4 Dojo loader cannot find the Dojo library in the ArcGIS JavaScript API. Does anyone know how to make the latest version of Intern work with Dojo and the ArcGIS JavaScript API?

The old fix no longer works. Intern says:

PS C:\UniServerZ\www\HelloIntern2> .\node_modules\.bin\intern
Config has unknown option "useLoader"
(????)?????
ReferenceError: define is not defined
  at Object.<anonymous>  <tests\unit\ViewByAttributeTest.js:1:63>
  at Module._compile  <module.js:652:30>
  at Object.Module._extensions..js  <module.js:663:10>
  at Module.load  <module.js:565:32>
  at tryModuleLoad  <module.js:505:12>
  at Function.Module._load  <module.js:497:3>
  at Module.require  <module.js:596:17>
  at require  <internal\module.js:11:18>
  at Node.loadScript  <src\lib\executors\Node.ts:260:5>
  at Node._loader  <src\loaders\default.ts:10:16>

Furthermore, given the intern.json file at the end of this post, intern says:

PS C:\UniServerZ\www\HelloIntern2> .\node_modules\.bin\intern
(????)?????
Error: Cannot find module 'node_modules/dojo/dojo.js' from 'C:\UniServerZ\www\He
lloIntern2'
  at Function.module.exports [as sync]  <node_modules\resolve\lib\sync.js:40:15>

  at Node.loadScript  <src\lib\executors\Node.ts:264:13>
  at <src\loaders\dojo.ts:17:15>
  at Node.Executor.registerLoader  <src\lib\executors\Executor.ts:468:37>
  at Object.<anonymous>  <src\loaders\dojo.ts:6:7>
  at Module._compile  <module.js:652:30>
  at Object.Module._extensions..js  <module.js:663:10>
  at Module.load  <module.js:565:32>
  at tryModuleLoad  <module.js:505:12>
  at Function.Module._load  <module.js:497:3>

intern.json:

{
    "loader" : {
        "script" : "dojo",
        "options" : {
            "packages" : [{
                    "name" : "zian",
                    "location" : "/zian"
                }, {
                    "name" : "dgrid",
                    "location" : "http://js.arcgis.com/4.6/dgrid"
                }, {
                    "name" : "dijit",
                    "location" : "http://js.arcgis.com/4.6/dijit"
                }, {
                    "name" : "esri",
                    "location" : "http://js.arcgis.com/4.6/esri"
                }, {
                    "name" : "dojo",
                    "location" : "http://js.arcgis.com/4.6/dojo"
                }, {
                    "name" : "dojox",
                    "location" : "http://js.arcgis.com/4.6/dojox"
                }, {
                    "name" : "moment",
                    "location" : "http://js.arcgis.com/4.6/moment"
                }
            ]
        }
    },
    "filterErrorStack" : false,
    "suites" : ["tests/unit/*.js"],
    "environments" : ["chrome", "node"]
}

Finally, for the sake of completeness, here is the full directory structure:

app has: calc.js and index.js
js has: starter.js
node_module has: tons and tons of folder...
test has: unit has: ViewByAttributeTest.js
zian has: ViewByAttribute.js
root of the folder has the above folders and: index.html, index.js, intern.json, package.json, and package-lock.json

package.json:

{
  "name": "helloworldcdnapi",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "author": "Zian Choy",
  "license": "ISC",
  "dependencies": {
    "intern": "^4.0.0-rc.1"
  }
}

ViewByAttributeTest.js

define([
    'require'
], function (require) {
    var registerSuite = intern.getInterface('object').registerSuite;
    var assert = intern.getPlugin('chai').assert;

    registerSuite('ViewByAttribute', {
        'default data': function () {

            assert.strictEqual(1, 1, '1 is 1.');
        }
    });
});

Incidentally, if you read this far, I hope you can appreciate the humor in computers failing to recognize that 1 is equal to 1.

Zian Choy
  • 2,846
  • 6
  • 33
  • 64

2 Answers2

0

You'll need to do several things to get this to work. First, you'll need to add a custom loader to load dojo, then you'll need to change your script to reference that new dojo loader file in intern.json. That file will look something like:

intern.registerLoader(function(options) {
  // do checks here

  return intern.loadScript(<location of your dojo file in arcgis js api>)
    .then(function() {
      //do stuff here
    })
});
tyanthony
  • 45
  • 5
0

There is a document to explain the process to setting intern 4 on WebAppbuilder for ArcGIS. WAB use ArcGIS API for Javascript.

Best Practices for Unit Test on WAB

hallext
  • 1
  • 1