Skip to content

Commit b670a64

Browse files
oleiadeinancgumus
authored andcommitted
Revert "Use new expect() syntax in script templates (#5040)"
This reverts commit 506791b.
1 parent a9f9e3b commit b670a64

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

internal/cmd/templates/browser.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import http from "k6/http";
22
import exec from 'k6/execution';
33
import { browser } from "k6/browser";
4-
import { sleep, fail } from 'k6';
5-
import { expect } from "https://jslib.k6.io/k6-testing/0.5.0/index.js";
4+
import { sleep, check, fail } from 'k6';
65

76
const BASE_URL = __ENV.BASE_URL || "https://quickpizza.grafana.com";
87

@@ -27,7 +26,9 @@ export const options = {
2726

2827
export function setup() {
2928
let res = http.get(BASE_URL);
30-
expect(res.status, `Got unexpected status code ${res.status} when trying to setup. Exiting.`).toBe(200);
29+
if (res.status !== 200) {
30+
exec.test.abort(`Got unexpected status code ${res.status} when trying to setup. Exiting.`);
31+
}
3132
}
3233

3334
export default async function() {
@@ -36,13 +37,21 @@ export default async function() {
3637

3738
try {
3839
await page.goto(BASE_URL);
39-
await expect.soft(page.locator("h1")).toHaveText("Looking to break out of your pizza routine?");
40+
41+
checkData = await page.locator("h1").textContent();
42+
check(page, {
43+
header: checkData === "Looking to break out of your pizza routine?",
44+
});
4045

4146
await page.locator('//button[. = "Pizza, Please!"]').click();
4247
await page.waitForTimeout(500);
4348

4449
await page.screenshot({ path: "screenshot.png" });
45-
await expect.soft(page.locator("div#recommendations")).not.toHaveText("");
50+
51+
checkData = await page.locator("div#recommendations").textContent();
52+
check(page, {
53+
recommendation: checkData !== "",
54+
});
4655
} catch (error) {
4756
fail(`Browser iteration failed: ${error.message}`);
4857
} finally {

internal/cmd/templates/minimal.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import http from 'k6/http';
2-
import { sleep } from 'k6';
3-
import { expect } from "https://jslib.k6.io/k6-testing/0.5.0/index.js";
2+
import { sleep, check } from 'k6';
43

54
export const options = {
65
vus: 10,
@@ -13,6 +12,6 @@ export const options = {
1312

1413
export default function() {
1514
let res = http.get('https://quickpizza.grafana.com');
16-
expect.soft(res.status).toBe(200);
15+
check(res, { "status is 200": (res) => res.status === 200 });
1716
sleep(1);
1817
}

internal/cmd/templates/protocol.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import http from "k6/http";
22
import exec from 'k6/execution';
3-
import { sleep } from "k6";
4-
import { expect } from "https://jslib.k6.io/k6-testing/0.5.0/index.js";
3+
import { check, sleep } from "k6";
54

65
const BASE_URL = __ENV.BASE_URL || 'https://quickpizza.grafana.com';
76

@@ -23,7 +22,9 @@ export const options = {
2322

2423
export function setup() {
2524
let res = http.get(BASE_URL);
26-
expect(res.status, `Got unexpected status code ${res.status} when trying to setup. Exiting.`).toBe(200);
25+
if (res.status !== 200) {
26+
exec.test.abort(`Got unexpected status code ${res.status} when trying to setup. Exiting.`);
27+
}
2728
}
2829

2930
export default function() {
@@ -43,7 +44,7 @@ export default function() {
4344
},
4445
});
4546

46-
expect.soft(res.status).toBe(200);
47+
check(res, { "status is 200": (res) => res.status === 200 });
4748
console.log(res.json().pizza.name + " (" + res.json().pizza.ingredients.length + " ingredients)");
4849
sleep(1);
4950
}

0 commit comments

Comments
 (0)