How does Karma know source from test files?

Viewed 647

Before installing Browserify I get a passing test:

Chrome 48.0.2564 (Mac OS X 10.11.3): Executed 1 of 1 SUCCESS (0.007 secs / 0.001 secs)

My file structure looks like this:

+ src
|  +-- functions.js
+ test
|  + spec
|    +-- functionsSpec.js
+-- karma.conf.js

functionsSpec.js:

describe("test", function() {
  it("should be recognized as a function inside functions.js", function() {
    expect(test()).toBe("Test")
  });
});

functions.js:

function test() {
    return "Test"
}

karma.conf.js:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: [
      'src/*.js',
      'test/**/*Spec.js'
    ],
    exclude: [
    ],
    preprocessors: {
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    concurrency: Infinity
  })
}

The moment I add browserify--by adding 'browserify' to the config file frameworks and preprocessors, and adding the browserify config entry with debug: true--my test fails. Here's that failure message:

Chrome 48.0.2564 (Mac OS X 10.11.3) test should be recognized as a function inside functions.js FAILED
    ReferenceError: test is not defined
        at Object.<anonymous> (/var/folders/km/xnwtjkn55_ddyj7q5qcr1j3r0000gn/T/4ba5e45cb5a106308dd677294fb01296.browserify:57:10 <- test/spec/FunctionsSpec.js:6:0)
Chrome 48.0.2564 (Mac OS X 10.11.3): Executed 1 of 1 (1 FAILED) ERROR (0.015 secs / 0.003 secs)

How does Karma know which of the file-paths you supply it (in config/files) are source and which are corresponding tests? Browserify bundles files, by doing so does it break whatever mechanisms Karma uses to make this distinction? And if so, does that mean because I'm using browserify with Karma I have to manually require all my source files in my test files? I've looked through the Karma website/documentation on the Configuration File, config/files, and preprocessors. I've also searched around stack overflow. I'm coming up blank. I'm going to start digging through code, but first I wanted to see if anyone with experience could help me out. I can only imagine others would find an in depth explanation of config/files helpful. Thanks!

0 Answers
Related