@teamscale/coverage-collector 0.0.1-beta.32 → 0.0.1-beta.35

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/coverage-collector",
3
- "version": "0.0.1-beta.32",
3
+ "version": "0.0.1-beta.35",
4
4
  "description": "Collector for JavaScript code coverage information",
5
5
  "main": "dist/src/main.js",
6
6
  "bin": "dist/src/main.js",
@@ -43,6 +43,7 @@
43
43
  "@types/async": "^3.2.6",
44
44
  "@types/bunyan": "^1.8.8",
45
45
  "@types/jest": "^27.0.1",
46
+ "@types/mkdirp": "^1.0.2",
46
47
  "@types/node": "^15.0.1",
47
48
  "@types/source-map": "^0.5.7",
48
49
  "@types/tmp": "^0.2.3",
package/dist/src/main.js CHANGED
@@ -122,7 +122,8 @@ class Main {
122
122
  const logfilePath = config.log_to_file.trim();
123
123
  mkdirp_1.default.sync(path_1.default.dirname(logfilePath));
124
124
  const logLevel = config.log_level;
125
- return bunyan_1.default.createLogger({ name: "Instrumenter",
125
+ return bunyan_1.default.createLogger({
126
+ name: 'Instrumenter',
126
127
  streams: [
127
128
  {
128
129
  level: logLevel,
@@ -137,7 +138,8 @@ class Main {
137
138
  level: logLevel,
138
139
  path: logfilePath
139
140
  }
140
- ] });
141
+ ]
142
+ });
141
143
  }
142
144
  /**
143
145
  * Entry point of the Teamscale JavaScript Profiler.
@@ -1,5 +1,5 @@
1
1
  import { IDataStorage } from '../storage/DataStorage';
2
- import Logger from "bunyan";
2
+ import Logger from 'bunyan';
3
3
  /**
4
4
  * Various constants that are used to exchange data between
5
5
  * the instrumented application and the coverage collector.
@@ -133,14 +133,19 @@ class WebSocketCollectingServer {
133
133
  */
134
134
  handleCoverageMessage(session, body) {
135
135
  var _a;
136
- const bodyPattern = /(?<fileId>\S+) (?<positions>((\d+:\d+)\s+)*(\d+:\d+))/;
136
+ const bodyPattern = /(?<fileId>\S+) (?<positions>((\d+:\d+(:\d+:\d+)?\s+)*(\d+:\d+(:\d+:\d+)?)))/;
137
137
  const matches = bodyPattern.exec(body);
138
138
  if (matches === null || matches === void 0 ? void 0 : matches.groups) {
139
139
  const fileId = matches.groups.fileId;
140
140
  const positions = ((_a = matches.groups.positions) !== null && _a !== void 0 ? _a : '').split(/\s+/);
141
141
  for (const position of positions) {
142
- const [line, column] = position.split(':');
143
- session.putCoverage(fileId, Number.parseInt(line), Number.parseInt(column));
142
+ const positionParts = position.split(':');
143
+ if (positionParts.length === 2) {
144
+ session.putCoverage(fileId, Number.parseInt(positionParts[0]), Number.parseInt(positionParts[1]), Number.parseInt(positionParts[1]), Number.parseInt(positionParts[2]));
145
+ }
146
+ else if (positionParts.length === 4) {
147
+ session.putCoverage(fileId, Number.parseInt(positionParts[0]), Number.parseInt(positionParts[1]), Number.parseInt(positionParts[2]), Number.parseInt(positionParts[3]));
148
+ }
144
149
  }
145
150
  }
146
151
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Socket } from 'net';
3
3
  import { IDataStorage } from '../storage/DataStorage';
4
- import Logger from "bunyan";
4
+ import Logger from 'bunyan';
5
5
  /**
6
6
  * The session maintains the relevant information for a client.
7
7
  * One session is created for each client.
@@ -46,7 +46,7 @@ export declare class Session {
46
46
  * @param line - The line number within the bundle.
47
47
  * @param column - The column within the bundle.
48
48
  */
49
- putCoverage(fileId: string, line: number, column: number): void;
49
+ putCoverage(fileId: string, startLine: number, startColumn: number, endLine: number, endColumn: number): void;
50
50
  /**
51
51
  * Map to the original file position.
52
52
  *
@@ -54,13 +54,50 @@ class Session {
54
54
  * @param line - The line number within the bundle.
55
55
  * @param column - The column within the bundle.
56
56
  */
57
- putCoverage(fileId, line, column) {
58
- const originalPosition = this.mapToOriginal(fileId, line, column);
59
- if (originalPosition.line && originalPosition.source) {
60
- this.storage.putCoverage(this.projectId, originalPosition.source, [originalPosition.line]);
61
- }
62
- else {
63
- this.storage.signalUnmappedCoverage(this.projectId);
57
+ putCoverage(fileId, startLine, startColumn, endLine, endColumn) {
58
+ var _a, _b;
59
+ // Iterate over the lines to scan
60
+ let line = startLine;
61
+ while (line <= endLine) {
62
+ // Determine the column range to consider for this line
63
+ let scanFromColumn;
64
+ if (line === startLine) {
65
+ scanFromColumn = startColumn;
66
+ }
67
+ else {
68
+ scanFromColumn = 0;
69
+ }
70
+ let scanToColumn;
71
+ if (line === endLine) {
72
+ scanToColumn = endColumn;
73
+ }
74
+ else {
75
+ // Since we do not know the length of the different lines, we assume
76
+ // all to end in the lager of `endColumn` and `startColumn`.
77
+ // A better estimate (or the correct value) is supposed to be implemented
78
+ // in context of TS-30077.
79
+ scanToColumn = Math.max(endColumn, startColumn);
80
+ }
81
+ let column = scanFromColumn;
82
+ let lastCoveredLine = -1;
83
+ while (column <= scanToColumn) {
84
+ const originalPosition = this.mapToOriginal(fileId, line, column);
85
+ if (originalPosition.line && originalPosition.source) {
86
+ if (lastCoveredLine !== originalPosition.line) {
87
+ this.storage.putCoverage(this.projectId, originalPosition.source, [originalPosition.line]);
88
+ lastCoveredLine = originalPosition.line;
89
+ }
90
+ }
91
+ else {
92
+ this.storage.signalUnmappedCoverage(this.projectId);
93
+ }
94
+ // Step to the next column to map back to the original.
95
+ // `originalPosition.name` is the token on the position, that is, if it is present
96
+ // we increment the column by its length.
97
+ column = column + Math.max(1, (_b = (_a = originalPosition.name) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 1);
98
+ }
99
+ // And the next line
100
+ line++;
64
101
  }
65
102
  }
66
103
  /**
@@ -1,4 +1,4 @@
1
- import Logger from "bunyan";
1
+ import Logger from 'bunyan';
2
2
  /**
3
3
  * Lines covered for the specified file.
4
4
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/coverage-collector",
3
- "version": "0.0.1-beta.32",
3
+ "version": "0.0.1-beta.35",
4
4
  "description": "Collector for JavaScript code coverage information",
5
5
  "main": "dist/src/main.js",
6
6
  "bin": "dist/src/main.js",
@@ -43,6 +43,7 @@
43
43
  "@types/async": "^3.2.6",
44
44
  "@types/bunyan": "^1.8.8",
45
45
  "@types/jest": "^27.0.1",
46
+ "@types/mkdirp": "^1.0.2",
46
47
  "@types/node": "^15.0.1",
47
48
  "@types/source-map": "^0.5.7",
48
49
  "@types/tmp": "^0.2.3",