@teamscale/coverage-collector 0.0.1-beta.7 → 0.1.0-beta.2

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/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+
package/README.md CHANGED
@@ -9,7 +9,7 @@ files in the [Teamscale Simple Coverage Format](https://docs.teamscale.com/refer
9
9
  The Teamscale JavaScript Profiler consists of this Coverage Collector and the
10
10
  [JavaScript Instrumenter](https://www.npmjs.com/package/@teamscale/javascript-instrumenter).
11
11
  More details on using them (in combination) can be found
12
- on the projects' [Github page](https://github.com/cqse/teamscale-javascript-profiler/).
12
+ in the [Teamscale Documentation](https://docs.teamscale.com/howto/recording-test-coverage-for-javascript/).
13
13
 
14
14
  The JavaScript Coverage Collector starts a server process that listens for
15
15
  code coverage information from manually or automatically exercised (tested)
@@ -19,12 +19,12 @@ information back to the original source code.
19
19
  ## Building
20
20
 
21
21
  The Collector is written in TypeScript/JavaScript. For building and running it,
22
- NodeJs (>= v14) and Yarn are needed as prerequisites.
22
+ NodeJs (>= v16) and pnpm are needed as prerequisites.
23
23
 
24
24
  ```
25
- yarn clean
26
- yarn install
27
- yarn build
25
+ pnpm clean
26
+ pnpm install
27
+ pnpm build
28
28
  ```
29
29
 
30
30
  ## Running the Collector
@@ -49,8 +49,3 @@ for example, by setting a corresponding environment variable.
49
49
  export NODE_OPTIONS="$NODE_OPTIONS --max-old-space-size=8192"
50
50
  ```
51
51
 
52
- ## Publishing
53
-
54
- The list of files to publish is defined by the `files` attribute in `package.json`.
55
- The actual files packed by npm can be listed by running `npx npm-packlist`.
56
-
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/coverage-collector",
3
- "version": "0.0.1-beta.7",
3
+ "version": "0.1.0-beta.2",
4
4
  "description": "Collector for JavaScript code coverage information",
5
5
  "main": "dist/src/main.js",
6
6
  "bin": "dist/src/main.js",
@@ -12,46 +12,51 @@
12
12
  "url": "https://github.com/cqse/teamscale-javascript-profiler.git"
13
13
  },
14
14
  "scripts": {
15
+ "prepublishOnly": "pnpm clean && pnpm build",
15
16
  "clean": "rimraf dist tsconfig.tsbuildinfo",
16
17
  "build": "tsc",
17
18
  "collector": "node dist/src/main.js",
18
- "test": "yarn build && NODE_OPTIONS='--experimental-vm-modules' jest --forceExit --coverage --silent=true --detectOpenHandles"
19
+ "test": "pnpm build && NODE_OPTIONS='--experimental-vm-modules' jest --coverage --silent=true --detectOpenHandles --forceExit"
19
20
  },
20
21
  "files": [
21
22
  "dist/**/*"
22
23
  ],
23
24
  "dependencies": {
24
- "@cqse/commons": "^0.0.1-beta.1",
25
+ "@cqse/commons": "0.0.1-beta.59",
25
26
  "argparse": "^2.0.1",
26
- "async": "^3.2.0",
27
- "axios": "^0.24.0",
28
- "dotenv": "^14.1.0",
27
+ "async": "^3.2.4",
28
+ "axios": "^1.6.2",
29
+ "bunyan": "^1.8.15",
30
+ "date-and-time": "^3.0.3",
31
+ "dotenv": "^16.3.1",
32
+ "express": "^4.18.2",
29
33
  "form-data": "^4.0.0",
30
- "rxjs": "^7.1.0",
31
- "source-map": "^0.7.3",
34
+ "mkdirp": "^3.0.1",
35
+ "rxjs": "^7.8.1",
36
+ "source-map": "^0.7.4",
32
37
  "tmp": "^0.2.1",
33
38
  "typescript-optional": "^2.0.1",
34
- "winston": "^3.3.3",
35
- "ws": "^7.4.5"
39
+ "ws": "^8.14.2"
36
40
  },
37
41
  "devDependencies": {
38
- "@babel/core": "^7.14.0",
39
- "@babel/preset-env": "^7.14.1",
40
- "@types/argparse": "^2.0.5",
41
- "@types/async": "^3.2.6",
42
- "@types/jest": "^27.0.1",
43
- "@types/node": "^15.0.1",
44
- "@types/source-map": "^0.5.7",
45
- "@types/tmp": "^0.2.3",
46
- "@types/winston": "^2.4.4",
47
- "@types/ws": "^7.4.2",
48
- "babel-jest": "^27.2.0",
49
- "esbuild": "^0.13.4",
50
- "jest": "^27.2.0",
51
- "rimraf": "^3.0.2",
52
- "ts-jest": "^27.0.5",
53
- "ts-node": "^10.2.1",
54
- "typescript": "^4.4.3"
42
+ "@babel/core": "^7.23.2",
43
+ "@babel/preset-env": "^7.23.2",
44
+ "@types/argparse": "^2.0.12",
45
+ "@types/async": "^3.2.22",
46
+ "@types/bunyan": "^1.8.10",
47
+ "@types/express": "^4.17.20",
48
+ "@types/jest": "^29.5.6",
49
+ "@types/node": "^20.8.6",
50
+ "@types/tmp": "^0.2.4",
51
+ "@types/ws": "^8.5.7",
52
+ "babel-jest": "^29.7.0",
53
+ "esbuild": "^0.19.5",
54
+ "jest": "^29.7.0",
55
+ "mockttp": "^3.9.4",
56
+ "rimraf": "^5.0.5",
57
+ "ts-jest": "^29.1.1",
58
+ "ts-node": "^10.9.1",
59
+ "typescript": "^5.2.2"
55
60
  },
56
61
  "publishConfig": {
57
62
  "access": "public"
@@ -0,0 +1,39 @@
1
+ import 'dotenv/config';
2
+ import { ConfigParameters } from './utils/ConfigParameters';
3
+ /**
4
+ * The main class of the Teamscale JavaScript Collector.
5
+ * Used to start the collector with a given configuration.
6
+ */
7
+ export declare class App {
8
+ /**
9
+ * Parse the given command line arguments into a corresponding options object.
10
+ */
11
+ private static parseArguments;
12
+ /**
13
+ * Construct the logger.
14
+ */
15
+ private static buildLogger;
16
+ /**
17
+ * Entry point of the Teamscale JavaScript Profiler.
18
+ */
19
+ static run(): void;
20
+ /**
21
+ * Run the collector with the given configuration options.
22
+ *
23
+ * @param config - The configuration options to run the collector with.
24
+ */
25
+ static runWithConfig(config: ConfigParameters): {
26
+ stop: () => Promise<void>;
27
+ };
28
+ /**
29
+ * Start a timer for dumping the data, depending on the configuration.
30
+ *
31
+ * @param config - The config that determines whether to do the timed dump or not.
32
+ * @param storage - The storage with the information to dump.
33
+ * @param logger - The logger to use.
34
+ */
35
+ private static maybeStartDumpTimer;
36
+ private static dumpCoverage;
37
+ private static uploadCoverage;
38
+ private static startControlServer;
39
+ }
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.App = void 0;
30
+ const bunyan_1 = __importDefault(require("bunyan"));
31
+ const DataStorage_1 = require("./storage/DataStorage");
32
+ const CollectingServer_1 = require("./receiver/CollectingServer");
33
+ require("dotenv/config");
34
+ const fs = __importStar(require("fs"));
35
+ const ConfigParameters_1 = require("./utils/ConfigParameters");
36
+ const mkdirp_1 = require("mkdirp");
37
+ const path_1 = __importDefault(require("path"));
38
+ const StdConsoleLogger_1 = require("./utils/StdConsoleLogger");
39
+ const PrettyFileLogger_1 = require("./utils/PrettyFileLogger");
40
+ const express_1 = __importDefault(require("express"));
41
+ const TeamscaleUpload_1 = require("./upload/TeamscaleUpload");
42
+ const CommonUpload_1 = require("./upload/CommonUpload");
43
+ const ArtifactoryUpload_1 = require("./upload/ArtifactoryUpload");
44
+ /**
45
+ * The main class of the Teamscale JavaScript Collector.
46
+ * Used to start the collector with a given configuration.
47
+ */
48
+ class App {
49
+ /**
50
+ * Parse the given command line arguments into a corresponding options object.
51
+ */
52
+ static parseArguments() {
53
+ const parser = (0, ConfigParameters_1.buildParameterParser)();
54
+ return parser.parse_args();
55
+ }
56
+ /**
57
+ * Construct the logger.
58
+ */
59
+ static buildLogger(config) {
60
+ const logfilePath = config.log_to_file.trim();
61
+ mkdirp_1.mkdirp.sync(path_1.default.dirname(logfilePath));
62
+ const logLevel = config.log_level;
63
+ const logger = bunyan_1.default.createLogger({
64
+ name: 'Collector',
65
+ streams: [
66
+ // console output
67
+ { level: logLevel, stream: new StdConsoleLogger_1.StdConsoleLogger(), type: 'raw' },
68
+ // default log file
69
+ { level: logLevel, stream: new PrettyFileLogger_1.PrettyFileLogger(fs.createWriteStream(logfilePath)), type: 'raw' }
70
+ ]
71
+ });
72
+ // If the given flag is set, we also log with a JSON-like format
73
+ if (config.json_log) {
74
+ logger.addStream({ level: logLevel, path: `${logfilePath}.json` });
75
+ }
76
+ return logger;
77
+ }
78
+ /**
79
+ * Entry point of the Teamscale JavaScript Profiler.
80
+ */
81
+ static run() {
82
+ // Parse the command line arguments
83
+ const config = this.parseArguments();
84
+ App.runWithConfig(config);
85
+ }
86
+ /**
87
+ * Run the collector with the given configuration options.
88
+ *
89
+ * @param config - The configuration options to run the collector with.
90
+ */
91
+ static runWithConfig(config) {
92
+ // Build the logger
93
+ const logger = this.buildLogger(config);
94
+ logger.info(`Starting collector in working directory "${process.cwd()}".`);
95
+ logger.info(`Logging "${config.log_level}" to "${config.log_to_file}".`);
96
+ // Prepare the storage and the server
97
+ const storage = new DataStorage_1.DataStorage(logger);
98
+ const server = new CollectingServer_1.WebSocketCollectingServer(config.port, storage, logger);
99
+ // Enable the remote control API if configured
100
+ const controlServerState = this.startControlServer(config, storage, logger);
101
+ // Start the server socket.
102
+ // ATTENTION: The server is executed asynchronously
103
+ const serverState = server.start();
104
+ // Optionally, start a timer that dumps the coverage after a N seconds
105
+ const timerState = this.maybeStartDumpTimer(config, storage, logger);
106
+ // Say bye bye on CTRL+C and exit the process
107
+ process.on('SIGINT', async () => {
108
+ // ... and do a final dump before.
109
+ await this.dumpCoverage(config, storage, logger);
110
+ logger.info('Bye bye.');
111
+ process.exit();
112
+ });
113
+ return {
114
+ async stop() {
115
+ logger.info('Stopping the collector.');
116
+ timerState.stop();
117
+ await controlServerState.stop();
118
+ serverState.stop();
119
+ }
120
+ };
121
+ }
122
+ /**
123
+ * Start a timer for dumping the data, depending on the configuration.
124
+ *
125
+ * @param config - The config that determines whether to do the timed dump or not.
126
+ * @param storage - The storage with the information to dump.
127
+ * @param logger - The logger to use.
128
+ */
129
+ static maybeStartDumpTimer(config, storage, logger) {
130
+ if (config.dump_after_mins > 0) {
131
+ logger.info(`Will dump coverage information every ${config.dump_after_mins} minute(s).`);
132
+ const timer = setInterval(async () => {
133
+ await this.dumpCoverage(config, storage, logger);
134
+ }, config.dump_after_mins * 1000 * 60);
135
+ process.on('SIGINT', () => {
136
+ // Stop the timed file dump
137
+ if (timer) {
138
+ clearInterval(timer);
139
+ }
140
+ });
141
+ return {
142
+ stop: () => clearInterval(timer)
143
+ };
144
+ }
145
+ return {
146
+ stop() {
147
+ // no timer to stop yet
148
+ }
149
+ };
150
+ }
151
+ static async dumpCoverage(config, storage, logger) {
152
+ try {
153
+ // 1. Write coverage to a file
154
+ const [coverageFile, lines] = storage.dumpToSimpleCoverageFile(config.dump_to_folder, new Date());
155
+ logger.info(`Dumped ${lines} lines of coverage to ${coverageFile}.`);
156
+ // 2. Upload to Teamscale or Artifactory if configured
157
+ if (config.teamscale_server_url || config.artifactory_server_url) {
158
+ await this.uploadCoverage(config, coverageFile, lines, logger);
159
+ }
160
+ }
161
+ catch (e) {
162
+ if (e instanceof CommonUpload_1.UploadError) {
163
+ logger.error(`Coverage upload failed. The coverage files on disk (inside the folder "${config.dump_to_folder}") were not deleted.
164
+ You can still upload them manually.`, e);
165
+ }
166
+ else {
167
+ logger.error('Coverage dump failed.', e);
168
+ }
169
+ }
170
+ }
171
+ static async uploadCoverage(config, coverageFile, lines, logger) {
172
+ if (config.teamscale_server_url) {
173
+ await (0, TeamscaleUpload_1.uploadToTeamscale)(config, logger, coverageFile, lines);
174
+ }
175
+ if (config.artifactory_server_url) {
176
+ await (0, ArtifactoryUpload_1.uploadToArtifactory)(config, logger, coverageFile, lines);
177
+ }
178
+ // Delete coverage if upload was successful and keeping coverage files on disk was not configure by the user
179
+ if (!config.keep_coverage_files) {
180
+ fs.unlinkSync(coverageFile);
181
+ }
182
+ }
183
+ static startControlServer(config, storage, logger) {
184
+ if (!config.enable_control_port) {
185
+ return {
186
+ async stop() {
187
+ // nothing to stop in this case
188
+ }
189
+ };
190
+ }
191
+ const controlServer = (0, express_1.default)();
192
+ controlServer.use(express_1.default.text({}));
193
+ const serverSocket = controlServer.listen(config.enable_control_port);
194
+ controlServer.put('/partition', (request, response) => {
195
+ const targetPartition = request.body.trim();
196
+ config.teamscale_partition = targetPartition;
197
+ logger.info(`Switched the target partition to '${targetPartition}' via the control API.`);
198
+ response.sendStatus(200);
199
+ });
200
+ controlServer.post('/dump', async (request, response) => {
201
+ logger.info('Dumping coverage requested via the control API.');
202
+ await this.dumpCoverage(config, storage, logger);
203
+ response.sendStatus(200);
204
+ });
205
+ controlServer.put('/project', async (request, response) => {
206
+ const targetProject = request.body.trim();
207
+ config.teamscale_project = targetProject;
208
+ logger.info(`Switching the target project to '${targetProject}' via the control API.`);
209
+ response.sendStatus(200);
210
+ });
211
+ controlServer.put('/revision', async (request, response) => {
212
+ const targetRevision = request.body.trim();
213
+ config.teamscale_revision = targetRevision;
214
+ logger.info(`Switching the target revision to '${targetRevision}' via the control API.`);
215
+ response.sendStatus(200);
216
+ });
217
+ controlServer.put('/commit', async (request, response) => {
218
+ const targetCommit = request.body.trim();
219
+ config.teamscale_commit = targetCommit;
220
+ logger.info(`Switching the target commit to '${targetCommit}' via the control API.`);
221
+ response.sendStatus(200);
222
+ });
223
+ controlServer.put('/message', async (request, response) => {
224
+ const uploadMessage = request.body.trim();
225
+ config.teamscale_message = uploadMessage;
226
+ logger.info(`Switching the upload message to '${uploadMessage}' via the control API.`);
227
+ response.sendStatus(200);
228
+ });
229
+ controlServer.post('/reset', async (request, response) => {
230
+ storage.discardCollectedCoverage();
231
+ logger.info(`Discarding collected coverage information as requested via the control API.`);
232
+ response.sendStatus(200);
233
+ });
234
+ logger.info(`Control server enabled at port ${config.enable_control_port}`);
235
+ return {
236
+ async stop() {
237
+ return new Promise(resolve => {
238
+ serverSocket.close(() => resolve());
239
+ });
240
+ }
241
+ };
242
+ }
243
+ }
244
+ exports.App = App;
@@ -1,33 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import 'dotenv/config';
3
- /**
4
- * The main class of the Teamscale JavaScript Collector.
5
- * Used to start the collector for with a given configuration.
6
- */
7
- export declare class Main {
8
- /**
9
- * Construct the object for parsing the command line arguments.
10
- */
11
- private static buildParser;
12
- /**
13
- * Parse the given command line arguments into a corresponding options object.
14
- */
15
- private static parseArguments;
16
- /**
17
- * Construct the logger.
18
- */
19
- private static buildLogger;
20
- /**
21
- * Entry point of the Teamscale JavaScript Profiler.
22
- */
23
- static run(): void;
24
- /**
25
- * Start a timer for dumping the data, depending on the configuration.
26
- *
27
- * @param config - The config that determines whether to do the timed dump or not.
28
- * @param storage - The storage with the information to dump.
29
- * @param logger - The logger to use.
30
- */
31
- private static maybeStartDumpTimer;
32
- private static dumpCoverage;
33
- }
2
+ export {};