Is it possible to use dojo/text! in an Intern functional test?

六眼飞鱼酱① 提交于 2019-12-11 11:17:39

问题


Is it possible to use "dojo/text!" in an Intern functional test?

I am able to setup my test page as a JSON string, but ideally I'd like to externalise the string in a file for ease of editing. I'm just getting started with Intern at the moment so I'm just experimenting with what's possible, but here is the start of my test code).

This works with the commented "testData" variable used, but is currently failing when I try to provide the same String by the dojo/text! statement.

Code:

define([
    'intern!object',
    'intern/chai!assert',
    'dojo/text!./firstTestPageConfig.json',
    'require'
], function (registerSuite, assert, PageConfig, require) {
    registerSuite({
        name: 'firstTest',

        'greeting form': function () {

            var testData = PageConfig;
            // var testData = '{"widgets":[{"name":"alfresco/menus/AlfMenuBar","config":{"widgets":[{"name":"alfresco/menus/AlfMenuBarPopup","config":{"id":"DD1","label":"Drop-Down","iconClass":"alf-configure-icon","widgets":[{"name":"alfresco/menus/AlfMenuGroup","config":{"label":"Group 1","widgets":[{"name":"alfresco/menus/AlfMenuItem","config":{"label":"Item 1","iconClass":"alf-user-icon"}},{"name":"alfresco/menus/AlfMenuItem","config":{"label":"Item 2","iconClass":"alf-password-icon"}}]}},{"name":"alfresco/menus/AlfMenuGroup","config":{"label":"Group 2","widgets":[{"name":"alfresco/menus/AlfMenuItem","config":{"label":"Item 3","iconClass":"alf-help-icon"}}]}}]}}]}}]}';
            var testPage = 'http://localhost:8081/share/page/tp/ws/unittest?testdata=';

            return this.remote
                .get(testPage + testData)
                .waitForElementByCssSelector('.alfresco-core-Page.allWidgetsProcessed', 5000)
                .elementById('DD1')
                    .clickElement()
                    .end()

       }
   });
});

The error I'm getting is this:

/home/dave/ScratchPad/ShareInternTests/node_modules/intern/node_modules/dojo/dojo.js:742
                throw new Error('Failed to load module ' + module.mid + ' from ' + url + 
                          ^
Error: Failed to load module dojo/text from /home/dave/ScratchPad/ShareInternTests/dojo/text.js (parent: dojo/text!17!*)
at /home/dave/ScratchPad/ShareInternTests/node_modules/intern/node_modules/dojo/dojo.js:742:12
at fs.js:207:20
at Object.oncomplete (fs.js:107:15)

I've tried playing around with the loader/package/map configuration but without any success. It's not clear (to me at least) from the error message whether or not it can't find the file I'm passing to dojo/text (but I've tried full as well as relative paths) or the Dojo module itself ?

I'd just like to confirm that what I'm attempting is possible, before I spend any more time with this... but obviously any solution or example would be greatly appreciated!!

Many thanks, Dave


回答1:


To your specific error: You need to install Dojo for your own project if you want to use it. You are trying to load a module that does not exist. You may also try using the copy that comes with Intern, by loading modules from intern/dojo, but this isn’t recommended if you don’t understand the potential caveats of loading this internal library.

To using dojo/text in a functional test, generally: This is not currently possible unless you use the Geezer branch or explicitly use the Dojo 1 loader, because that module relies on functionality that is only exposed by the Dojo 1 loader when running in Node.js. A different text loader module that is fully generic would work, or you could load intern/dojo/node!fs and load the text yourself. This will be addressed in the future.




回答2:


I just came across the same issue and for me this worked:

define([
     "dojo/_base/declare",
     "intern/dojo/text!/[PathToText]"
], function (declare, base) {

Seems as if Sitepen has included this in the meantime...



来源:https://stackoverflow.com/questions/20049848/is-it-possible-to-use-dojo-text-in-an-intern-functional-test

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!