From b73dbd69050bc7e192b1ad0ac9bb880f0ec00a0e Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Sat, 3 Jul 2021 23:18:43 +0200 Subject: [PATCH 1/3] feat(spec-filter): allow custom specFilter Allow users to define their own jasmine `specFilter`. ```js jasmine.getEnv().configure({ specFilter: function(spec) { // ... } }) ``` --- README.md | 26 +++++++++++++++++++ src/adapter.js | 4 +-- test/adapter.spec.js | 18 +++++++++++-- test/fixtures/custom-filter/karma.conf.js | 18 +++++++++++++ .../custom-filter/test/custom-filter.spec.js | 18 +++++++++++++ 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/custom-filter/karma.conf.js create mode 100644 test/fixtures/custom-filter/test/custom-filter.spec.js diff --git a/README.md b/README.md index 1ef4c6d8..15fc7783 100644 --- a/README.md +++ b/README.md @@ -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/). diff --git a/src/adapter.js b/src/adapter.js index 2552c253..a64bf7b7 100644 --- a/src/adapter.js +++ b/src/adapter.js @@ -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 @@ -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 || diff --git a/test/adapter.spec.js b/test/adapter.spec.js index 21063218..de0d3086 100644 --- a/test/adapter.spec.js +++ b/test/adapter.spec.js @@ -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: [] @@ -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) + }) }) }) }) diff --git a/test/fixtures/custom-filter/karma.conf.js b/test/fixtures/custom-filter/karma.conf.js new file mode 100644 index 00000000..28c036ea --- /dev/null +++ b/test/fixtures/custom-filter/karma.conf.js @@ -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('../../../') + ] + }) +} diff --git a/test/fixtures/custom-filter/test/custom-filter.spec.js b/test/fixtures/custom-filter/test/custom-filter.spec.js new file mode 100644 index 00000000..93a1f17a --- /dev/null +++ b/test/fixtures/custom-filter/test/custom-filter.spec.js @@ -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) + }) +}) From c3f702a2a567086e6069dd57b0308c2da1a90e37 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 16 Jun 2022 02:44:36 +0000 Subject: [PATCH 2/3] chore(release): 5.1.0 [skip ci] # [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)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23ac7b2f..b5ebbb82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package.json b/package.json index 310f9f8d..a6b5f6cd 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "Patrick McGuckin ", "Richard Park ", "Fernando Costa ", + "Nico Jansen ", "Aaron Hartwig ", "Alesei N ", "Barry Fitzgerald ", @@ -95,7 +96,6 @@ "Marek Vavrecan ", "Matthew Hill ", "Milan Lempera ", - "Nico Jansen ", "Niels Dequeker ", "Robin Gloster ", "Sahat Yalkabov ", From 057bf014c4ff0901a772dca7b04b7aaa5606a179 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 22:58:34 +0000 Subject: [PATCH 3/3] chore(deps-dev): bump word-wrap from 1.2.3 to 1.2.5 Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.5. - [Release notes](https://github.com/jonschlinkert/word-wrap/releases) - [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.5) --- updated-dependencies: - dependency-name: word-wrap dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7c4da1f7..75008908 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9554,9 +9554,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, "engines": { "node": ">=0.10.0" @@ -16786,9 +16786,9 @@ "dev": true }, "word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true }, "wordwrap": {