Dojo 1.9和Intern 1.7 - require.on没有定义?

时间:2014-06-30 16:24:43

标签: javascript dojo intern

Dojo 1.9Intern 1.7

我遇到了Intern的问题,因为它报告require.on未定义且我的测试套件正在倒下。

仅在尝试定义包含窗口小部件的测试时才会发生这种情况。它看起来像需要小部件包时会遇到一行require.on("idle", onload)但是因为require.on未定义而失败。

作为测试,我定义了require.on并且测试没有结束。

我能想到的是,当使用实习生需要小部件时,实习生随附的dojo版本会干扰正常的dojo模块吗?

以下是我测试的简化版本:

define([
    "intern!object",
    "intern/chai!expect",
    "dijit/form/Button"
],
function (
    registerSuite,
    expect,
    Button) {
    registerSuite({
        name: "Simple test",
        "failing test for demo" : function (){
            expect(true).to.be.false;
        }
    });
});

这是我的配置:

define({
    // The port on which the instrumenting proxy will listen
    proxyPort: 9000,

    // A fully qualified URL to the Intern proxy
    proxyUrl: 'http://localhost:9000/',

    // Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
    // specified browser environments in the `environments` array below as well. See
    // https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and
    // https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities.
    // Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment
    // automatically
    capabilities: {
        'selenium-version': '2.40.0'
    },

    // Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce
    // OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other
    // capabilities options specified for an environment will be copied as-is
    environments: [
        { browserName: 'chrome' }
    ],

    // Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
    maxConcurrency: 3,

    // Whether or not to start Sauce Connect before running tests
    useSauceConnect: false,

    // Connection information for the remote WebDriver service. If using Sauce Labs, keep your username and password
    // in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables unless you are sure you will NEVER be
    // publishing this configuration file somewhere
    webdriver: {
        host: 'localhost',
        port: 4444
    },

    // Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader
    // can be used here
    loader: {
        // Packages that should be registered with the loader in each testing environment
        packages: [
            {
                name: "dojo",
                location: "libs/dojo"
            }{
                name: "dijit",
                location: "libs/dijit"
            },{
                name: "unitTests",
                location: "test/unit"
            }
        ]
    },

    // Non-functional test suite(s) to run in each browser
    suites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */
        "unitTests/exampleTest"
    ],

    // Functional test suite(s) to run in each browser once non-functional tests are completed
    functionalSuites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */
    ],

    // A regular expression matching URLs to files that should not be included in code coverage analysis
    excludeInstrumentation: /^tests\//
});

文件夹结构是:

app/
    libs/
        dojo
        dijit
        intern
    test/
        unit/
            exampleTest.js
    intern.js

我正在直接从谷歌浏览器浏览器运行测试:

http://{webroot}/app/libs/intern/client.html?config=../test/intern

我确实有一些测试成功运行但不包含任何小部件。

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

您正在运行一个过时的Dojo 1.9版本,期望使用的AMD加载程序是Dojo 1.9附带的加载程序,而Intern的默认安装则不然。您有两种选择:

  1. 升级到Dojo 1.9.3或更高版本。 (推荐)。
  2. 使用useLoader配置选项指向Dojo 1.9副本中的dojo.js:
  3. define({
      // ...
      useLoader: {
        'host-browser': 'path/to/dojo1.9/dojo.js'
      }
    })