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

Karma 0.13 ignores included:false pattern #1530

Closed
hacst opened this issue Aug 2, 2015 · 11 comments · May be fixed by Omrisnyk/npm-lockfiles#122 or Omrisnyk/npm-lockfiles#132
Closed

Karma 0.13 ignores included:false pattern #1530

hacst opened this issue Aug 2, 2015 · 11 comments · May be fixed by Omrisnyk/npm-lockfiles#122 or Omrisnyk/npm-lockfiles#132

Comments

@hacst
Copy link

hacst commented Aug 2, 2015

Hi. In one of my projects Karma started to include files marked with "included:false" in the karma.conf.js after I upgraded to Karma 0.13.3. Switching back to 0.12.37 resolves the issue so either there was a intended behavioral change (either undocumented or breaking some wrong assumptions on my side) or a regression. I reproduced the issue on Windows 10 as well as Ubuntu 15.04.

The karma.conf.js looks something like this:

module.exports = function(config) {
  config.set({
    basePath: '../',
    ...
    files: [
      {pattern: 'src/scripts/backend/worker.js', included: false}, // Web-worker script with entry point
      'src/scripts/**/*.js',
      'test/unit/test_*.js'
    ],
    ...
  });
};

The worker.js script contains web-worker specific functionality and hence must not be executed directly.

Steps to reproduce:

Expected: As worker.js should not be included directly its contents should be ignored and the dummy test should pass in both runs of npm test

Actual: For the first run with Karma 0.13.3 worker.js is included and Karma fails and complains about someWebworkerSpecificFunction in worker.js. The second run with Karma 0.12.37 works as expected.

As I said. I'm not sure if it's something I'm doing or not but the behavior definitely changed between those two versions.

@dignifiedquire
Copy link
Member

Thanks for the detailed report I will see what I can find out. There have been a lot of changes in this area so this is probably a simple regression on our side

hacst added a commit to LogikSim/LogikSim that referenced this issue Aug 2, 2015
- Karma 0.13.X seems to have a regression when it comes to
  removing files from inclusion which prevents us from using it
  (see karma-runner/karma#1530). Instead
  stick to 0.12.X until the issue is resolved.
@khealy316
Copy link

I have the same problem as well. I would like to use the latest version for testing with ES6 and WebPack, but I still need to run my old ES5 tests and would like to ignore the ES6 files for those tests. Thanks!

@ahutchings
Copy link

I'm running into this as well using this set of patterns:

{
  files: [
    '**/__tests__/**/*',
    {
      pattern: 'node_modules/**/__tests__/**/*',
      included: false,
      watched: false,
      served: false
    }
  ]
}

@jaymes-bearden
Copy link

I'm having the exact same issue with the glob pattern ignoring previously declared patterns that have been defined as not included / not served:

...

var sources = [
    'src/app.js',
    ...
    {pattern: 'src/login.js', included: false, served: false, watched: false, useSourcesPath: true},
    'src/**/*.js'
].map(mapToSourcesPath);

var tests = [
    'src/unit/**/*.spec.js',
];

var files = externalSources.concat(libraries, sources, tests);

config.set({
    autoWatch: true,
    basePath: './',
    browsers: ['PhantomJS'],
    files: files,
    frameworks: ['jasmine'],
    reporters: ['dots']
});

...

As specified above, login.js is under /src/ and becomes included even though included and served are set to false. Reverting back to 0.12.37 returns to the expected behavior.

@danhaller
Copy link

Similar problem with 0.13 here, this pattern previously worked but now does not:

'src/**/!(*scenario).js'

i.e. include all .js files except ones containing scenario

@DarthCharles
Copy link
Contributor

I've been trying to track this down to see whats going on, it appears that in this part

   var included = this._patterns.filter(function (pattern) {
      return pattern.included
    })
    .map(function (p) {
          return from(self.buckets.get(p.pattern) || []).sort(byPath)
    });

the map function is not working properly, it returns files that are not included in the filter function. I don't how to proceed next.

@jaymes-bearden
Copy link

Any update on the proposed fix above?

@boneskull
Copy link
Contributor

I'm having a similar problem. I was not able to get included: false to work in any way, shape or form.

The documentation claims:

Eventually, all the patterns will get resolved into files using glob, so you can use minimatch expressions like test/unit/*/.spec.js.

I was unable to get a glob like !path/to/file working; Karma wants to form a path which looks like /absolute/path/to/cwd/!path/to/file, and throws an exception.

My workaround:

var globby = require('globby');
module.exports = function(config) {
  config.set({
    files: globby.sync([
      './src/**/*.js',
      './test/unit/**/*.js',
      '!./src/util/async-listener.js',
      '!./src/plugins/resolver.js',
      '!./src/options/rc.js'
    ])
  });
};

Use case: I'm using karma-browserify to transform my modules, but I have a browser field which replaces the three files above prefixed with ! with browser versions. I was unable to find another solution than the above.

@dignifiedquire
Copy link
Member

@budde377 any chance you could take a look at this?

@budde377
Copy link
Member

budde377 commented Mar 7, 2016

@dignifiedquire Yes. I'll get right at it.

@budde377 budde377 self-assigned this Mar 7, 2016
@dignifiedquire
Copy link
Member

Thanks @budde377 !

budde377 added a commit to budde377/karma that referenced this issue Mar 7, 2016
Do not include a file, when `include=false`.
Give `include=false` precedence over `include=true`.

Closes karma-runner#1530
budde377 added a commit to budde377/karma that referenced this issue Mar 7, 2016
Do not include a file, when `include=false`.
Give `include=false` precedence over `include=true`.

Closes karma-runner#1530
budde377 added a commit to budde377/karma that referenced this issue Mar 17, 2016
Define specificity of patterns.
Let most specific pattern decide to include files or not.

Closes karma-runner#1530
budde377 added a commit to budde377/karma that referenced this issue Mar 17, 2016
Define specificity of patterns.
Let most specific pattern decide to include files or not.

Closes karma-runner#1530
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants