Skip to content

Commit

Permalink
Merge pull request #150 from cqse/fix_relative_collector
Browse files Browse the repository at this point in the history
Fix relative collector
  • Loading branch information
stahlbauer committed Mar 15, 2024
2 parents 3ebb8fb + 2c0625f commit 4c334c4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
4 changes: 3 additions & 1 deletion packages/teamscale-javascript-instrumenter/CHANGELOG.md
Expand Up @@ -2,9 +2,11 @@ We use [Semantic Versioning](https://semver.org/).

# New Release

- [fix] `--relative-collector` option was not parsed correctly.

# 0.1.0-beta.6

- [feature] Add `--collector-pattern` to support Kubernetes deployments of the collector.
- [feature] Add `--relative-collector` to support Kubernetes deployments of the collector.

# 0.1.0-beta.5

Expand Down
18 changes: 13 additions & 5 deletions packages/teamscale-javascript-instrumenter/src/App.ts
Expand Up @@ -19,10 +19,7 @@ export class App {
* Parses the command line options and the instrumentation accordingly.
*/
public static async run(): Promise<TaskResult> {
// Parsing of command line arguments:
// Build the configuration object from the command line arguments.
const parser: ArgumentParser = this.buildParser();
const config: ConfigurationParameters = parser.parse_args();
const config = this.parseCommandLine();

// Build the logger
const logger = this.buildLogger(config);
Expand All @@ -33,6 +30,17 @@ export class App {
return this.runForConfigArguments(config, logger);
}

/**
* Parses the command-line arguments.
*
* @param args Optional. For testing. If given, uses this as the arguments to parse and does not exit the process on errors.
* If not given, uses the NodeJS process's arguments and exits on errors.
*/
public static parseCommandLine(args?: string[]): ConfigurationParameters {
const parser: ArgumentParser = this.buildParser();
return parser.parse_args(args);
}

/**
* Sometimes we get inputs from shell environments where the strings are
* still quoted. We remove those here.
Expand Down Expand Up @@ -82,7 +90,7 @@ export class App {
*/
private static buildParser(): ArgumentParser {
const parser = new ArgumentParser({
description: 'Instrumenter of the Teamscale JavaScript Profiler'
description: 'Instrumenter of the Teamscale JavaScript Profiler',
});

parser.add_argument('-v', '--version', { action: 'version', version });
Expand Down
Expand Up @@ -23,7 +23,8 @@ export type ConfigurationParameters = {
// eslint-disable-next-line camelcase
source_map?: string;
collector: string;
collector_pattern?: string;
// eslint-disable-next-line camelcase
relative_collector?: string;
// eslint-disable-next-line camelcase
include_origin?: string[];
// eslint-disable-next-line camelcase
Expand Down Expand Up @@ -130,7 +131,7 @@ export class TaskBuilder {
const sourceMap: string | undefined = config.source_map;
this.dumpOriginsFile = config.dump_origins_to;
this.dumpMatchedOriginsFile = config.dump_origin_matches_to;
this.setCollectorFromCommandLine(config.collector, config.collector_pattern);
this.setCollectorFromCommandLine(config.collector, config.relative_collector);
this.setOriginSourceIncludePatterns(config.include_origin);
this.setOriginSourceExcludePatterns(config.exclude_origin);
this.setBundleExcludePatterns(config.exclude_bundle);
Expand Down
Expand Up @@ -140,7 +140,7 @@ test('Instrumented code must contain collector specification', async () => {
exclude_origin: ['node_modules/**/*.*'],
in_place: false,
collector: "ws://not-used-since-pattern-is-also-given",
collector_pattern: "replace-in-host:foo bar,port:1234,scheme:wss",
relative_collector: "replace-in-host:foo bar,port:1234,scheme:wss",
to: outputDir
});
const matchStats = result.task?.originSourcePattern.retrieveMatchingFiles();
Expand Down
14 changes: 11 additions & 3 deletions packages/teamscale-javascript-instrumenter/test/unit/App.test.ts
@@ -1,9 +1,17 @@
import {App} from "../../src/App";
import { App } from "../../src/App";

test('Postprocessing of config input parameters', () => {
const config = { inputs: ['"abc"', "'cde'"], collector: "'foo'"};
const config = { inputs: ['"abc"', "'cde'"], collector: "'foo'" };
App.postprocessConfig(config)
expect(config.inputs[0]).toEqual('abc');
expect(config.inputs[1]).toEqual('cde');
expect(config.collector).toEqual('foo');
});
});


test('Parsing command-line parameters', () => {
expect(App.parseCommandLine(["--relative-collector", "replace-in-host:app collector", "input.file"]).relative_collector)
.toEqual("replace-in-host:app collector")
expect(App.parseCommandLine(["input.file"]).relative_collector)
.toBeUndefined()
});

0 comments on commit 4c334c4

Please sign in to comment.