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

Ngu*_*ien 9 typescript karma-runner karma-jasmine webpack

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

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
Run Code Online (Sandbox Code Playgroud)

我认为是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,

    });
};
Run Code Online (Sandbox Code Playgroud)

我使用webpack 4.16.5和业力4.0.0

小智 -4

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

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

  • 不,那不是我想做的。问题是它需要支持 .ts,而不仅仅是 .js (2认同)