1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.TestSelectionResult = void 0;
|
4 | const util_1 = require("@stryker-mutator/util");
|
5 | const SourceFile_1 = require("./SourceFile");
|
6 | var TestSelectionResult;
|
7 | (function (TestSelectionResult) {
|
8 | TestSelectionResult[TestSelectionResult["Failed"] = 0] = "Failed";
|
9 | TestSelectionResult[TestSelectionResult["FailedButAlreadyReported"] = 1] = "FailedButAlreadyReported";
|
10 | TestSelectionResult[TestSelectionResult["Success"] = 2] = "Success";
|
11 | })(TestSelectionResult = exports.TestSelectionResult || (exports.TestSelectionResult = {}));
|
12 | class TestFilter {
|
13 | constructor() {
|
14 | this.timeSpentScopedTests = 0;
|
15 | this.runAllTests = false;
|
16 | this.selectedTests = [];
|
17 | }
|
18 | selectAllTests(runResult) {
|
19 | this.timeSpentScopedTests = runResult.tests.reduce((time, test) => time + test.timeSpentMs, this.timeSpentScopedTests);
|
20 | this.runAllTests = true;
|
21 | }
|
22 | selectTest(testResult, index) {
|
23 | this.selectedTests.push({ id: index, name: testResult.name });
|
24 | this.timeSpentScopedTests += testResult.timeSpentMs;
|
25 | this.runAllTests = false;
|
26 | }
|
27 | }
|
28 | class TestableMutant {
|
29 | constructor(id, mutant, sourceFile) {
|
30 | this.id = id;
|
31 | this.mutant = mutant;
|
32 | this.sourceFile = sourceFile;
|
33 | this.specsRan = [];
|
34 | this.filter = new TestFilter();
|
35 | this.testSelectionResult = TestSelectionResult.Success;
|
36 | }
|
37 | get selectedTests() {
|
38 | return this.filter.selectedTests;
|
39 | }
|
40 | get runAllTests() {
|
41 | return this.filter.runAllTests;
|
42 | }
|
43 | get timeSpentScopedTests() {
|
44 | return this.filter.timeSpentScopedTests;
|
45 | }
|
46 | get fileName() {
|
47 | return this.mutant.fileName;
|
48 | }
|
49 | get mutatorName() {
|
50 | return this.mutant.mutatorName;
|
51 | }
|
52 | get range() {
|
53 | return this.mutant.range;
|
54 | }
|
55 | get replacement() {
|
56 | return this.mutant.replacement;
|
57 | }
|
58 | get location() {
|
59 | if (!this._location) {
|
60 | this._location = this.sourceFile.getLocation(this.range);
|
61 | }
|
62 | return this._location;
|
63 | }
|
64 | get mutatedCode() {
|
65 | return this.sourceFile.content.substr(0, this.range[0]) + this.replacement + this.sourceFile.content.substr(this.range[1]);
|
66 | }
|
67 | get originalCode() {
|
68 | return this.sourceFile.content;
|
69 | }
|
70 | selectAllTests(runResult, testSelectionResult) {
|
71 | this.filter.selectAllTests(runResult);
|
72 | this.testSelectionResult = testSelectionResult;
|
73 | }
|
74 | selectTest(testResult, index) {
|
75 | this.filter.selectTest(testResult, index);
|
76 | }
|
77 | get originalLines() {
|
78 | const [startIndex, endIndex] = this.getMutationLineIndexes();
|
79 | return this.sourceFile.content.substring(startIndex, endIndex);
|
80 | }
|
81 | get mutatedLines() {
|
82 | const [startIndex, endIndex] = this.getMutationLineIndexes();
|
83 | return (this.sourceFile.content.substring(startIndex, this.mutant.range[0]) +
|
84 | this.mutant.replacement +
|
85 | this.sourceFile.content.substring(this.mutant.range[1], endIndex));
|
86 | }
|
87 | getMutationLineIndexes() {
|
88 | let startIndexLines = this.mutant.range[0];
|
89 | let endIndexLines = this.mutant.range[1];
|
90 | while (startIndexLines > 0 && !SourceFile_1.isLineBreak(this.originalCode.charCodeAt(startIndexLines - 1))) {
|
91 | startIndexLines--;
|
92 | }
|
93 | while (endIndexLines < this.sourceFile.content.length && !SourceFile_1.isLineBreak(this.originalCode.charCodeAt(endIndexLines))) {
|
94 | endIndexLines++;
|
95 | }
|
96 | return [startIndexLines, endIndexLines];
|
97 | }
|
98 | createResult(status, testsRan) {
|
99 | return util_1.deepFreeze({
|
100 | id: this.id,
|
101 | location: this.location,
|
102 | mutatedLines: this.mutatedLines,
|
103 | mutatorName: this.mutatorName,
|
104 | originalLines: this.originalLines,
|
105 | range: this.range,
|
106 | replacement: this.replacement,
|
107 | sourceFilePath: this.fileName,
|
108 | status,
|
109 | testsRan,
|
110 | });
|
111 | }
|
112 | toString() {
|
113 | return `${this.mutant.mutatorName}: (${this.replacement}) file://${this.fileName}:${this.location.start.line + 1}:${this.location.start.column}`;
|
114 | }
|
115 | }
|
116 | exports.default = TestableMutant;
|
117 |
|
\ | No newline at end of file |