jeudi 28 janvier 2016

Can't find variable: exports with Karma with Ember-Cli

I'm trying to run my tests with Karma in an Ember app.

I have this karma.conf.js file :

// Karma configuration
// Generated on Wed Jan 27 2016 13:35:28 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: [
      'bower_components/jquery/dist/jquery.js',
      'bower_components/ember/ember.debug.js',
      'bower_components/ember-data/ember-data.js',
      'bower_components/ember-mocha-adapter/adapter.js',
      "app/**/*.hbs",
      "app/**/*.js",
      "tests/**/*.js"
    ],


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

    plugins: [
     'karma-mocha',
     'karma-ember-preprocessor',
     'karma-phantomjs-launcher',
     'karma-babel-preprocessor'
    ],



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

    babelPreprocessor: {
      options: {
        presets: ['es2015'],
        sourceMap: 'inline'
      },
    },


    // 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: false,


    // start these browsers
    // available browser launchers: http://ift.tt/1ft83KU
    browsers: ['PhantomJS', '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
  })
}

When I do karma start and karma run, I have this error message :

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  ReferenceError: Can't find variable: exports
  at /frontend/app/adapters/application.js:3

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  ReferenceError: Can't find variable: exports
  at /frontend/app/adapters/application.js:3

Here is the line in question :

export default ActiveModelAdapter.extend(DataAdapterMixin, {

I already saw this question on the subject but I think there must be a better way with a preprocessor.

If I understand, babel should convert, from es6 to e5, this file but it didn't.

I didn't found a tutorial to setup ember tests with ember-cli + karma + mocha. Any resource is welcomed.




Aucun commentaire:

Enregistrer un commentaire