nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease
MIT License
321 stars 49 forks source link

bundle error - cannot find module #157

Closed ekkis closed 8 years ago

ekkis commented 8 years ago

I read through this thread: https://github.com/nikku/karma-browserify/issues/50 and got a little further but I'm still having issues. first, my karma.conf.js (not complete):

module.exports = function(config) {
  config.set({
    frameworks: ['mocha', 'browserify'],
    files: [
      'tests/browser/*.js',
    ],  
   preprocessors: {
        'tests/browser/*.js': ['browserify']
    },  
    browsers: ['PhantomJS'],
    browserify: {
        debug: true,
        all: {
            src: ['src/*.js', 'tests/browser/*.js'],
            dest: 'tests/browser/tests.js'
        }
    }

so one thing I don't understand is how karma tells phantomJs what to run. I have a tests/browser/test.html page that includes the browserised tests/browser/tests.js (which you'll notice includes my source and the tests), which my Gruntfile.js tags via:

    mocha_phantomjs: {
        all: ['tests/browser/test.html']
    },

the other thing I don't understand is how to specify what gets browserified. the last stanza in the karma.conf.js came from my working Gruntfile.js but I have a feeling is wrong since (presumably) the files and preprocessors clauses are supposed to direct that. the docs really give me no clue.

so here's the aim: collect all the src/*.js and tests/browser/*.js into tests/browser/tests.js and have phantomJS run tests/browser/test.html

can anyone help? oh yeah... at present I'm getting these errors:

aprilis:tst ekkis$ clear; karma start

21 12 2015 17:01:27.850:ERROR [framework.browserify]: bundle error 21 12 2015 17:01:27.853:ERROR [framework.browserify]: Error: Cannot find module './lib/chai' from '/Users/ekkis/Development/tst/tests/browser' 21 12 2015 17:01:27.856:ERROR [framework.browserify]: bundle error 21 12 2015 17:01:27.856:ERROR [framework.browserify]: Error: Cannot find module './chai/utils' from '/Users/ekkis/Development/tst/tests/browser' [...] 21 12 2015 17:01:27.926:INFO [karma]: Karma v0.13.15 server started at http://localhost:9876/ 21 12 2015 17:01:27.932:INFO [launcher]: Starting browser PhantomJS 21 12 2015 17:01:29.808:INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket p4GRosUITjsaB0hEAAAA with id 2137851 PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR You need to include some adapter that implements karma.start method!

nikku commented 8 years ago

karma-browserify is a preprocessor for Karma so it probably makes sense for you to read into how Karma works before asking detailed questions about karma-browserify. After all, this will help you to better understand how this plug-in works, too.

As a general note, karma-browserify helps you to test your CommonJS code without the need to bundle it first (and create a test.html or the like). It does so by putting all files mentioned in preprocessors into a browserified bundle. Karma will load the bundle + generated test stubs in its own html page.

Please check out README and the provided example to learn more about this project and how to use it.

ekkis commented 8 years ago

I had read the README in its entirety but it doesn't explain enough for me to figure out how to use it... but I think t's because I don't understand karma well enough. thanks for the reply.

ghost commented 8 years ago

@ekkis Same here. My config is ok according to the readme, and according to the debug the module file was added to the bundle and served, but still I cannot load it with require("./thefile").