1
votes

I'm trying to set up karma tests with Jasmine on my Angular project.

I can't get basic test

`it("dummy", function() {
    expect(true).toBe(true);`

to run, and I'm getting the error:

PhantomJS 1.9.8 (Linux 0.0.0) ERROR Error: Cannot find module 'gulp'

This is my gulp test task:

gulp.task('test', function(coverage) {
   gulp.src('dummy')
   .pipe(karma({
   configFile: 'karma.conf.js',
   action: 'run'
  }))
  .on('error', function(err) {
      // Make sure failed tests cause gulp to exit non-zero
      throw err;
  });

});

And this is my karma conf file:

module.exports = function(config) {
  config.set({
    // base path, that will be used to resolve files and exclude
    basePath: '',

    // testing framework to use (jasmine/mocha/qunit/...)
    frameworks: ['browserify', 'jasmine'],

    plugins : [
      'karma-browserify',
      'karma-jasmine',
      'karma-phantomjs-launcher'
    ],

    preprocessors: {
      'src/app/**/*.spec.js': [ 'browserify' ], 
      'src/components/**/*.spec.js': [ 'browserify' ], 
      'src/services/**/*.spec.js': [ 'browserify' ]
    },

    // list of files / patterns to load in the browser
    files: [
      'bower_components/jquery/dist/jquery.js',
      'bower_components/angular/angular.js',
      'bower_components/angular-cookies/angular-cookies.js',
      'bower_components/angular-mocks/angular-mocks.js',
      'bower_components/angular-resource/angular-resource.js',
      'bower_components/**/*.js',
      'src/**/*.spec.js'
    ],

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

    // web server port
    port: 8080,

    // level of logging
    // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['PhantomJS'],


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

Please help me stackoverflow you're my only hope!

1

1 Answers

3
votes

The most common question: did you install gulp correctly?

npm install gulp

Also check which files you are loading into the files property in karma.conf.js. There should be only your 3rd party libraries js files, your custom js files and your test files.

There's also a chance that your gulp task is not correct but since I often use grunt, I can't really help in that part :P