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

Add "iit" preprocessor and optimize file loading #1

Open
vojtajina opened this issue Aug 26, 2013 · 1 comment
Open

Add "iit" preprocessor and optimize file loading #1

vojtajina opened this issue Aug 26, 2013 · 1 comment

Comments

@vojtajina
Copy link
Contributor

Similar to https://github.com/karma-runner/karma-closure parse source files (probably using https://github.com/shtylman/node-required to build a dependency tree and optimize file loading (load only required files):

  • when using iit
  • when sharding tests
@itsjamie
Copy link

I'm actively working towards this, hopefully making it slightly easier to setup and less "work" and hopefully solve an issue I ran into. (Where the require worked when running in browserify, but failed when running in this context)

I find myself wondering about the API for Karma.

Is it possible for the framework to return an asynchronous callback or a promise for it's initialization function?

The approach I currently have is the config.preprocessor array would be filtered looking for 'commonjs' entries.

var initCommonJS = function(preprocessors, files) {
    _.filter(preprocessors, function filterCommonJS(frameworks, pattern) {
      if (frameworks.indexOf('commonjs') >= 0) {
        var matches = glob.sync(pattern);
        async.each(matches, function(filePath, cb) {  
          resolver(filePath).then(function(deps) {
            dependencies = _.union(dependencies, deps);
            cb(null);
          });
        }, function() {
          dependencies = _.unique(dependencies, 'filename');

          _.each(dependencies, function(dependency) {
            files.push({
              pattern: dependency.filename,
              included: true,
              served: true,
              watched: true
            });
          });

          // Include the file that resolves all the dependencies on the client.
          files.push({
            pattern: BRIDGE_FILE_PATH,
            included: true,
            served: true,
            watched: false
          });
        });
      }
    });
  }
};
initCommonJS.$inject = ['config.preprocessors', 'config.files'];

Dependencies
resolver is a wrapper around node-required that flattens the recursive tree it builds, would probably be switched out for npm dep flatten-required
async npm dep asnyc
_ npm dep lodash

Issues currently:

  • Karma moves on before the initialization function is actually complete.
  • Native Node Modules (For example, Chai running in a Node environment uses the native Buffer module, I'd be afraid of compatibility with the browser, perhaps an alias map ala..
browser: {
   chai: "path"
}

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

2 participants