Not able to use .ts files with Jasmine and Karma. Getting error 'Unable to determine file...

Discussão em 'Angular' iniciado por Wild Ace, Março 18, 2025.

  1. Wild Ace

    Wild Ace Guest

    I really need some help to configure karma.conf.js to handle typescript files or not sure what is missing or what I am doing wrong here. Pretty new to unit-testing and learned the Jasmine framework (in the examples it uses *.js and *.spec.js files) but in my ionic-angular project its *.ts files and getting errors (shown below). I have been trying to figure it out for 2 days and not able to get this solved. Any help really appreciated.

    [Using ionic 3 (ionic-angular 3.9.+) framework with Angular 6 (6.1.10) and typescript (3.8.+.)]

    my tsconfig.json >

    {
    "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
    "dom",
    "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es6"
    },
    "include": [
    "src/**/*.ts"
    ],
    "exclude": [
    "node_modules",
    "src/**/*.spec.ts",
    "src/**/__tests__/*.ts"
    ],
    "compileOnSave": false,
    "atom": {
    "rewriteTsconfig": false
    }
    }


    my karma.conf.js >

    module.exports = function (config) {
    config.set({
    frameworks: ['jasmine', 'jasmine-matchers'],
    files: [
    'src/**/*.ts',
    'src/**/*.spec.ts'
    ],
    plugins: [
    'karma-jasmine',
    'karma-jasmine-matchers',
    'karma-chrome-launcher'
    ],
    reporters: ['dots'],
    colors: true,
    browsers: ['ChromeHeadless'],
    singleRun: true
    })
    };


    my package.json devDependencies:

    "devDependencies": {
    "@ionic/app-scripts": "3.2.4",
    "jasmine-core": "^3.5.0",
    "karma": "^5.1.0",
    "karma-chrome-launcher": "^3.1.0",
    "karma-jasmine": "^3.3.1",
    "karma-jasmine-matchers": "^4.0.2",
    "puppeteer": "^1.20.0",
    "ts-node": "^8.10.2",
    "typescript": "^3.8.3"
    },


    ERROR I am getting:

    15 06 2020 09:40:23.844:WARN [middleware:karma]: Unable to determine file type from the file extension, defaulting to js.
    To silence the warning specify a valid type for C:/Users/USR01/Documents/testing/src/providers/member/member.ts in the configuration file.
    See http://karma-runner.github.io/latest/config/files.html
    ........
    ........
    15 06 2020 09:40:23.844:WARN [middleware:karma]: Unable to determine file type from the file extension, defaulting to js.
    To silence the warning specify a valid type for C:/Users/USR01/Documents/testing/src/providers/scores/scores.ts in the configuration file.
    Chrome 83.0.4103.97 (Windows 10): Executed 0 of 0 SUCCESS (0.001 secs / 0 secs)
    npm ERR! Test failed. See above for more details.

    Continue reading...

Compartilhe esta Página