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

Ability to add files and preprocessors programmatically #571

Closed
ilyavolodin opened this issue Jun 13, 2013 · 6 comments
Closed

Ability to add files and preprocessors programmatically #571

ilyavolodin opened this issue Jun 13, 2013 · 6 comments

Comments

@ilyavolodin
Copy link
Contributor

I'm setting up Karma to run on CI server for unit testing. I don't really want to specify each file that needs to be included, all of my JavaScript files are located under the same root folder, and if a file has a unit test the unittest file will have the same name as the original file + .test.js extension. It would be nice if I could provide a function that would be able to pick up all the .test.js files, and then get corresponding .js files added to the Karma configuration. Also, would be nice if the same patter would be applied to preprocessors... Right now, I don't know how to setup a wildcard rule to exclude .test.js files from coverage preprocessor.

@vojtajina
Copy link
Contributor

Why using globs does not work for you ?

basePath = 'path/to/root/folder';

files = [
  '**/*.js'
];

preprocessors = {
  '**/!(*.test).js': ['coverage']
};

@ilyavolodin
Copy link
Contributor Author

globs are not flexible enough in some cases. Like the case that is described above, I would want to use */.test.js then iterate through the results and for each file also include a file with the same name, but without "test" suffix. As far as I know, it's not possible to do with just globs.

@xdissent
Copy link
Contributor

Since the config is just JS could you calculate your own list of test files within your config and just pass that? I know that might not be ideal in your dev env (where you may be adding/removing files) but on a CI server presumably that wouldn't be an issue.

@ilyavolodin
Copy link
Contributor Author

Do you mean something like that?

  files = (function() {
    var arrayOfFiles = [];
    ...
    return arrayOfFiles;
  })();

  preprocessors = {
    '**/!(*.test).js': ['coverage']
  };

@xdissent
Copy link
Contributor

Something like that! I also believe the files config array may include objects rather than strings for finer grain control over what is served and watched. Although, that may only be available in canary.

@ilyavolodin
Copy link
Contributor Author

Ah. Thank you very much. I didn't think of that myself.

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