Skip to content

Commit 4dec39b

Browse files
committed
Merge branch 'main' into fix/debugger-not-stopping
2 parents 9369e62 + 96383c9 commit 4dec39b

File tree

40 files changed

+5122
-3361
lines changed

40 files changed

+5122
-3361
lines changed

package-lock.json

Lines changed: 4312 additions & 3214 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Generated by Grafana k6 Studio (0.0.0-vitest) on 2023-10-01T00:00:00.000Z
2+
3+
import { browser } from "k6/browser";
4+
5+
export const options = {
6+
scenarios: {
7+
default: {
8+
executor: "shared-iterations",
9+
options: { browser: { type: "chromium" } },
10+
},
11+
},
12+
};
13+
14+
export default async function () {
15+
const page = await browser.newPage();
16+
17+
try {
18+
await page.waitForTimeout(1500);
19+
} finally {
20+
await page?.close();
21+
}
22+
}

src/codegen/browser/code/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function isBrowserScenario(scenario: ir.Scenario) {
5353
case 'WaitForExpression':
5454
case 'WaitForOptionsExpression':
5555
case 'WaitForNavigationExpression':
56+
case 'WaitForTimeoutExpression':
5657
return true
5758

5859
case 'Identifier':

src/codegen/browser/code/scenario.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,19 @@ function emitWaitForNavigationExpression(
469469
.done()
470470
}
471471

472+
function emitWaitForTimeoutExpression(
473+
context: ScenarioContext,
474+
expression: ir.WaitForTimeoutExpression
475+
): ts.Expression {
476+
const target = emitExpression(context, expression.target)
477+
478+
return new ExpressionBuilder(target)
479+
.member('waitForTimeout')
480+
.call([literal({ value: expression.timeout })])
481+
.await(context)
482+
.done()
483+
}
484+
472485
function emitPromiseAllExpression(
473486
context: ScenarioContext,
474487
expression: ir.PromiseAllExpression
@@ -571,6 +584,9 @@ function emitExpression(
571584
case 'WaitForNavigationExpression':
572585
return emitWaitForNavigationExpression(context, expression)
573586

587+
case 'WaitForTimeoutExpression':
588+
return emitWaitForTimeoutExpression(context, expression)
589+
574590
case 'PromiseAllExpression':
575591
return emitPromiseAllExpression(context, expression)
576592

src/codegen/browser/codegen.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,30 @@ it('should emit a waitFor statement', async ({ expect }) => {
12211221
)
12221222
})
12231223

1224+
it('should emit page.waitForTimeout', async ({ expect }) => {
1225+
const script = await emitScript({
1226+
defaultScenario: {
1227+
nodes: [
1228+
{
1229+
type: 'page',
1230+
nodeId: 'page',
1231+
},
1232+
{
1233+
type: 'wait-for-timeout',
1234+
nodeId: 'wait-for-timeout',
1235+
timeout: 1500,
1236+
inputs: { page: { nodeId: 'page' } },
1237+
},
1238+
],
1239+
},
1240+
scenarios: {},
1241+
})
1242+
1243+
await expect(script).toMatchFileSnapshot(
1244+
'__snapshots__/browser/wait-for-timeout-statement.ts'
1245+
)
1246+
})
1247+
12241248
it('should emit merged try-finally blocks', async ({ expect }) => {
12251249
const script = await emitScript({
12261250
defaultScenario: {

src/codegen/browser/formatting/formatter.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
/* eslint-disable import/default */
22
import type { TSESTree as ts } from '@typescript-eslint/types'
3-
import {
4-
AstPath,
5-
Plugin,
6-
Printer,
7-
SupportOption,
8-
ParserOptions,
9-
} from 'prettier'
3+
import { AstPath, Plugin, SupportOption, ParserOptions } from 'prettier'
104
import { builders } from 'prettier/doc'
115
import defaultOptions, { options, printers } from 'prettier/plugins/estree'
126
import { format as formatWithPrettier } from 'prettier/standalone'
@@ -15,10 +9,6 @@ const { hardline } = builders
159
const estree = printers.estree
1610

1711
declare module 'prettier/plugins/estree' {
18-
const printers: {
19-
estree: Printer<ts.Node>
20-
}
21-
2212
const options: Record<string, SupportOption>
2313
}
2414

src/codegen/browser/intermediate/ast.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ export interface WaitForNavigationExpression {
152152
target: Expression
153153
}
154154

155+
export interface WaitForTimeoutExpression {
156+
type: 'WaitForTimeoutExpression'
157+
target: Expression
158+
timeout: number
159+
}
160+
155161
export interface PromiseAllExpression {
156162
type: 'PromiseAllExpression'
157163
expressions: Expression[]
@@ -237,6 +243,7 @@ export type Expression =
237243
| WaitForExpression
238244
| WaitForOptionsExpression
239245
| WaitForNavigationExpression
246+
| WaitForTimeoutExpression
240247
| PromiseAllExpression
241248

242249
export interface VariableDeclaration {

src/codegen/browser/intermediate/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function buildScenarioGraph(scenario: model.Scenario) {
5252

5353
case 'goto':
5454
case 'reload':
55+
case 'wait-for-timeout':
5556
graph.connect(node.nodeId, node.inputs.page.nodeId, 'reference')
5657
connectPrevious(graph, node)
5758
break

src/codegen/browser/intermediate/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,22 @@ function emitWaitForNode(context: IntermediateContext, node: m.WaitForNode) {
427427
})
428428
}
429429

430+
function emitWaitForTimeoutNode(
431+
context: IntermediateContext,
432+
node: m.WaitForTimeoutNode
433+
) {
434+
const page = context.reference(node.inputs.page)
435+
436+
context.emit({
437+
type: 'ExpressionStatement',
438+
expression: {
439+
type: 'WaitForTimeoutExpression',
440+
target: page,
441+
timeout: node.timeout,
442+
},
443+
})
444+
}
445+
430446
function emitNode(context: IntermediateContext, node: m.TestNode) {
431447
switch (node.type) {
432448
case 'page':
@@ -462,6 +478,9 @@ function emitNode(context: IntermediateContext, node: m.TestNode) {
462478
case 'wait-for':
463479
return emitWaitForNode(context, node)
464480

481+
case 'wait-for-timeout':
482+
return emitWaitForTimeoutNode(context, node)
483+
465484
default:
466485
return exhaustive(node)
467486
}

src/codegen/browser/intermediate/variables.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ function substituteExpression(
217217
target: substituteExpression(node.target, substitutions),
218218
}
219219

220+
case 'WaitForTimeoutExpression':
221+
return {
222+
type: 'WaitForTimeoutExpression',
223+
target: substituteExpression(node.target, substitutions),
224+
timeout: node.timeout,
225+
}
226+
220227
default:
221228
return exhaustive(node)
222229
}

0 commit comments

Comments
 (0)