1 | # karma-jasmine
|
2 |
|
3 | [![npm version](https://img.shields.io/npm/v/karma-jasmine?style=flat-square)](https://www.npmjs.com/package/karma-jasmine)
|
4 | [![npm downloads](https://img.shields.io/npm/dm/karma-jasmine?style=flat-square)](https://www.npmjs.com/package/karma-jasmine)
|
5 | [![Release Workflow Status](https://img.shields.io/github/workflow/status/karma-runner/karma-jasmine/Release/master?style=flat-square&logo=github&label=Release)](https://github.com/karma-runner/karma-jasmine/actions/workflows/release.yml?query=branch%3Amaster)
|
6 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen?style=flat-square)](https://github.com/karma-runner/karma-jasmine)
|
7 | [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079?style=flat-square)](https://github.com/semantic-release/semantic-release)
|
8 |
|
9 | > Adapter for the [Jasmine](https://jasmine.github.io/) testing framework.
|
10 |
|
11 | ## Installation
|
12 |
|
13 | ```bash
|
14 | npm install karma-jasmine --save-dev
|
15 | ```
|
16 |
|
17 | ## Configuration
|
18 |
|
19 | ```js
|
20 | // karma.conf.js
|
21 | module.exports = function(config) {
|
22 | config.set({
|
23 | frameworks: ['jasmine'],
|
24 | files: [
|
25 | '*.js'
|
26 | ]
|
27 | })
|
28 | }
|
29 | ```
|
30 |
|
31 | If you want to run only some tests whose name match a given pattern you can do this in the following way
|
32 |
|
33 | ```bash
|
34 | $ karma start &
|
35 | $ karma run -- --grep=<pattern>
|
36 | ```
|
37 |
|
38 | where pattern is either a string (e.g `--grep=#slow` runs tests containing "#slow") or a Regex (e.g `--grep=/^(?!.*#slow).*$/` runs tests _not_ containing "#slow").
|
39 |
|
40 | You can also pass it to `karma.config.js`:
|
41 |
|
42 | ```js
|
43 | module.exports = function(config) {
|
44 | config.set({
|
45 | // ...
|
46 | client: {
|
47 | args: ['--grep', '<pattern>'],
|
48 | // ...
|
49 | }
|
50 | })
|
51 | }
|
52 | ```
|
53 |
|
54 | If you want to pass configuration options directly to jasmine you can do this in the following way
|
55 |
|
56 | ```js
|
57 | module.exports = function(config) {
|
58 | config.set({
|
59 | client: {
|
60 | jasmine: {
|
61 | random: true,
|
62 | seed: '4321',
|
63 | oneFailurePerSpec: true,
|
64 | failFast: true,
|
65 | timeoutInterval: 1000
|
66 | }
|
67 | }
|
68 | })
|
69 | }
|
70 | ```
|
71 |
|
72 | ## Debug by URL
|
73 |
|
74 | Failing tests print a debug URL with `?spec=`. Use it with `--no_single_run`
|
75 | and paste it into your browser to focus on a single failing test.
|
76 |
|
77 | ## Sharding
|
78 |
|
79 | By setting `config.client.shardIndex` and `config.client.totalShards`, you can
|
80 | run a subset of the full set of specs. Complete sharding support needs to be
|
81 | done in the process that calls karma, and would need to support test result
|
82 | integration across shards.
|
83 |
|
84 | ## Custom spec filter
|
85 |
|
86 | Providing a [custom spec filter](https://jasmine.github.io/api/edge/Configuration#specFilter) is also supported.
|
87 |
|
88 | Example:
|
89 |
|
90 | ```js
|
91 | // Users are able to set a custom specFilter themselves
|
92 |
|
93 | jasmine.getEnv().configure({
|
94 | specFilter: function (spec) {
|
95 | return spec.getFullName() === 'spec that succeeds'
|
96 | }
|
97 | })
|
98 |
|
99 | describe('spec', () => {
|
100 | it('that fails', () => {
|
101 | fail('This spec should not run!')
|
102 | })
|
103 |
|
104 | it('that succeeds', () => {
|
105 | expect(1).toBe(1)
|
106 | })
|
107 | })
|
108 | ```
|
109 |
|
110 | ---
|
111 |
|
112 | For more information on Karma see the [homepage](https://karma-runner.github.io/).
|