mardi 1 mars 2016

404 warnings for node_module(ng2-translate) during karma unit test(ionic 2)

I am building an app in ionic 2 but i get an error during unit testing with karma:

01 03 2016 10:56:38.451:WARN [web-server]: 404: /base/ng2-translate/ng2-translate.js

I've already tried to add this file in my karma.config.js but it is still not working. Does sombody know how to load this file from node_modules?

   // Karma configuration
    // Generated on Wed Jul 15 2015 09:44:02 GMT+0200 (Romance Daylight Time)

    module.exports = function(config) {
      'use strict';
      config.set({

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

    // frameworks to use
    // available frameworks: http://ift.tt/1ft83uu



    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [      
      'node_modules/http://ift.tt/1KReLA2',
      'node_modules/http://ift.tt/1KReNIi',
      'node_modules/http://ift.tt/1KReLA0',
      'node_modules/es6-module-loader/dist/es6-module-loader.js',
      'node_modules/traceur/bin/traceur.js',
      'node_modules/systemjs/dist/system.src.js',
      'node_modules/reflect-metadata/Reflect.js',     

      { pattern: 'node_modules/angular2/**/*.js', included: false, watched: false },
      { pattern: 'node_modules/ionic-framework/**/*.js', included: false, watched: false },     
      { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
      { pattern: 'www/build/test/**/*.js', included: false, watched: true },
      //{ pattern: 'www/build/test/pages/**/*.js', included: true, watched: true, served: true},
      { pattern: 'www/build/test/**/*.html', included: false, served: true},     

      'test/test-main.js'
    ],

    // list of files to exclude
    exclude: [      
      'node_modules/angular2/**/*_spec.js',
      'node_modules/ionic-framework/**/*spec*',
      'node_modules/ionic-framework/decorators/app.js',
    ],

    // preprocess matching files before serving them to the browser
    // available preprocessors: http://ift.tt/1gyw6MG
    preprocessors: {
      'www/build/test/**/!(*.spec|*.stub).js': 'coverage',
    },

    // options on how to report coverage:
    coverageReporter: {
      reporters: [
        {type: 'text'},
        {type: 'lcov', dir: 'coverage', subdir: '.'}
      ]
    },

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

    // web server port
    port: 9876,

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

    // GOTCHA -- Karma proxies _everything_ through base first..
    //           Also any files you want to serve need to be in the files array above with serverd: true
    proxies: {
      // allows us to keep test code separate from app code and still have the references work
      '/base/node_modules/ionic-framework/decorators/app.js': '/base/www/build/test/app.stub.js', // stub out Ionic's @App decorator
      '/build': '/base/www/build/test',
      '/pages/': '/app/pages/'
    },

    // 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: [
      'PhantomJS',
    ],

    customLaunchers: {
      Chrome_travis_ci: {
        base: 'Chrome',
        flags: ['--no-sandbox']
      }
    },

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

  if (process.env.APPVEYOR) {
    config.browsers = ['IE'];
    config.singleRun = true;
    config.browserNoActivityTimeout = 90000; // Note: default value (10000) is not enough
  }

  if (process.env.TRAVIS || process.env.CIRCLECI) {
    config.browsers = ['Chrome_travis_ci'];
    config.singleRun = true;
  }
};

this is my test file:

import { FlexCalendar } from './flex-calendar';



let flexCalendar: FlexCalendar = null;


export function main(): void {
  'use strict';

  describe('FlexCalendar', () => {

    beforeEach(() => {      
      flexCalendar = new FlexCalendar(null, null);      
    });

    it('initialises', () => {
      expect(flexCalendar).not.toBeNull();
    });
  });
}

and these are the files that the tested file is importing:

    import {IonicApp, NavController} from 'ionic/ionic';
    import {Component, Input, Output, OnChanges, EventEmitter} from 'angular2/core';
    import {TranslatePipe} from 'ng2-translate/ng2-translate';

Aucun commentaire:

Enregistrer un commentaire