Intern 4 Dojo加载程序无法在ArcGIS JavaScript API中找到Dojo库。有人知道如何使最新版本的Intern与Dojo和ArcGIS JavaScript API一起工作吗?
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文件,intern说:
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的幽默。
2条答案
按热度按时间6rvt4ljy1#
你需要做几件事来让它工作。首先,你需要添加一个自定义加载器来加载
dojo
,然后你需要修改你的script
来引用intern.json
中的新dojo加载器文件。dced5bon2#
有一个文档解释了在WebAppbuilder for ArcGIS. WAB上设置实习生4的过程。WAB使用ArcGIS API for Javascript。
Best Practices for Unit Test on WAB