Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serve multiple directories as baseDir #2259

Open
luisvt opened this issue Jul 15, 2016 · 3 comments
Open

Allow serve multiple directories as baseDir #2259

luisvt opened this issue Jul 15, 2016 · 3 comments

Comments

@luisvt
Copy link

luisvt commented Jul 15, 2016

Expected behavior

Allow specify a configuration option to be able to serve some directories like node_modules and bower_components as base directories.

This should be similar to what (browserSync baseDir)[https://www.browsersync.io/docs/options#option-server] option does. This will allow developers to use npm packages for browser unit-testing.

Actual behavior

Right now we should specify all the files coming from node_modules one by one. This is cumbersome. For example if we want to use requirejs, angular and lodash we should do:

files: [
  {pattern: 'node_modules/angular/angular.js', included: false},
  {pattern: 'node_modules/requirejs/require.js', included: false},
  {pattern: 'node_modules/lodash/lodash.js', included: false},
  'test-main.js'
}

since trying to use a glob value for node modules doesn't work, for example doing this:

files: [
  {pattern: 'node_modules/**/*.js', included: false},
  'test-main.js'
}

throws next error:

You need to include some adapter that implements __karma__.start method!

Enviroment Details

  • Karma version: 1.1.1
  • Relevant part of your karma.config.js file
    files: [
      {pattern: 'node_modules/angular/**/*.js', included: false},
      {pattern: 'node_modules/angular-mocks/**/*.js', included: false},
      {pattern: 'node_modules/angular-resource/**/*.js', included: false},
      {pattern: 'node_modules/ts-helpers/index.js', included: false},
      {pattern: 'src/**/*', included: false},
      {pattern: 'test/**/*', included: false},
      'test/test-main.js'
    ],
    // list of files to exclude
    exclude: [
      'node_modules/**/test/**/*.js',
      'node_modules/**/*.spec.js',
      'node_modules/**/*.test.js'
    ],
@dignifiedquire
Copy link
Member

dignifiedquire commented Jul 26, 2016

The error about the __karma__.start method is tracked in #2194 and has nothing to do with the behaviour you are looking for. Your second configuration should work fine. Also in general you can easily write a method for the behaviour that you want

function toModule (name) {
  return {
    pattern: 'node_modules/' + name,
    included: false
  }
}
// later
files: [
  toModule('angular/angular.js'),
  toModule('requirejs/require.js'),
  toModule('lodash/lodash.js'),
  'test-main.js'
}

@luisvt
Copy link
Author

luisvt commented Aug 25, 2016

with karma 1.2.0 having next code in karma.config.js:

files: [
  {pattern: 'node_modules/**/*.js', included: false},
  'test-main.js'
}

it produces next error message:

25 08 2016 18:41:32.578:ERROR [karma]: { Error: listen ENFILE 0.0.0.0:9876
    at Object.exports._errnoException (util.js:1008:11)
    at exports._exceptionWithHostPort (util.js:1031:20)
    at Server._listen2 (net.js:1240:19)
    at listen (net.js:1289:10)
    at Server.listen (net.js:1385:5)
    at afterPreprocess (/Users/lvargas/projects/js/angular-typescript/node_modules/karma/lib/server.js:174:15)
    at tryCatcher (/Users/lvargas/projects/js/angular-typescript/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/lvargas/projects/js/angular-typescript/node_modules/bluebird/js/release/promise.js:509:31)
    at Promise._settlePromise (/Users/lvargas/projects/js/angular-typescript/node_modules/bluebird/js/release/promise.js:566:18)
    at Promise._settlePromise0 (/Users/lvargas/projects/js/angular-typescript/node_modules/bluebird/js/release/promise.js:611:10)
    at Promise._settlePromises (/Users/lvargas/projects/js/angular-typescript/node_modules/bluebird/js/release/promise.js:686:18)
    at Async._drainQueue (/Users/lvargas/projects/js/angular-typescript/node_modules/bluebird/js/release/async.js:138:16)
    at Async._drainQueues (/Users/lvargas/projects/js/angular-typescript/node_modules/bluebird/js/release/async.js:148:10)
    at Immediate.Async.drainQueues (/Users/lvargas/projects/js/angular-typescript/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:566:20)
    at tryOnImmediate (timers.js:546:5)
  code: 'ENFILE',
  errno: 'ENFILE',
  syscall: 'listen',
  address: '0.0.0.0',
  port: 9876 }

From what I understand it means that Karma Server is trying to open and listen into too many files.

@wesleycho
Copy link
Member

This is because that glob pattern is overly broad.

IMO, that is fine, because a broad glob pattern has huge negative performance implications as well. This is one area where I think supporting has large negative ramifications for the user on the performance side, and that nothing more should be done in karma itself in regards to this area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants