๐Ÿ“ฆ J-Sek / example-gulp-karma-include-all

๐Ÿ“„ Readme.md ยท 67 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67# "Include All" with gulp and karma-coverage

Example project using Require.js and file path patterns. 
Prooving it is possible to get 0% coverage and not worry about
confliciting implementations.

> Note: you **don't need** to use Require.js across the solution.

---

![](screenshots/report.png)

---

Setup:

    npm install

Run:

    npm test

or:

    gulp coverage

compare with:

    gulp coverage_tested

---

### How is it working?

- Set pattern to match all files but include none:

```
{pattern: 'Scripts/App/**/*.js', included: false},
{pattern: 'Scripts/Test/**/*Spec.js', included: false},
```

- Configure require.js

```
var tests = [];
for (var file in window.__karma__.files) {
    if (/Spec\.js$/.test(file)) {
        tests.push(file);
    }
}

require(['/base/Scripts/App/Calc.js']);

requirejs.config({
    deps: tests,
    callback: window.__karma__.start
});
```

- Use additional flag for Istanbul

```
coverageReporter: {
    includeAllSources: true,
    ...
}
```