dimanche 13 novembre 2016

Make Karma works with Ember.js

I want to use Karma in an ember app.

I have this conf file :

// Karma configuration
// Generated on Sun Nov 13 2016 10:50:12 GMT+0000 (UTC)

module.exports = function(config) {
  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: ['mocha'],


    // list of files / patterns to load in the browser
    files: [
      'app/**/*.js',
      'tests/**/*test.js'
    ],


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


    // preprocess matching files before serving them to the browser
    // available preprocessors: http://ift.tt/1gyw6MG
    preprocessors: {
      'app/**/*.js': ['babel'],
      'tests/**/*.js': ['babel']
    },


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


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


    // 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,
    babelPreprocessor: {
      options: {
        presets: ['latest'],
        plugins: [
          ["transform-decorators-legacy"],
          ["transform-es2015-modules-umd"]
        ],
        sourceMap: 'inline'
      }
    }
  })
}

When I run karma start I have this error :

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  TypeError: undefined is not an object (evaluating '_emberData2.default.JSONAPIAdapter')
  at app/adapters/application.js:36

I stops at this file :

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend(DataAdapterMixin, {
});

I understand it can not find 'ember-data'.

I tried to add 'node_modules/**/*.js', 'bower_components/**/*.js' in the loaded files but I have this error :

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  ReferenceError: Can't find variable: require
  at node_modules/JSONStream/examples/all_docs.js:1

I also tried to include each module like this :

files: [
  'bower_components/jquery/dist/jquery.js',
  'bower_components/ember/ember.js',
  'node_modules/ember-data/app/**/*.js',
  'node_modules/ember-data/addon/**/*.js',
  'node_modules/ember-data/lib/**/*.js',
  'node_modules/ember-data/blueprints/*.js',
  'app/**/*.js',
  'tests/**/*test.js'
],

But I have this message :

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  TypeError: undefined is not an object (evaluating '_ember2.default.K')
  at node_modules/ember-data/app/initializers/data-adapter.js:31

I suppose I can include all modules one by one but it will be tedious and not maintainable.

What's te best way to use ember with karma ?




Aucun commentaire:

Enregistrer un commentaire