typescript - 警告 [中间件 :karma]: Invalid file type, 默认为 js。 TS

标签 typescript webpack karma-jasmine karma-runner

当我通过 karma 运行单元测试时,我收到了那些警告:

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 和 karma 4.0.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 :

The css and html types create link elements; the js, dart, and module elements create script elements. The dom type includes the file content in the page, used, for example, to test components combinging HTML and JS.

所以我相信如果你想添加一个具有不同文件类型的资源作为链接,它应该在文件配置中输入 HTML。以下对我有用:

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

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

关于typescript - 警告 [中间件 :karma]: Invalid file type, 默认为 js。 TS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54650812/

相关文章:

typescript - Promise 类型中最终缺少属性

javascript - TypeScript 与 BreezeJS 结合

angular - 使用 Angular 4、Webpack 2、Karma 和 Jasmine 获得单元测试覆盖率

angular - 测试 Angular snackbar

angularjs - $httpBackend ExpectGET 未返回预期数据

angular - 使用 jasmine spy 测试 cdk 覆盖

typescript - 在接口(interface)中使用胖箭头和非胖箭头语法声明函数有什么区别?

具有动态参数的 Angular Factory Provider

javascript - 将变量注入(inject) webpack

javascript - 使用react-icons一次导入多个图标