Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Insert test variables and sleeps in script #56

Merged
merged 6 commits into from
Jul 23, 2024

Conversation

going-confetti
Copy link
Collaborator

No description provided.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed for consistency: we don't use enums in other places (for example, for rule types, sleep types, etc.)

case 'fixed':
return `sleep(${timing.value})`
case 'range':
return `sleep(Math.random() * (${timing.value.max} - ${timing.value.min}) + ${timing.value.min})`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should switch to randomIntBetween once we've figured out imports

setPreview(script)
}

updatePreview()
// TODO: implement a more reactive way to update the preview
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use this middleware to subscribe to store changes. I'll think about this in my future PRs

src/codegen/codegen.ts Outdated Show resolved Hide resolved
export function generateVariableDeclarations(variables: Variable[]): string {
return variables
.filter(({ name }) => name)
.map(({ name, value }) => `const ${name} = "${value}"`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want to namespace variables ?

possibly a global VARS object or similar to have them bounded, what do you think ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we discussed this, but noticed that we didn't follow this approach for correlated values - do you remember why?

In this case, one potential downside of this would be explaining to the user that variables need to be accessed not just by their names, but also by the name of the test variables object. It may still lead to a better DX in Monaco

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more than a downside it might be a perk, that variables defined will be always autocompleted from VARS or similar 🤔

but noticed that we didn't follow this approach for correlated values - do you remember why?
yap, correlation runs at runtime so we define the variable before extracting it and use it with the sequentially incremented id correlation_1

For variables, we know about them when generating the script and there are advantages in grouping them under a common name.

In theory you could have an object also for correlation variables but we don't have problems with them at script level because of the autoincrementing id that we do not make use of in vars

src/codegen/codegen.ts Outdated Show resolved Hide resolved
rules: generatorState.rules,
allowlist: generatorState.allowList,
}
const generatorFile = storeToGeneratorFileData(useGeneratorStore.getState())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩

@going-confetti
Copy link
Collaborator Author

I think we shouldn't assume that the user doesn't want groups if there is a single one 🤔

Another topic would be the default group we create on recording, we most likely have to improve on that.

I agree. Mayne we can change the interaction in the following way:

  • By default, there are not groups
  • If you click on "Create group" for the first time, two groups are created - one for previous requests and one for the requests that will follow

Although I admit it may be confusing. Still, putting requests into a single group doesn't feel right somehow :\

@Llandy3d
Copy link
Member

I think we shouldn't assume that the user doesn't want groups if there is a single one 🤔

Another topic would be the default group we create on recording, we most likely have to improve on that.

I agree. Mayne we can change the interaction in the following way:

  • By default, there are not groups
  • If you click on "Create group" for the first time, two groups are created - one for previous requests and one for the requests that will follow

Although I admit it may be confusing. Still, putting requests into a single group doesn't feel right somehow :\

yeah I completely agree that it does not feel right at all.

I think your proposal makes sense, specially if we consider improvements in the future where you can pick which groups to keep in the recording before saving the HAR if it makes sense at all 🤔

Copy link
Member

@Llandy3d Llandy3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@going-confetti going-confetti merged commit 92a49c2 into main Jul 23, 2024
1 check passed
@going-confetti going-confetti deleted the feat/test-data-think-time-in-script branch July 23, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants