Skip to content

Commit

Permalink
Merge branch 'master' into xhm/lf
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Mar 29, 2024
2 parents 19d22cf + 057bf01 commit cb0bf46
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [5.1.0](https://github.com/karma-runner/karma-jasmine/compare/v5.0.1...v5.1.0) (2022-06-16)


### Features

* **spec-filter:** allow custom specFilter ([b73dbd6](https://github.com/karma-runner/karma-jasmine/commit/b73dbd69050bc7e192b1ad0ac9bb880f0ec00a0e))

## [5.0.1](https://github.com/karma-runner/karma-jasmine/compare/v5.0.0...v5.0.1) (2022-05-13)


Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,32 @@ run a subset of the full set of specs. Complete sharding support needs to be
done in the process that calls karma, and would need to support test result
integration across shards.

## Custom spec filter

Providing a [custom spec filter](https://jasmine.github.io/api/edge/Configuration#specFilter) is also supported.

Example:

```js
// Users are able to set a custom specFilter themselves

jasmine.getEnv().configure({
specFilter: function (spec) {
return spec.getFullName() === 'spec that succeeds'
}
})

describe('spec', () => {
it('that fails', () => {
fail('This spec should not run!')
})

it('that succeeds', () => {
expect(1).toBe(1)
})
})
```

---

For more information on Karma see the [homepage](https://karma-runner.github.io/).
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"Patrick McGuckin <patrick@gskinner.com>",
"Richard Park <objectiv@gmail.com>",
"Fernando Costa <fadc80@gmail.com>",
"Nico Jansen <jansennico@gmail.com>",
"Aaron Hartwig <aaron.hartwig@whyhigh.com>",
"Alesei N <github.com@bzik.net>",
"Barry Fitzgerald <barfitzgerald@gmail.com>",
Expand All @@ -95,7 +96,6 @@
"Marek Vavrecan <vavrecan@gmail.com>",
"Matthew Hill <Matthew.Hill4@bskyb.com>",
"Milan Lempera <milanlempera@gmail.com>",
"Nico Jansen <jansennico@gmail.com>",
"Niels Dequeker <niels.dequeker@gmail.com>",
"Robin Gloster <robin@loc-com.de>",
"Sahat Yalkabov <sakhat@gmail.com>",
Expand Down
4 changes: 2 additions & 2 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ var KarmaSpecFilter = function (clientConfig, jasmineEnv) {
var createSpecFilter = function (config, jasmineEnv) {
var karmaSpecFilter = new KarmaSpecFilter(config, jasmineEnv)

var originalSpecFilter = jasmineEnv.configuration().specFilter
var specFilter = function (spec) {
return karmaSpecFilter.matches(spec)
return originalSpecFilter(spec) && karmaSpecFilter.matches(spec)
}

return specFilter
Expand All @@ -502,7 +503,6 @@ function createStartFn (karma, jasmineEnv) {
jasmineEnv = jasmineEnv || window.jasmine.getEnv()

jasmineConfig.specFilter = createSpecFilter(clientConfig, jasmineEnv)

jasmineEnv.configure(jasmineConfig)

window.jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineConfig.timeoutInterval ||
Expand Down
18 changes: 16 additions & 2 deletions test/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,17 +572,21 @@ describe('jasmine adapter', function () {
name: 'test',
id: 1
}
var mockConfiguration = {
specFilter: jasmine.createSpy().and.returnValue(true)
}
mockJasmineEnv = {
topSuite: () => {
return {
children: [mockSpecTest, mockSpecBar]
}
}
},
configuration: () => mockConfiguration
}
specs = mockJasmineEnv.topSuite().children
})

describe(' getGrepSpecsToRun', function () {
describe('getGrepSpecsToRun', function () {
it('should not match without grep arg', function () {
var karmaConfMock = {
args: []
Expand Down Expand Up @@ -660,6 +664,16 @@ describe('jasmine adapter', function () {
expect(specFilter(mockSpecTest)).toEqual(true)
expect(specFilter(mockSpecBar)).toEqual(false)
})
it('should still allow a custom spec filter', function () {
var karmaConfMock = {}
mockJasmineEnv.configuration().specFilter.and.returnValue(false)
var specFilter = createSpecFilter(karmaConfMock, mockJasmineEnv)
expect(specFilter(mockSpecTest)).toEqual(false)
expect(specFilter(mockSpecBar)).toEqual(false)
expect(mockJasmineEnv.configuration().specFilter).toHaveBeenCalledTimes(2)
expect(mockJasmineEnv.configuration().specFilter).toHaveBeenCalledWith(mockSpecTest)
expect(mockJasmineEnv.configuration().specFilter).toHaveBeenCalledWith(mockSpecBar)
})
})
})
})
18 changes: 18 additions & 0 deletions test/fixtures/custom-filter/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = function (config) {
config.set({
frameworks: ['jasmine'],
reporters: ['karma-jasmine'],

files: ['test/*.js'],

browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'],

autoWatch: true,

plugins: [
'karma-firefox-launcher',
'karma-chrome-launcher',
require.resolve('../../../')
]
})
}
18 changes: 18 additions & 0 deletions test/fixtures/custom-filter/test/custom-filter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Users are able to set a custom specFilter themselves
// karma-jasmine will allow them to do so.

jasmine.getEnv().configure({
specFilter: function (spec) {
return spec.getFullName() !== 'spec that fails'
}
})

describe('spec', () => {
it('that fails', () => {
fail('This spec should not run!')
})

it('that succeeds', () => {
expect(1).toBe(1)
})
})

0 comments on commit cb0bf46

Please sign in to comment.