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) {

    basePath: '',
    frameworks: ['jasmine', 'browserify'],
    files: [
    exclude: [],
    preprocessors: {
      'src/**/*.js': ['browserify']
    plugins: [
    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')

Basically you need to transform your source code for the browser, replacing require calls with the actual module code. Take a look at these utilities:

http://browserify.org/ – it does exactly the transformation you need

https://webpack.github.io/ – a more complicated web packaging framework, with lots of other useful features.


Karma is a test runner that runs your tests in a browser. Whatever browser you setup doesn’t know what the require function is.

To use jasmine with node try jasmine-node. https://github.com/mhevery/jasmine-node