错误'找不到名字......'使用karma-typescript-preprocessor插件

时间:2015-04-28 06:41:18

标签: gruntjs typescript karma-runner

我正在尝试使用grunt karma和karma-typescript-preprocessor自动执行单元测试。

然而,当我跑步' grunt watch'时,karma会输出以下错误: 错误[preprocessor.typescript]:/ home / love / Code / appName / src / app / app.spec.ts.ktp.ts(15,13):错误TS2304:找不到姓名'期待'。

这个错误发生在很多名字上:'描述,角度,期待'等

奇怪的是,当我运行命令行&#t; tsc /path/to/app.spec.ts'时,会创建新的js文件,没有错误。

低于我的karma.conf.js:

module.exports = function ( karma ) {
    karma.set({
    /**
     * From where to look for files, starting with the location of this file.
     */
    basePath: '../',

    typescriptPreprocessor: {
        // options passed to the typescript compiler
        options: {
            sourceMap: false, // (optional) Generates corresponding .map file.
            target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
            module: 'amd', // (optional) Specify module code generation: 'commonjs' or 'amd'
            noImplicitAny: false, // (optional) Warn on expressions and declarations with an implied 'any' type.
            noResolve: true, // (optional) Skip resolution and preprocessing.
            removeComments: true // (optional) Do not emit comments to output.
        },
        // transforming the filenames
        transformPath: function(path) {
            return path.replace(/\.ts$/, '.js');
        }
    },

    /**
     * This is the list of file patterns to load into the browser during testing.
     */
    files: [
    <% scripts.forEach( function ( file ) { %>'<%= file %>',
        <% }); %>
'src/**/*.ts'
],
exclude: [
    'src/assets/**/*.ts',
    'src/typeScript/**/*.ts'
],
    frameworks: [ 'jasmine' ],
    plugins: [ 'karma-jasmine', 'karma-firefox-launcher', 'karma-typescript-preprocessor' ],
    preprocessors: {
    '**/*.ts': 'typescript'
},

/**
 * How to report, by default.
 */
reporters: 'dots',

/**
 * On which port should the browser connect, on which port is the test runner
 * operating, and what is the URL path for the browser to use.
 */
    port: 9018,
    runnerPort: 9100,
    urlRoot: '/',

/**
 * Disable file watching by default.
 */
    autoWatch: false,

/**
 * The list of browsers to launch to test on. This includes only "Firefox" by
 * default, but other browser names include:
 * Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
 *
 * Note that you can also use the executable name of the browser, like "chromium"
 * or "firefox", but that these vary based on your operating system.
 *
 * You may also leave this blank and manually navigate your browser to
 * http://localhost:9018/ when you're running tests. The window/tab can be left
 * open and the tests will automatically occur there during the build. This has
 * the aesthetic advantage of not launching a browser every time you save.
 */
    browsers: [
    'Firefox'
]
});
};

任何帮助将不胜感激

3 个答案:

答案 0 :(得分:1)

尝试删除该行

noResolve: true,
来自typescriptPreprocessor配置的

。它似乎导致编译器无法正确解析您的引用。

答案 1 :(得分:0)

我有同样的问题,我最终做了gulp任务,在序列打字稿编译和业力测试中运行。

答案 2 :(得分:0)

将“noResolve”值设置为false,并添加引用

我也在这里发表评论

https://github.com/sergeyt/karma-typescript-preprocessor/issues/29