File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ php artisan test -p --gql-coverage
28
28
```
29
29
30
30
### Setting coverage limits
31
+
31
32
By adding the argument ` --gql-min=<percentage> ` , we can limit to have a min coverage of x.
32
33
33
34
``` bash
@@ -44,13 +45,32 @@ php artisan test --gql-coverage --gql-untested-count=25
44
45
```
45
46
46
47
### Changing default schema fetching command
48
+
47
49
By default, it will fetch the schema using ` php artisan lighthouse:print-schema ` , however if you have a
48
50
custom command for fetching the schema, that can be used instead by adding ` --schema-command ` argument
49
51
50
52
``` bash
51
53
php artisan test --gql-coverage --schema-command=" php artisan lighthouse:print-schema-v2"
52
54
```
53
55
56
+ ### Excluding nodes from total coverage
57
+
58
+ By default, all nodes will be included when calculating coverage. However, if you have nodes such as the built-in
59
+ Lighthouse pagination types that you do not want to be covered, you can configure ignored fields from your ` Pest.php ` configuration file.
60
+
61
+ ``` php
62
+ <?php
63
+
64
+ declare(strict_types=1);
65
+
66
+ use Worksome\PestGraphqlCoverage\Config;
67
+
68
+ Config::new()->ignore([
69
+ 'PaginatorInfo.count',
70
+ // ...
71
+ ]);
72
+ ```
73
+
54
74
### Native Pest usage
55
75
56
76
This also works natively with Pest (without using Artisan), as it is a Pest plugin.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Worksome \PestGraphqlCoverage ;
6
+
7
+ final class Config
8
+ {
9
+ /** @var array<string, mixed> */
10
+ private static array $ ignoredNodes = [];
11
+
12
+ public static function new (): self
13
+ {
14
+ return new self ();
15
+ }
16
+
17
+ /** @param array<string> $ignoredNodes */
18
+ public function ignore (array $ ignoredNodes ): self
19
+ {
20
+ self ::$ ignoredNodes = array_merge (self ::$ ignoredNodes , array_flip ($ ignoredNodes ));
21
+
22
+ return $ this ;
23
+ }
24
+
25
+ /** @return array<string, mixed> */
26
+ public static function ignoredNodes (): array
27
+ {
28
+ return self ::$ ignoredNodes ;
29
+ }
30
+ }
Original file line number Diff line number Diff line change @@ -138,6 +138,9 @@ public function addOutput(int $testReturnCode): int
138
138
// Create an array of all untested nodes.
139
139
$ untested = array_diff_key ($ dottedNodes , $ dottedTestedNodes );
140
140
141
+ // Remove ignored nodes
142
+ $ untested = array_diff_key ($ untested , Config::ignoredNodes ());
143
+
141
144
// Count the nodes and calculate the percentage of tested nodes.
142
145
$ totalNodes = count ($ dottedNodes );
143
146
$ totalTestedNodes = $ totalNodes - count ($ untested );
You can’t perform that action at this time.
0 commit comments