Skip to content

Commit

Permalink
fix: Arguments.find is not a function
Browse files Browse the repository at this point in the history
  • Loading branch information
rorlic committed Apr 2, 2024
1 parent 2ae34d2 commit 14ac11d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,15 @@ export class Controller {

const parsed = this._testParser.parse(body) as JMeterTest;
const testPlan = parsed.jmeterTestPlan.hashTree.TestPlan;
const testLabels = parsed.jmeterTestPlan.hashTree.hashTree.Arguments.find(x => x._testname === 'Labels');

const labels = testLabels?.collectionProp.elementProp
.map(x => ({ key: x._name, value: x.stringProp.find(s => s._name === 'Argument.value')?._text }))
const args = parsed.jmeterTestPlan.hashTree.hashTree.Arguments;
const elements = Array.isArray(args) && args?.find(x => x._testname === 'Labels')?.collectionProp?.elementProp;
const labels = Array.isArray(elements) && elements
.map(x => ({
key: x._name,
value: Array.isArray(x.stringProp)
? x.stringProp.find(s => s._name === 'Argument.value')?._text
: (x.stringProp._name === 'Argument.value' ? x.stringProp._text : undefined)
}))
.reduce<Labels>((a, x) => (a[x.key] = x.value?.toString(), a), {});

const timestamp = new Date().toISOString();
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export interface JMeterStringProp {

export interface JMeterElementProp {
_name: string,
stringProp: JMeterStringProp[]
stringProp: JMeterStringProp | JMeterStringProp[]
}

export interface JMeterCollectionProp {
elementProp: JMeterElementProp[]
elementProp: JMeterElementProp | JMeterElementProp[]
}

export interface JMeterArguments {
Expand All @@ -26,7 +26,7 @@ export interface JMeterTest {
_testname: string
},
hashTree: {
Arguments: JMeterArguments[]
Arguments: JMeterArguments | JMeterArguments[]
}
}
}
Expand Down

0 comments on commit 14ac11d

Please sign in to comment.