jeudi 6 juillet 2017

Angular 4 Karma testing

I have issues when trying to run tests with Karma on my Angular 4 project. When starting npm test I get whole bunch of errors which don't seem to have any impact on the tests itself as the browser starts, and tests pass. But I still wonder how I can solve the issue. This is the output

06 07 2017 10:10:41.994:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.4.0
06 07 2017 10:10:44.164:ERROR [compiler.karma-typescript]: node_modules/@angular/common/src/directives/ng_class.d.ts(48,34): error TS2304: Cannot find name 'Set'.
06 07 2017 10:10:44.166:ERROR [compiler.karma-typescript]: node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(24,16): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.166:ERROR [compiler.karma-typescript]: node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(32,16): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.166:ERROR [compiler.karma-typescript]: node_modules/@angular/core/src/change_detection/differs/keyvalue_differs.d.ts(23,18): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.166:ERROR [compiler.karma-typescript]: node_modules/@angular/core/src/di/reflective_provider.d.ts(87,123): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.167:ERROR [compiler.karma-typescript]: node_modules/@angular/core/src/di/reflective_provider.d.ts(87,165): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.167:ERROR [compiler.karma-typescript]: node_modules/@angular/http/src/headers.d.ts(52,71): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.167:ERROR [compiler.karma-typescript]: node_modules/@angular/http/src/url_search_params.d.ts(46,16): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.167:ERROR [compiler.karma-typescript]: node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(79,33): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.167:ERROR [compiler.karma-typescript]: node_modules/@angular/platform-browser/src/dom/dom_adapter.d.ts(97,42): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.168:ERROR [compiler.karma-typescript]: node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts(11,30): error TS2304: Cannot find name 'Set'.
06 07 2017 10:10:44.168:ERROR [compiler.karma-typescript]: node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts(22,30): error TS2304: Cannot find name 'Set'.
06 07 2017 10:10:44.168:ERROR [compiler.karma-typescript]: node_modules/@angular/router/src/router_outlet_context.d.ts(42,28): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.168:ERROR [compiler.karma-typescript]: node_modules/@angular/router/src/router_outlet_context.d.ts(43,34): error TS2304: Cannot find name 'Map'.
06 07 2017 10:10:44.168:ERROR [compiler.karma-typescript]: node_modules/rxjs/Observable.d.ts(58,60): error TS2693: 'Promise' only refers to a type, but is being used as a value here.
06 07 2017 10:10:44.168:ERROR [compiler.karma-typescript]: node_modules/rxjs/operator/toPromise.d.ts(3,79): error TS2693: 'Promise' only refers to a type, but is being used as a value here.
06 07 2017 10:10:44.168:ERROR [compiler.karma-typescript]: src/app/services/ErrorHandler.ts(9,10): error TS2693: 'Promise' only refers to a type, but is being used as a value here.

06 07 2017 10:10:44.366:INFO [compiler.karma-typescript]: Compiled 35 files in 2341 ms.
06 07 2017 10:10:44.994:INFO [bundler.karma-typescript]: Bundled imports for 3 file(s) in 127 ms.
06 07 2017 10:10:44.998:WARN [karma]: No captured browser, open http://localhost:9876/
06 07 2017 10:10:45.011:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/
06 07 2017 10:10:45.011:INFO [launcher]: Launching browser Chrome with unlimited concurrency
06 07 2017 10:10:45.049:INFO [launcher]: Starting browser Chrome
06 07 2017 10:10:46.953:INFO [Chrome 59.0.3071 (Windows 10 0.0.0)]: Connected on socket S0TFujMRxRhtNV6eAAAA with id 48829654

I am using these dependencies:

    "typescript": "2.4.0",
    "karma": "^1.7.0",
    "karma-typescript": "^3.0.4",
    "karma-chrome-launcher": "^2.2.0",
    "karma-jasmine": "^1.1.0",
    "@types/jasmine": "^2.5.53",

And here is my karma.conf.js

// Karma configuration
// Generated on Mon Jun 12 2017 14:21:41 GMT+0200 (Central European Daylight Time)

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

        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: 'src/app',


        // frameworks to use
        // available frameworks: http://ift.tt/1ft83uu
        frameworks: ['jasmine', 'karma-typescript'],


        // list of files / patterns to load in the browser
        files: [
            { pattern: '**/*.spec.ts' }
        ],

        // list of files to exclude
        exclude: [],

        // preprocess matching files before serving them to the browser
        // available preprocessors: http://ift.tt/1gyw6MG
        preprocessors: {
            "**/*.ts": ['karma-typescript']
        },


        // test results reporter to use
        // possible values: 'dots', 'progress'
        // available reporters: http://ift.tt/1ft83KQ
        reporters: ['progress', 'karma-typescript'],


        // web server port
        port: 9876,


        // enable / disable colors in the output (reporters and logs)
        colors: true,


        // level of logging
        // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
        logLevel: config.LOG_INFO,


        // enable / disable watching file and executing tests whenever any file changes
        autoWatch: true,


        // start these browsers
        // available browser launchers: http://ift.tt/1ft83KU
        browsers: ['Chrome'],


        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: false,

        // Concurrency level
        // how many browser should be started simultaneous
        concurrency: Infinity,

        mime: {
            'text/x-typescript': ['ts', 'tsx']
        }
    });
};

Aucun commentaire:

Enregistrer un commentaire