dimanche 30 juillet 2017

karma setup giving require is not defined

I'm new at setting up karma and testing here, so I've been going through a bunch of examples out there to set my env up. However, whenever I run karma start, it gives me this:

Uncaught ReferenceError: require is not defined
at test/person-test.js:1

I think I probably didn't set up my karma.conf.js correctly, does anyone have any clue? This is what I have:

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

    basePath: '',
    frameworks: ['jasmine', 'browserify'],
    files: [
      'test/**/*.js'
    ],
    exclude: [],
    preprocessors: {
      'src/**/*.js': ['browserify']
    },
    plugins: [
      'karma-chrome-launcher',
      'karma-jasmine',
      'karma-browserify'
      ],
    browserify: {
      debug: true,
      transform: [ 'brfs', 'browserify-shim' ]
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    concurrency: Infinity
  })
}

I have file structure like this:

.
├── src
|   └── person.js
├── test
|   ├── person-test.js
├── karma.conf.js
└── package.json

Where my person.js file is like this:

class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  upperCaseName() {
    this.name = this.name.upperCaseName();
  }
}

module.exports = Person;

and (so far) my person-test.js is:

const Person = require('../src/person.js')

Aucun commentaire:

Enregistrer un commentaire