0
votes

I've been trying to run some e2e tests with Karma. It's not working for me at all.

Right now I'm getting the following error:

    Firefox 28.0.0 (Windows 7) ERROR
  ReferenceError: module is not defined
  at C:/MYPATH/Test/node_modules/karma-ng-scenario/lib/ind
ex.js:12

Firefox 28.0.0 (Windows 7) ERROR
  ReferenceError: browser is not defined
  at C:/MYPATH/Test/e2e/scenarios.js:12

My config file looks like this:

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

    basePath : './',

    frameworks: ['ng-scenario'],

    files : [
    './node_modules/karma-ng-scenario/lib/*.js',
      './e2e/*.js'
    ],

    autoWatch : true,

    singleRun : true,

    browsers : ['Firefox'],

    plugins : [
            'karma-ng-scenario',
            'karma-chrome-launcher',
            'karma-firefox-launcher'
            ],

    junitReporter : {
      outputFile: 'test_out/unit.xml',
      suite: 'unit'
    },

    urlRoot : '/__karma/',

    proxies : {
      '/public/' : 'http://localhost:8080'
    }

  });
};

My scenarios file just tests to see if the base path redirects. I've already done a lot of messing with npm to get to this point, most recently "npm install karma-ng-scenario --save-dev" but no luck unfortunately.

3
You are missing ng-mocks fileBKM
I've included it but still getting the same errors.keoghpe

3 Answers

0
votes

In files[] specify path to angular.js as a very first, then any other angular modules you use (angular-mocks.js, angular-resource.js, angular-cookies.js), then any library you use, then your own code.

0
votes

In files:[...] array you have to specify all the files that contain the actual code to which you are writing tests, if your module is using other modules, then you should add files of all the modules on which your module depends.

suppose you are testing 'someModule' module you have to include the 'someModule' controllers, views, services, directives and other modules if your module depends on them

Note: Assuming your files are in their specific directories

files: [
  ...       //angularjs, angular-mocks, karma, protractor and other files you need
  ...                                
  'scripts/someModule/controllers/*.js',
  'scripts/someModule/services/*.js',
  'scripts/someModule/directives/*.js',
  'views/someModule/*.html'
]

or simply

files: [
   ...       //angularjs, angular-mocks, karma, protractor and other files you need
   ...
   'scripts/someModule/**/*.js',
   'views/someModule/*.html'
]

And make sure to install and include all the testing libraries you depend on (i.e, angularjs, angular-mocks, protrator, karma etc) in the files array

0
votes

So the configuration I finally got my E2E tests to work with was this:

// Karma configuration
// Generated on Fri Apr 11 2014 02:35:20 GMT+0800 (China Standard Time)

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

    // base path, that will be used to resolve files and exclude
    basePath: '..',


    // frameworks to use
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
    ANGULAR_SCENARIO,
    ANGULAR_SCENARIO_ADAPTER,
      'test/e2e/*.js',
    ],


    // list of files to exclude
    exclude: [

    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    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, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera (has to be installed with `npm install karma-opera-launcher`)
    // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
    // - PhantomJS
    // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
    //browsers: ['PhantomJS', 'Firefox', 'Chrome'],
    browsers: ['Firefox', 'Chrome'],



    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false,

    proxies : {
    "/": "http://localhost:8080"
    },

    urlRoot : "/__karma/"
  });
};

It seems that a better solution for running end to end tests is to use protractor. NG-SCENARIO is depreciated and will cause warnings but this should still run. https://github.com/angular/protractor