Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WARN [middleware:karma]: Invalid file type, defaulting to js. ts

When I run unit testing via karma, I got those warning:

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

I assumed that the type of the karma.conf.js file caused the issue, so I changed it to karma.conf.ts.

However the issue still happened, so it would be great if someone can tell me how to disable this warning.

Below is my karma.conf.ts file

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,

    });
};

I use webpack 4.16.5 and karma 4.0.0

like image 431
Nguyen Phong Thien Avatar asked Feb 12 '19 13:02

Nguyen Phong Thien


1 Answers

I ran into the same error message, and I believe a similar issue but in my case for .ttf font files causing:

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

From 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.

So I believe if you want to add a resource with a different file type as a link it should be type HTML in the files config. The following worked for me:

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

Not sure how .ts files should be included in an HTML page (as shouldn't they be transpiled to JS?) but you could try setting the type to js.

like image 98
geographika Avatar answered Oct 16 '22 12:10

geographika