在使用 TypeScript、RequireJs 和 Jasmine 时无法确定将 require.config 放在哪里

Can't figure out where to put require.config when using TypeScript, RequireJs, and Jasmine

我一直在遵循 Steve Fenton 在这里描述的设置 TypeScript、RequireJS 和 Jasmine 的模式:

https://www.stevefenton.co.uk/Content/Blog/Date/201407/Blog/Combining-TypeScript-Jasmine-And-AMD-With-RequireJS/

那个模式真的很管用,真的让我畅通无阻(耶!),但我现在正处于需要为 RequireJS 自定义一些设置的地步,但我似乎无法弄清楚将我的设置放在哪里require.config 打电话。我尝试过的所有地方都导致了中断和倒退。以下是看起来最 logical/promising

的两种方法

在SpecRunner.cshtml

<script data-main="/Scripts/TypeScript/RequireJsConfig" src="/Scripts/require.js"></script>

在RequireJsConfig.ts

require.config({
    baseUrl: "../Scripts",
    paths: {
        jquery: "../jquery-2.1.3"
    }
});

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Attempt 1: When I try it this way I immediately get this error
//
//     JavaScript runtime error: Object doesn't support property or method 'config'
//
import TestLoader = require("Tests/TestLoader");
TestLoader.Run();

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Attempt 2: When I try it this way, everything builds and runs without errors, but 
// Jasmine doesn't find any of the tests.  All I get is "No specs found" even 
// though I see the breakpoints on my "it" statements getting hit.
//
require(["Tests/TestLoader"], (testLoader) => {
    testLoader.Run();
});

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

jasmine.getEnv().execute();

在TestLoader.ts

import GuidHelperTests = require("Tests/T3/Helpers/GuidHelperTests");
import ObjectHelperTests = require("Tests/T3/Helpers/ObjectHelperTests");

class TestLoader {

    public static Run: () => void = () => {
        GuidHelperTests.Run();
        ObjectHelperTests.Run();
    }    
}

export var Run = () => TestLoader.Run();

在GuidHelperTests.ts

import T3 = require("T3/T3Lib");

export var Run = () => {

    describe("GuidHelper tests", () => {
        it("GUID validator validates good GUID", () => {

        // etc. ... 

我的猜测是,尝试 2 不起作用是因为某种排序问题,即在加载模块之前发生测试发现过程,或类似的问题。我只是对 RequireJS 不够精通,不知道我的选择是什么。

我更喜欢让我的配置远离我的应用程序 - 您可以像这样预先注册配置,它会在加载时由 RequireJS 获取。无需将其添加到您的第一个文件中。

<script>
var require = {
    baseUrl: "../Scripts",
    paths: {
        jquery: "../jquery-2.1.3"
    }
};
</script>
<script data-main="/Scripts/TypeScript/RequireJsConfig" src="/Scripts/require.js"></script>