【问题标题】:How do you add Intern to a Dojo project?如何将 Intern 添加到 Dojo 项目中?
【发布时间】:2016-12-06 21:06:30
【问题描述】:

实习生网站上的教程开始于使用 npm 获取实习生,但我下载了最新版本的实习生源代码。 (我没有使用npm)并且我的应用程序文件夹结构是这样的

|myapp
    |app
    |tests
       |unit
       |functional
    main.js
|third-party
    |dojo-release-1.10.6
    |intern-3.4.2
index.html

现在在我的 index.html 中,我在包配置中添加了以下内容

            packages: [
                { name: 'dojo', location: 'third_party/dojo-release-1.10.6-src/dojo' },
                { name: 'intern', location: 'third_party/intern-3.4.2' },
            ],

在此之后,我应该将 intern.js 放在哪里?

【问题讨论】:

  • 将其放入intern/intern.js,然后像require("intern/intern.js")一样导入...

标签: javascript dojo intern


【解决方案1】:

除了使用 npm 之外,使用 Intern 的基本过程将与教程中概述的相同。编写单元测试,然后使用 Intern 的三个测试运行器之一(intern-clientintern-runnerclient.html)来实际运行测试。

您不需要在您的应用程序包列表中包括实习生。相反,您将在实习生测试配置中的 loaderOptions 对象中包含您的应用程序包。

您的测试如何与您的应用程序交互取决于您编写的测试类型。对于单元测试,您的单元测试套件将加载您的应用程序的各个部分,然后在它们上运行测试。对于功能测试,您的测试(通过实习生)将告诉浏览器加载运行您的应用程序的测试页面,然后告诉浏览器执行各种操作。

// unit test
define([ 'intern!object', 'myApp/myModule' ], function (registerSuite, mod) {
    registerSuite({
        name: 'myApp/myModule',

        '#someFunction': function () {
            var value = mod.someFunction(...);
            // make assertion about value
        }
    });
});

// functional test
define([ 'intern!object' ], function (registerSuite) {
    registerSuite({
        name: 'myApp/myModule',

        '#someFunction': function () {
            return this.remote.get('myTestPage.html')
                .findById('someButton')
                .click()
                // make assertions about state of elements on the page
        }
    });
});

Intern 本身是一个 Dojo 项目,默认使用自己定制的 Dojo 版本来加载模块。这对于单元测试来说可能已经足够了。如果不是,您需要在测试配置中设置loaders 以指向您自己的Dojo 的dojo.js(加载程序的路径应该相对于实习生的dojo/loader.js)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-29
    • 2012-01-11
    • 2012-01-05
    • 2019-04-11
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多