I am trying to setup karma to run the unit tests for our magento site and having a lot of problems.
Here is my karma config file:
// Karma configuration // Generated on Thu Jan 05 2017 01:04:20 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: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['jasmine', 'requirejs'], // list of files / patterns to load in the browser files: [ 'test-main.js', {pattern: '../jasmine/tests/**/*.js', included: false}, {pattern: '../../../../pub/static/_requirejs/frontend/Magento/blank/en_US/**/*.js', included: false}, {pattern: '../../../../pub/static/frontend/Magento/blank/en_US/**/*.js', included: true} //{pattern: '../../../../pub/static/frontend/Magento/blank/en_US/js/bundle/**/*.js', included: true} ], // list of files to exclude exclude: [ //'../../../../pub/static/frontend/Magento/blank/en_US/js/bundle/**', //'../../../../pub/static/frontend/Magento/blank/en_US/Magento_Braintree/**', //'../../../../pub/static/frontend/Magento/blank/en_US/Magento_ConfigurableProduct/**', //'../../../../pub/static/frontend/Magento/blank/en_US/Magento_Paypal/**', //'../../../../pub/static/frontend/Magento/blank/en_US/Magento_Authorizenet/**' ], // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { '*.js': 'coverage' }, // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter reporters: ['progress','coverage'], coverageReporter: { // specify a common output directory dir: 'coverage', reporters: [ // reporters not supporting the `file` property { type: 'html', subdir: 'report-html' }, { type: 'lcov', subdir: 'report-lcov' }, // reporters supporting the `file` property, use `subdir` to directly // output them in the `dir` directory { type: 'cobertura', subdir: '.', file: 'cobertura.txt' }, { type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' }, { type: 'teamcity', subdir: '.', file: 'teamcity.txt' }, { type: 'text', subdir: '.', file: 'text.txt' }, { type: 'text-summary', subdir: '.', file: 'text-summary.txt' }, ] }, // 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: https://npmjs.org/browse/keyword/karma-launcher browsers: ['PhantomJS'], // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits singleRun: true, // Concurrency level // how many browser should be started simultaneous concurrency: Infinity }) }
Right now I am getting a lot of requirejs errors saying "Error: Mismatched anonymous define() module: {0}" I have been searching all over the place trying to figure out how to set this up and haven't been able to fix it. The reason I am trying to set this up is to generate an LCOV report that I can import into SonarQube to show our test coverage.
Thanks
Hi @srarnold,
Since this has been posted several days ago, I would like to know if you were able to find the solution.
Please let us know.
Best regards.
Gabriel