Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

Undefined variable when it's being converted #23

Open
0UserName opened this issue Dec 13, 2019 · 0 comments
Open

Undefined variable when it's being converted #23

0UserName opened this issue Dec 13, 2019 · 0 comments

Comments

@0UserName
Copy link

I has problem in the following place:

const makeContext = require('../context')
const text = require('../text')

/**
 * Convert variable
 *
 * @param {object} node - Parsed variable node.
 *
 * @return {ConvertResult}
 */
function variable (node, context = makeContext()) {
  const properties = node.children.filter(item => item.name === 'stringProp')
  const nameNode = properties.find(item => {
    return item.attributes.name.split('.').pop() === 'name'
  })
  if (!nameNode) throw new Error('Variable missing name')
  const valueNode = properties.find(item => {
    return item.attributes.name.split('.').pop() === 'value'
  })
  if (!valueNode) throw new Error('Variable missing value')
  const description = properties.find(item => {
    return item.attributes.name.split('.').pop() === 'desc'
  })
  const result = { vars: new Map() }
  const spec = { value: text(valueNode.children) }
  if (description) spec.comment = text(description.children)
  const name = text(nameNode.children)
  result.vars.set(name, spec)
  context.vars.set(name, spec.value)
  return result
}

module.exports = variable

The following objects have empty maps at the end of execution:

 result.vars.set(name, spec)
 context.vars.set(name, spec.value)

Local variables are defined, and in general the functionality works properly, except for the lines I mentioned, I tried changing the new Map () to {}, and it works, but there are a lot of dependent places that use the context with vars.map.

 UnhandledPromiseRejectionWarning: Error: Undefined variable: front_url
    at variable (C:\Users\username\AppData\Roaming\npm\node_modules\jmeter-to-k6\src\string\interpolate.js:43:38)
    at evaluate (C:\Users\username\AppData\Roaming\npm\node_modules\jmeter-to-k6\src\string\interpolate.js:30:15)
    at replace (C:\Users\username\AppData\Roaming\npm\node_modules\jmeter-to-k6\src\string\interpolate.js:20:10)
    at C:\Users\username\AppData\Roaming\npm\node_modules\jmeter-to-k6\src\string\interpolate.js:10:38
    at Array.map (<anonymous>)
    at interpolate (C:\Users\username\AppData\Roaming\npm\node_modules\jmeter-to-k6\src\string\interpolate.js:10:25)
    at string (C:\Users\username\AppData\Roaming\npm\node_modules\jmeter-to-k6\src\string\convert.js:7:41)
    at value (C:\Users\username\AppData\Roaming\npm\node_modules\jmeter-to-k6\src\value.js:5:10)
    at extractValue (C:\Users\username\AppData\Roaming\npm\node_modules\jmeter-to-k6\src\common\property.js:20:19)
    at property (C:\Users\username\AppData\Roaming\npm\node_modules\jmeter-to-k6\src\common\property.js:11:25)
(node:4740) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (reject
ion id: 1)
(node:4740) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Node: v12.13.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants