1
1
import { expect } from 'chai' ;
2
2
import { MutationTestResult } from 'mutation-testing-report-schema/api' ;
3
3
import { aggregateResultsByModule } from '../../src' ;
4
- import { createFileResult , createMutationTestResult , createTestFile } from '../helpers/factories' ;
4
+ import { createFileResult , createMutantResult , createMutationTestResult , createTestDefinition , createTestFile } from '../helpers/factories' ;
5
5
6
6
describe ( aggregateResultsByModule . name , ( ) => {
7
7
it ( 'should result in an empty report when an empty object is provided' , ( ) => {
@@ -38,15 +38,15 @@ describe(aggregateResultsByModule.name, () => {
38
38
39
39
describe ( 'files' , ( ) => {
40
40
it ( 'should prefix files with the module name' , ( ) => {
41
- const file = createFileResult ( ) ;
41
+ const file = createFileResult ( { mutants : [ ] } ) ;
42
42
const module = createMutationTestResult ( { files : { a : file } } ) ;
43
43
const result = aggregateResultsByModule ( { module } ) ;
44
44
expect ( result . files ) . deep . eq ( { 'module/a' : file } ) ;
45
45
} ) ;
46
46
it ( 'should merge file results together' , ( ) => {
47
- const fileA = createFileResult ( ) ;
48
- const fileB = createFileResult ( ) ;
49
- const fileC = createFileResult ( ) ;
47
+ const fileA = createFileResult ( { source : 'core/a' , mutants : [ ] } ) ;
48
+ const fileB = createFileResult ( { source : 'core/b' , mutants : [ ] } ) ;
49
+ const fileC = createFileResult ( { source : 'api/c' , mutants : [ ] } ) ;
50
50
const core = createMutationTestResult ( { files : { a : fileA , b : fileB } } ) ;
51
51
const api = createMutationTestResult ( { files : { a : fileC } } ) ;
52
52
const result = aggregateResultsByModule ( { core, api } ) ;
@@ -56,27 +56,102 @@ describe(aggregateResultsByModule.name, () => {
56
56
57
57
describe ( 'testFiles' , ( ) => {
58
58
it ( 'should prefix test files with the module name' , ( ) => {
59
- const file = createTestFile ( ) ;
59
+ const file = createTestFile ( { tests : [ ] } ) ;
60
60
const module = createMutationTestResult ( { testFiles : { a : file } } ) ;
61
61
const result = aggregateResultsByModule ( { module } ) ;
62
62
expect ( result . testFiles ) . deep . eq ( { 'module/a' : file } ) ;
63
63
} ) ;
64
64
it ( 'should merge test file results together' , ( ) => {
65
- const fileA = createTestFile ( ) ;
66
- const fileB = createTestFile ( ) ;
67
- const fileC = createTestFile ( ) ;
65
+ const fileA = createTestFile ( { source : 'fileA' , tests : [ ] } ) ;
66
+ const fileB = createTestFile ( { source : 'fileB' , tests : [ ] } ) ;
67
+ const fileC = createTestFile ( { source : 'fileC' , tests : [ ] } ) ;
68
68
const core = createMutationTestResult ( { testFiles : { a : fileA , b : fileB } } ) ;
69
69
const api = createMutationTestResult ( { testFiles : { a : fileC } } ) ;
70
70
const result = aggregateResultsByModule ( { core, api } ) ;
71
71
expect ( result . testFiles ) . deep . eq ( { 'core/a' : fileA , 'core/b' : fileB , 'api/a' : fileC } ) ;
72
72
} ) ;
73
73
it ( 'should allow undefined test files' , ( ) => {
74
- const fileA = createTestFile ( ) ;
75
- const fileB = createTestFile ( ) ;
74
+ const fileA = createTestFile ( { source : 'fileA' , tests : [ ] } ) ;
75
+ const fileB = createTestFile ( { source : 'fileB' , tests : [ ] } ) ;
76
76
const core = createMutationTestResult ( { testFiles : { a : fileA , b : fileB } } ) ;
77
77
const api = createMutationTestResult ( { testFiles : undefined } ) ;
78
78
const result = aggregateResultsByModule ( { core, api } ) ;
79
79
expect ( result . testFiles ) . deep . eq ( { 'core/a' : fileA , 'core/b' : fileB } ) ;
80
80
} ) ;
81
81
} ) ;
82
+
83
+ describe ( 'mutants' , ( ) => {
84
+ it ( 'should prefix mutant ids with moduleName' , ( ) => {
85
+ // Arrange
86
+ const fileA = createFileResult ( { mutants : [ createMutantResult ( { id : '1' } ) ] } ) ;
87
+ const fileB = createFileResult ( { mutants : [ createMutantResult ( { id : '1' } ) ] } ) ;
88
+ const core = createMutationTestResult ( { files : { a : fileA } } ) ;
89
+ const api = createMutationTestResult ( { files : { b : fileB } } ) ;
90
+
91
+ // Act
92
+ const result = aggregateResultsByModule ( { core, api } ) ;
93
+
94
+ // Assert
95
+ const mutantsCore = result . files [ 'core/a' ] . mutants ;
96
+ const mutantsApi = result . files [ 'api/b' ] . mutants ;
97
+ expect ( mutantsCore ) . lengthOf ( 1 ) ;
98
+ expect ( mutantsApi ) . lengthOf ( 1 ) ;
99
+ expect ( mutantsCore [ 0 ] . id ) . eq ( 'core_1' ) ;
100
+ expect ( mutantsApi [ 0 ] . id ) . eq ( 'api_1' ) ;
101
+ } ) ;
102
+
103
+ it ( 'should prefix coveredBy with moduleName' , ( ) => {
104
+ // Arrange
105
+ const fileA = createFileResult ( { mutants : [ createMutantResult ( { coveredBy : [ '1' ] } ) ] } ) ;
106
+ const fileB = createFileResult ( { mutants : [ createMutantResult ( { coveredBy : [ '1' , '2' ] } ) ] } ) ;
107
+ const core = createMutationTestResult ( { files : { a : fileA } } ) ;
108
+ const api = createMutationTestResult ( { files : { b : fileB } } ) ;
109
+
110
+ // Act
111
+ const result = aggregateResultsByModule ( { core, api } ) ;
112
+
113
+ // Assert
114
+ const [ mutantCore ] = result . files [ 'core/a' ] . mutants ;
115
+ const [ mutantApi ] = result . files [ 'api/b' ] . mutants ;
116
+ expect ( mutantCore . coveredBy ) . deep . eq ( [ 'core_1' ] ) ;
117
+ expect ( mutantApi . coveredBy ) . deep . eq ( [ 'api_1' , 'api_2' ] ) ;
118
+ } ) ;
119
+
120
+ it ( 'should prefix killedBy with moduleName' , ( ) => {
121
+ // Arrange
122
+ const fileA = createFileResult ( { mutants : [ createMutantResult ( { killedBy : [ '1' ] } ) ] } ) ;
123
+ const fileB = createFileResult ( { mutants : [ createMutantResult ( { killedBy : [ '1' , '2' ] } ) ] } ) ;
124
+ const core = createMutationTestResult ( { files : { a : fileA } } ) ;
125
+ const api = createMutationTestResult ( { files : { b : fileB } } ) ;
126
+
127
+ // Act
128
+ const result = aggregateResultsByModule ( { core, api } ) ;
129
+
130
+ // Assert
131
+ const [ mutantCore ] = result . files [ 'core/a' ] . mutants ;
132
+ const [ mutantApi ] = result . files [ 'api/b' ] . mutants ;
133
+ expect ( mutantCore . killedBy ) . deep . eq ( [ 'core_1' ] ) ;
134
+ expect ( mutantApi . killedBy ) . deep . eq ( [ 'api_1' , 'api_2' ] ) ;
135
+ } ) ;
136
+ } ) ;
137
+ describe ( 'tests' , ( ) => {
138
+ it ( 'should prefix test ids with moduleName' , ( ) => {
139
+ // Arrange
140
+ const fileA = createTestFile ( { tests : [ createTestDefinition ( { id : '1' } ) ] } ) ;
141
+ const fileB = createTestFile ( { tests : [ createTestDefinition ( { id : '1' } ) ] } ) ;
142
+ const core = createMutationTestResult ( { testFiles : { a : fileA } } ) ;
143
+ const api = createMutationTestResult ( { testFiles : { b : fileB } } ) ;
144
+
145
+ // Act
146
+ const result = aggregateResultsByModule ( { core, api } ) ;
147
+
148
+ // Assert
149
+ const testsCore = result . testFiles ! [ 'core/a' ] . tests ;
150
+ const testsApi = result . testFiles ! [ 'api/b' ] . tests ;
151
+ expect ( testsCore ) . lengthOf ( 1 ) ;
152
+ expect ( testsApi ) . lengthOf ( 1 ) ;
153
+ expect ( testsCore [ 0 ] . id ) . eq ( 'core_1' ) ;
154
+ expect ( testsApi [ 0 ] . id ) . eq ( 'api_1' ) ;
155
+ } ) ;
156
+ } ) ;
82
157
} ) ;
0 commit comments