Skip to content

Commit

Permalink
fix(files): Ignore included:false pattern
Browse files Browse the repository at this point in the history
Do not include a file, when `include=false`.
Give `include=false` precedence over `include=true`.

Closes #1530
  • Loading branch information
budde377 committed Mar 7, 2016
1 parent 8ef475f commit 8279277
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/config/02-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Each pattern is either a simple string or an object with four properties:
* **Description.** Should the files be included in the browser using
`<script>` tag? Use `false` if you want to load them manually, eg.
using [Require.js](../plus/requirejs.html).

If a file is covered by multiple patterns with different `include` properties, `false` takes precedence over `true`.

### `served`
* **Type.** Boolean
Expand Down
31 changes: 20 additions & 11 deletions lib/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,28 +214,37 @@ List.prototype._refresh = function () {
Object.defineProperty(List.prototype, 'files', {
get: function () {
var self = this
var uniqueFlat = function (list) {
return _.uniq(_.flatten(list), 'path')
}

var expandPattern = function (p) {
return from(self.buckets.get(p.pattern) || []).sort(byPath)
}

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

var excludedPatterns = this._patterns.filter(function (pattern) {
return !pattern.included
})

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

var uniqFlat = function (list) {
return _.uniq(_.flatten(list), 'path')
}
.map(expandPattern)

var flatIncluded = uniqueFlat(included)
flatIncluded = excludedPatterns.reduce(function (included, p) {
return included.filter(function (f) {
return !mm(f.path, p.pattern)
})
}, flatIncluded)
return {
served: uniqFlat(served),
included: uniqFlat(included)
served: uniqueFlat(served),
included: flatIncluded
}
}
})
Expand Down
66 changes: 66 additions & 0 deletions test/e2e/files.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Feature: Including files
In order to use Karma
As a person who wants to write great tests
I want to be able to include and exclude files

Scenario: Execute a test excluding a file
Given a configuration with:
"""
files = [
{pattern: 'files/log_foo.js', included: false},
'files/*.js'
];
browsers = ['PhantomJS'];
plugins = [
'karma-jasmine',
'karma-phantomjs-launcher'
];
"""
When I start Karma
Then it passes with:
"""
.
PhantomJS
"""

Scenario: Execute a test excluding an explicitly included file
Given a configuration with:
"""
files = [
{pattern: 'files/log_foo.js', included: false},
{pattern: 'files/log_foo.js', included: true},
'files/*.js'
];
browsers = ['PhantomJS'];
plugins = [
'karma-jasmine',
'karma-phantomjs-launcher'
];
"""
When I start Karma
Then it passes with:
"""
.
PhantomJS
"""

Scenario: Execute a test excluding an explicitly included file in another order
Given a configuration with:
"""
files = [
'files/*.js',
{pattern: 'files/log_foo.js', included: false},
{pattern: 'files/log_foo.js', included: true}
];
browsers = ['PhantomJS'];
plugins = [
'karma-jasmine',
'karma-phantomjs-launcher'
];
"""
When I start Karma
Then it passes with:
"""
.
PhantomJS
"""
2 changes: 2 additions & 0 deletions test/e2e/support/files/log_foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

console.log('foo')
5 changes: 5 additions & 0 deletions test/e2e/support/files/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('plus', function () {
it('should pass', function () {
expect(true).toBe(true)
})
})

0 comments on commit 8279277

Please sign in to comment.