Skip to content

Uncaught (in promise) should fail functional tests #5249

@ankur22

Description

@ankur22

Feature Description

k6's initial focus has been to provide functionality for load testing. When a test such as the one below fails with "Uncaught (in promise)", the test is actually marked as passed:

import { browser } from 'k6/browser';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
            type: 'chromium',
        },
      },
    },
  },
}

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

  await page.goto('https://quickpizza.grafana.com/');

  await page.locator('a[href="/fake-link.php"]').click({ timeout: 1000 });

  await page.close();
}

As mentioned before, with a non-functional test this might not matter in most cases since you might be running multiple VUs and many iterations, where a few tests would fail and we don't want to abort the whole test run in those cases.

However in the functional case, this is a problem. The expectation is that the test actually fail since the test didn't complete to the end. Current workarounds include:

  1. Having to parse the logs for "Uncaught (in promise)" or "stacktrace".
  2. Catching the error and calling fail or asserting with expect.

This is just extra boilerplate code which makes adopting k6 harder than other JS testing libraries.

Suggested Solution (optional)

  1. Create a CLI flag/envvar/option that tells k6 that if it encounters "Uncaught (in promise)" or "stacktrace" (and maybe other errors) to fail the test and make sure it is marked as failed.

Already existing or connected issues / PRs (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions