WARN [middleware:karma]:无效的文件类型,默认为js。 ts

时间:2019-02-12 13:07:18

标签: typescript webpack karma-jasmine karma-runner

当我通过业力运行单元测试时,我得到那些警告:

12 02 2019 14:01:05.740:WARN [middleware:karma]: Invalid file type, defaulting to js. ts
12 02 2019 14:01:05.741:WARN [middleware:karma]: Invalid file type, defaulting to js. ts

我认为是karma.conf.js文件的类型引起了问题,所以我将其更改为karma.conf.ts

但是问题仍然存在,所以如果有人可以告诉我如何禁用此警告,那就太好了。

下面是我的karma.conf.ts文件

module.exports = function karmaConfig(config) {
    config.set({

        singleRun: true,

        frameworks: [
            'jasmine'
        ],

        files: [
            'sdk/**/*.spec.ts'
        ],

        preprocessors: {
            'sdk/**/*.spec.ts': ['webpack', 'sourcemap'],
            'sdk/**/!(*.spec).ts': ['coverage']
        },

        browsers: [
            'PhantomJS'
        ],

        reporters: [
            'progress',
            'coverage',
            'junit'
        ],

        coverageReporter: {
            dir: 'coverage/',
            reporters: [
                { type: 'text-summary' },
                { type: 'html' },
                {
                    type: 'lcov',
                    dir: 'reports',
                    subdir: 'coverage'
                }
            ]
        },

        junitReporter: {
            outputFile: 'reports/junit/TEST-karma.xml',
            useBrowserName: false
        },

        transports: ['polling'],

        webpack: require('./webpack.config'),

        webpackMiddleware: {
            stats: 'errors-only'
        },

        logLevel: config.LOG_INFO,

    });
};

我使用webpack 4.16.5和业力4.0.0

2 个答案:

答案 0 :(得分:0)

您对I assumed that the type of the karma.conf.js file caused the issue为真 但我认为原因是

  

个文件:[               'sdk / ** / *。spec.ts'           ],   我认为您应该将'sdk/**/*.spec.ts'更改为'sdk/**/*.spec.js'   希望对您有帮助。

答案 1 :(得分:0)

我遇到了相同的错误消息,并且我相信也会发生类似的问题,但就我而言,.ttf字体文件会导致:

19 11 2019 22:12:35.398:WARN [middleware:karma]: Invalid file type (ttf), defaulting to js.

来自http://karma-runner.github.io/4.0/config/files.html

  

css和html类型创建链接元素; js,dart和模块   元素创建脚本元素。 dom类型包括文件   页面中的内容,例如用于测试组件组合   HTML和JS。

因此,我相信如果您想添加具有不同文件类型的资源作为链接,则应该在文件配置中键入HTML。以下对我有用:

{
    pattern: 'resources/fonts/**/*.ttf',
    type: 'html',
    served: true,
    included: true
},

不确定.ts文件应如何包含在HTML页面中(不应该将它们转换为JS吗?),但是您可以尝试将type设置为js