@teamscale/coverage-collector 0.0.1-alpha.20 → 0.0.1-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +4 -8
- package/dist/package.json +19 -8
- package/dist/src/main.d.ts +4 -2
- package/dist/src/main.js +169 -38
- package/dist/src/receiver/CollectingServer.js +34 -10
- package/dist/src/receiver/Session.js +29 -6
- package/dist/src/storage/DataStorage.d.ts +4 -0
- package/dist/src/storage/DataStorage.js +38 -10
- package/dist/src/utils/QueryParameters.d.ts +9 -0
- package/dist/src/utils/QueryParameters.js +19 -0
- package/package.json +15 -8
- package/dist/main.d.ts +0 -31
- package/dist/main.js +0 -112
- package/dist/receiver/CollectingServer.d.ts +0 -63
- package/dist/receiver/CollectingServer.js +0 -120
- package/dist/receiver/Session.d.ts +0 -70
- package/dist/receiver/Session.js +0 -86
- package/dist/storage/CoveragePersiterBase.d.ts +0 -6
- package/dist/storage/CoveragePersiterBase.js +0 -10
- package/dist/storage/DataStorage.d.ts +0 -134
- package/dist/storage/DataStorage.js +0 -130
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.CoveragePersisterBase = void 0;
|
|
4
|
-
const common_qualities_1 = require('@cqse/commons');
|
|
5
|
-
class CoveragePersisterBase {
|
|
6
|
-
constructor(storage) {
|
|
7
|
-
this._storage = common_qualities_1.Contract.requireDefined(storage);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.CoveragePersisterBase = CoveragePersisterBase;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'winston';
|
|
2
|
-
/**
|
|
3
|
-
* Lines covered for the specified file.
|
|
4
|
-
*/
|
|
5
|
-
export declare type FileCoverage = {
|
|
6
|
-
/** Name of the file in the origin */
|
|
7
|
-
sourceFile: string;
|
|
8
|
-
/** Lines covered */
|
|
9
|
-
coveredLines: Set<number>;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Storage interface for reading information.
|
|
13
|
-
*/
|
|
14
|
-
export interface IReadableStorage {
|
|
15
|
-
/**
|
|
16
|
-
* The list of projects the collector received coverage information for.
|
|
17
|
-
*/
|
|
18
|
-
getProjects(): string[];
|
|
19
|
-
/**
|
|
20
|
-
* Retrieve the projects' coverage by source file.
|
|
21
|
-
*/
|
|
22
|
-
getCoverageBySourceFile(project: string): IterableIterator<FileCoverage> | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Write the coverage to the specified file.
|
|
25
|
-
*
|
|
26
|
-
* @param filePath - Full path of the file to write the coverage to.
|
|
27
|
-
*/
|
|
28
|
-
dumpToSimpleCoverageFile(filePath: string): void;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Storage interface for writing information.
|
|
32
|
-
*/
|
|
33
|
-
export interface IWriteableStorage {
|
|
34
|
-
/**
|
|
35
|
-
* Add coverage information to the storage.
|
|
36
|
-
*
|
|
37
|
-
* @param project - The project to add the information to.
|
|
38
|
-
* @param sourceFilePath - The file for that lines are covered.
|
|
39
|
-
* @param coveredOriginalLines - The covered lines.
|
|
40
|
-
*/
|
|
41
|
-
putCoverage(project: string, sourceFilePath: string, coveredOriginalLines: number[]): void;
|
|
42
|
-
/**
|
|
43
|
-
* Signals that we have received coverage information
|
|
44
|
-
* for that no mapping based on sourcemaps was possible.
|
|
45
|
-
*
|
|
46
|
-
* @param project - The project to add the information to.
|
|
47
|
-
*/
|
|
48
|
-
signalUnmappedCoverage(project: string): void;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Union of write and read interface.
|
|
52
|
-
*/
|
|
53
|
-
export interface IDataStorage extends IReadableStorage, IWriteableStorage {
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* The coverage information received for one particular project.
|
|
57
|
-
*/
|
|
58
|
-
export declare class ProjectCoverage {
|
|
59
|
-
/**
|
|
60
|
-
* The identifier of the project.
|
|
61
|
-
*/
|
|
62
|
-
private readonly projectId;
|
|
63
|
-
/**
|
|
64
|
-
* The coverage.
|
|
65
|
-
*/
|
|
66
|
-
private readonly coveredLinesByFile;
|
|
67
|
-
/**
|
|
68
|
-
* Constructor.
|
|
69
|
-
*
|
|
70
|
-
* @param projectId - The identifier of the project to collect the coverage for.
|
|
71
|
-
*/
|
|
72
|
-
constructor(projectId: string);
|
|
73
|
-
/**
|
|
74
|
-
* Put coverage for a single line to the storage.
|
|
75
|
-
*
|
|
76
|
-
* @param sourceFile - The file in that the line is covered.
|
|
77
|
-
* @param line - The line number.
|
|
78
|
-
*/
|
|
79
|
-
putLine(sourceFile: string, line: number): void;
|
|
80
|
-
/**
|
|
81
|
-
* Returns an iterator over the projects' coverage.
|
|
82
|
-
*/
|
|
83
|
-
getCoverage(): IterableIterator<FileCoverage>;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* The data storage which retrieves coverage information.
|
|
87
|
-
*/
|
|
88
|
-
export declare class DataStorage implements IDataStorage {
|
|
89
|
-
/**
|
|
90
|
-
* Coverage information by project.
|
|
91
|
-
*/
|
|
92
|
-
private readonly coverageByProject;
|
|
93
|
-
/**
|
|
94
|
-
* Logger to use.
|
|
95
|
-
*/
|
|
96
|
-
private readonly logger;
|
|
97
|
-
/**
|
|
98
|
-
* Constructs the data storage.
|
|
99
|
-
*
|
|
100
|
-
* @param logger - The logger to use.
|
|
101
|
-
*/
|
|
102
|
-
constructor(logger: Logger);
|
|
103
|
-
/**
|
|
104
|
-
* Put coverage into the storage.
|
|
105
|
-
*
|
|
106
|
-
* @param project - The project to add it to.
|
|
107
|
-
* @param sourceFilePath - The covered file.
|
|
108
|
-
* @param coveredOriginalLines - The lines covered in the file.
|
|
109
|
-
*/
|
|
110
|
-
putCoverage(project: string, sourceFilePath: string, coveredOriginalLines: number[]): void;
|
|
111
|
-
/**
|
|
112
|
-
* Normalize the source file names provided by the Web browsers / from the
|
|
113
|
-
* instrumentation such that they can be matched to the original source code by Teamscale.
|
|
114
|
-
*
|
|
115
|
-
* @param sourceFile - The file name to normalize, produced by the instrumenter.
|
|
116
|
-
*/
|
|
117
|
-
private normalizeSourceFileName;
|
|
118
|
-
/**
|
|
119
|
-
* {@inheritDoc IWriteableStorage.signalUnmappedCoverage}
|
|
120
|
-
*/
|
|
121
|
-
signalUnmappedCoverage(project: string): void;
|
|
122
|
-
/**
|
|
123
|
-
* {@inheritDoc IReadableStorage.getCoverageBySourceFile}
|
|
124
|
-
*/
|
|
125
|
-
getCoverageBySourceFile(project: string): IterableIterator<FileCoverage> | undefined;
|
|
126
|
-
/**
|
|
127
|
-
* {@inheritDoc IReadableStorage.writeToSimpleCoverageFile}
|
|
128
|
-
*/
|
|
129
|
-
dumpToSimpleCoverageFile(filePath: string): number;
|
|
130
|
-
/**
|
|
131
|
-
* {@inheritDoc IReadableStorage.getProjects}
|
|
132
|
-
*/
|
|
133
|
-
getProjects(): string[];
|
|
134
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { Contract, removePrefix } from '@cqse/commons';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
/**
|
|
4
|
-
* The coverage information received for one particular project.
|
|
5
|
-
*/
|
|
6
|
-
export class ProjectCoverage {
|
|
7
|
-
/**
|
|
8
|
-
* Constructor.
|
|
9
|
-
*
|
|
10
|
-
* @param projectId - The identifier of the project to collect the coverage for.
|
|
11
|
-
*/
|
|
12
|
-
constructor(projectId) {
|
|
13
|
-
this.projectId = Contract.requireDefined(projectId);
|
|
14
|
-
this.coveredLinesByFile = new Map();
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Put coverage for a single line to the storage.
|
|
18
|
-
*
|
|
19
|
-
* @param sourceFile - The file in that the line is covered.
|
|
20
|
-
* @param line - The line number.
|
|
21
|
-
*/
|
|
22
|
-
putLine(sourceFile, line) {
|
|
23
|
-
let targetSet = this.coveredLinesByFile.get(sourceFile);
|
|
24
|
-
if (!targetSet) {
|
|
25
|
-
targetSet = new Set();
|
|
26
|
-
this.coveredLinesByFile.set(sourceFile, targetSet);
|
|
27
|
-
}
|
|
28
|
-
targetSet.add(line);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Returns an iterator over the projects' coverage.
|
|
32
|
-
*/
|
|
33
|
-
getCoverage() {
|
|
34
|
-
function* iterate(iterable, transform) {
|
|
35
|
-
for (const e of iterable) {
|
|
36
|
-
yield transform(e);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return iterate(this.coveredLinesByFile.entries(), ([file, lines]) => {
|
|
40
|
-
return {
|
|
41
|
-
sourceFile: file,
|
|
42
|
-
coveredLines: lines
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* The data storage which retrieves coverage information.
|
|
49
|
-
*/
|
|
50
|
-
export class DataStorage {
|
|
51
|
-
/**
|
|
52
|
-
* Constructs the data storage.
|
|
53
|
-
*
|
|
54
|
-
* @param logger - The logger to use.
|
|
55
|
-
*/
|
|
56
|
-
constructor(logger) {
|
|
57
|
-
this.coverageByProject = new Map();
|
|
58
|
-
this.logger = Contract.requireDefined(logger);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Put coverage into the storage.
|
|
62
|
-
*
|
|
63
|
-
* @param project - The project to add it to.
|
|
64
|
-
* @param sourceFilePath - The covered file.
|
|
65
|
-
* @param coveredOriginalLines - The lines covered in the file.
|
|
66
|
-
*/
|
|
67
|
-
putCoverage(project, sourceFilePath, coveredOriginalLines) {
|
|
68
|
-
const uniformPath = this.normalizeSourceFileName(sourceFilePath);
|
|
69
|
-
let projectCoverage = this.coverageByProject.get(project);
|
|
70
|
-
if (!projectCoverage) {
|
|
71
|
-
projectCoverage = new ProjectCoverage(project);
|
|
72
|
-
this.coverageByProject.set(project, projectCoverage);
|
|
73
|
-
}
|
|
74
|
-
coveredOriginalLines.forEach(line => projectCoverage === null || projectCoverage === void 0 ? void 0 : projectCoverage.putLine(sourceFilePath, line));
|
|
75
|
-
this.logger.debug(`Mapped Coverage: ${project} ${uniformPath} ${coveredOriginalLines}`);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Normalize the source file names provided by the Web browsers / from the
|
|
79
|
-
* instrumentation such that they can be matched to the original source code by Teamscale.
|
|
80
|
-
*
|
|
81
|
-
* @param sourceFile - The file name to normalize, produced by the instrumenter.
|
|
82
|
-
*/
|
|
83
|
-
normalizeSourceFileName(sourceFile) {
|
|
84
|
-
return removePrefix('webpack:///', sourceFile.replace('\\', '/'));
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* {@inheritDoc IWriteableStorage.signalUnmappedCoverage}
|
|
88
|
-
*/
|
|
89
|
-
signalUnmappedCoverage(project) {
|
|
90
|
-
// Currently not used.
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* {@inheritDoc IReadableStorage.getCoverageBySourceFile}
|
|
94
|
-
*/
|
|
95
|
-
getCoverageBySourceFile(project) {
|
|
96
|
-
const projectCoverage = this.coverageByProject.get(project);
|
|
97
|
-
return projectCoverage === null || projectCoverage === void 0 ? void 0 : projectCoverage.getCoverage();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* {@inheritDoc IReadableStorage.writeToSimpleCoverageFile}
|
|
101
|
-
*/
|
|
102
|
-
dumpToSimpleCoverageFile(filePath) {
|
|
103
|
-
const toSimpleCoverage = () => {
|
|
104
|
-
const result = [];
|
|
105
|
-
Contract.require(this.getProjects().length < 2, 'Only one project supported to be handled in parallel.');
|
|
106
|
-
for (const project of this.getProjects()) {
|
|
107
|
-
const projectCoverage = this.getCoverageBySourceFile(project);
|
|
108
|
-
if (!projectCoverage) {
|
|
109
|
-
return [0, ''];
|
|
110
|
-
}
|
|
111
|
-
for (const entry of projectCoverage) {
|
|
112
|
-
result.push(this.normalizeSourceFileName(entry.sourceFile));
|
|
113
|
-
for (const lineNo of entry.coveredLines) {
|
|
114
|
-
result.push(String(lineNo));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return [result.length, result.join('\n')];
|
|
119
|
-
};
|
|
120
|
-
const [lines, content] = toSimpleCoverage();
|
|
121
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
122
|
-
return lines;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* {@inheritDoc IReadableStorage.getProjects}
|
|
126
|
-
*/
|
|
127
|
-
getProjects() {
|
|
128
|
-
return Array.from(this.coverageByProject.keys());
|
|
129
|
-
}
|
|
130
|
-
}
|