Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Generated by Grafana k6 Studio (0.0.0-vitest) on 2023-10-01T00:00:00.000Z

import { browser } from "k6/browser";

export const options = {
scenarios: {
default: {
executor: "shared-iterations",
options: { browser: { type: "chromium" } },
},
},
};

export default async function () {
const page = await browser.newPage();

try {
await page.waitForTimeout(1500);
} finally {
await page?.close();
}
}
1 change: 1 addition & 0 deletions src/codegen/browser/code/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function isBrowserScenario(scenario: ir.Scenario) {
case 'WaitForExpression':
case 'WaitForOptionsExpression':
case 'WaitForNavigationExpression':
case 'WaitForTimeoutExpression':
return true

case 'Identifier':
Expand Down
16 changes: 16 additions & 0 deletions src/codegen/browser/code/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,19 @@ function emitWaitForNavigationExpression(
.done()
}

function emitWaitForTimeoutExpression(
context: ScenarioContext,
expression: ir.WaitForTimeoutExpression
): ts.Expression {
const target = emitExpression(context, expression.target)

return new ExpressionBuilder(target)
.member('waitForTimeout')
.call([literal({ value: expression.timeout })])
.await(context)
.done()
}

function emitPromiseAllExpression(
context: ScenarioContext,
expression: ir.PromiseAllExpression
Expand Down Expand Up @@ -571,6 +584,9 @@ function emitExpression(
case 'WaitForNavigationExpression':
return emitWaitForNavigationExpression(context, expression)

case 'WaitForTimeoutExpression':
return emitWaitForTimeoutExpression(context, expression)

case 'PromiseAllExpression':
return emitPromiseAllExpression(context, expression)

Expand Down
24 changes: 24 additions & 0 deletions src/codegen/browser/codegen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,30 @@ it('should emit a waitFor statement', async ({ expect }) => {
)
})

it('should emit page.waitForTimeout', async ({ expect }) => {
const script = await emitScript({
defaultScenario: {
nodes: [
{
type: 'page',
nodeId: 'page',
},
{
type: 'wait-for-timeout',
nodeId: 'wait-for-timeout',
timeout: 1500,
inputs: { page: { nodeId: 'page' } },
},
],
},
scenarios: {},
})

await expect(script).toMatchFileSnapshot(
'__snapshots__/browser/wait-for-timeout-statement.ts'
)
})

it('should emit merged try-finally blocks', async ({ expect }) => {
const script = await emitScript({
defaultScenario: {
Expand Down
7 changes: 7 additions & 0 deletions src/codegen/browser/intermediate/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ export interface WaitForNavigationExpression {
target: Expression
}

export interface WaitForTimeoutExpression {
type: 'WaitForTimeoutExpression'
target: Expression
timeout: number
}

export interface PromiseAllExpression {
type: 'PromiseAllExpression'
expressions: Expression[]
Expand Down Expand Up @@ -237,6 +243,7 @@ export type Expression =
| WaitForExpression
| WaitForOptionsExpression
| WaitForNavigationExpression
| WaitForTimeoutExpression
| PromiseAllExpression

export interface VariableDeclaration {
Expand Down
Loading
Loading