Skip to content

Commit

Permalink
Update scripted check default example/snippet (#1006)
Browse files Browse the repository at this point in the history
* chore: update scripted check example to include fail()

* chore: fix escape
  • Loading branch information
peterschretlen authored Nov 27, 2024
1 parent 868a5bc commit fcaf922
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/components/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,25 @@ export const TIME_UNIT_OPTIONS = [
export const TEN_MINUTES_IN_MS = 1000 * 60 * 10;
export const FIVE_MINUTES_IN_MS = 1000 * 60 * 5;

const EXAMPLE_SCRIPT_SCRIPTED = btoa(`import { check } from 'k6'
const EXAMPLE_SCRIPT_SCRIPTED = btoa(`import { check, fail } from 'k6'
import http from 'k6/http'
export default function main() {
const res = http.get('http://test.k6.io/');
const result = http.get('http://test.k6.io/');
// console.log will be represented as logs in Loki
console.log('got a response')
check(res, {
console.log('got a response');
// Use check() to test conditions. These show as 'assertions' in the dashboard
// Note: failed check() calls do not impact uptime and reachability
const pass = check(result, {
'is status 200': (r) => r.status === 200,
});
// Use fail() to abort and fail a test, impacting uptime and reachability
if(!pass){
fail(\`non 200 result \${result.status}\`);
}
}`);

const EXAMPLE_SCRIPT_BROWSER = btoa(`import { browser } from 'k6/browser';
Expand Down

0 comments on commit fcaf922

Please sign in to comment.