k6 icon indicating copy to clipboard operation
k6 copied to clipboard

js: options.scenarios return an empty object

Open codebien opened this issue 3 years ago • 0 comments

Brief summary

Using as an example the reported script, it prints an unexpected {} object using >v0.37.0. This change has been introduced by https://github.com/grafana/k6/pull/2392.

This is happening because the logic sets the scenarios property after the change from 2392. https://github.com/grafana/k6/blob/737dfa7ced6e4f94dbb3d6f2c2837085e783ac09/js/bundle.go#L290-L294 Unfortunately, the goja.Value.Export doesn't work well for the options.Scenarios' Go type and it sets an empty object.

In v0.36.0 and previous versions, the scenarios key wasn't set during the js.Bundle.Instantiate because the key used for it was the wrong scenarios,omitempty as mentioned in 2393.

Note: We could consider not fixing this bug mostly because the correct API to use for fetching the options should be the new exec.test.options and we would avoid users accessing options using the variable defined and exported from the script.

k6 version

v0.37.0

OS

Linux

Docker version and image (if applicable)

No response

Steps to reproduce the problem

k6-v0.37.0 run script.js

Expected behaviour

console.log(JSON.stringify(options.scenarios)) // {}
---
INFO[0000] {"contacts":{"executor":"shared-iterations","iterations":1}}  source=console

Actual behaviour

import exec from 'k6/execution';

export const options = {
	scenarios: {
		contacts: {
			executor: 'shared-iterations',
			iterations: 1,
		},
	},
};

export default function() {
	console.log(JSON.stringify(options.scenarios))
}
---
INFO[0000] {}  source=console

codebien avatar Apr 14 '22 08:04 codebien