实习生4无法使用Dojo Loader和ArcGIS JavaScript API

问题描述 投票:1回答:2

Intern 4 Dojo加载程序无法在ArcGIS JavaScript API中找到Dojo库。有谁知道如何使用Dojo和ArcGIS JavaScript API制作最新版本的Intern?

old fix不再有效。实习生说:

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>

此外,鉴于本文末尾的intern.json文件,实习生说:

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"]
}

最后,为了完整起见,这里是完整的目录结构:

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.');
        }
    });
});

顺便说一句,如果你读到这一点,我希望你能理解计算机中的幽默,而不是认识到1等于1。

javascript dojo intern arcgis-js-api
2个回答
0
投票

你需要做几件事才能让它发挥作用。首先,你需要添加一个自定义加载器来加载dojo,然后你需要更改你的script来引用intern.json中的新dojo加载器文件。该文件看起来像:

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

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

0
投票

有一个文档可以解释在WebAppbuilder for ArcGIS上设置实习生4的过程。 WAB使用ArcGIS API for Javascript。

Best Practices for Unit Test on WAB

© www.soinside.com 2019 - 2024. All rights reserved.