How to run intern to test a dojo application running with node.js ?

﹥>﹥吖頭↗ 提交于 2019-12-01 23:41:51

The issue that you are experiencing is caused by the fact that there is code in Dojo that relies on certain has-rules being set from the Dojo loader, but this doesn’t happen because the Dojo loader isn’t in use. There are a couple of potential workarounds:

  1. Since Intern’s loader sets some of the same rules, you can load intern/node_modules/dojo/has and run has.add('dojo-has-api', true) before anything else tries to load your dojo/has module. This should cause Dojo to use the has.js implementation from Intern’s loader (and adopt all the rules it already has set, which currently includes host-node). The best place to do this is going to be the Intern configuration file, which would end up being something like this:

    define([ 'intern/dojo/has' ], function (has) {
        has.add('dojo-has-api', true);
    
        return {
            // your existing Intern configuration object…
        };
    });
    
  2. Before loading any modules that call has('host-node'), load dojo/has and intern/node_modules/dojo/has and call dojoHas.add('host-node', internHas('host-node')) (or I guess you can just hard code it :)). This would require a loader plugin to be used in place of your suites array:

    // tests/preload.js
    define({
        load: function (id, require, callback) {
            require([ 'dojo/has' ], function (has) {
                has.add('host-node', true);
                require(id.split(/\s*,\s*/), callback);
            }
        }
    });
    

    And then your suites would change to suites: [ 'tests/preload!tests/all,tests/foo,tests/bar' ].

Any other has-rules that Dojo code relies on that are set by the Dojo loader will need to be set yourself. Any other rules that Dojo adds from other parts of itself will work correctly.

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