jestjsjest-puppeteer

How to not skip tests in a suite upon failure?


I have a large number of tests, contained in "suites" or files, probably about 10-15 tests in each suite. The issue I'm having is that if the first test in a suite fails, then it just skips all the rest of the tests in that suite, and goes on to the next suite. This means that, say I have a suite of 10 tests, if the first one fails, the next 9 are skipped entirely. I want those to still run, as they pass. Otherwise, now I have to investigate and re-run 10 tests instead of just the one that failed.

I've tried using the --bail option, but that apparently only applies to the test suites, not to individual tests within a suite. Is there any option or way to force Jest to not skip the rest of the tests in a file, regardless of the pass/fail outcome of the previous test?

I've added the after each code as well.

here's the relevant part of the jest.config.js

testTimeout: 900000, forceExit: true, clearMocks: true, globals: { Headless: false , NoLogin: true } ,

and here's what a test file looks like:

"use strict";

import _ from 'lodash'
import { expect } from 'chai';

describe("test pages  ", () => {
    let searchPage

  test("test page 1", async () => {
    await searchPage.openPage1();
    expect(await searchPage.waitForElement(element 1))
    })

  test("test page 2", async () => {
    await searchPage.openPage2();
    expect(await searchPage.waitForElement(element 2))
    })

  test("test page 3", async () => {
    await searchPage.openPage3();
    expect(await searchPage.waitForElement(element 3))
    })`

Basically what happens now is if test 1 fails, then it completely skips the next two tests, and they show up as pending, and never get run.

Here's the After Each code:

    try {
  await global.driver.close();
} catch (e) {
  console.log(e);
}

And here's the Jest Configuration:

module.exports = {

  testEnvironment: "node",

  setupFilesAfterEnv: [`./testConfig/testSetup.js`],
  reporters: [
    "default",
    "jest-junit",
    "jest-html-reporters",
    [
      "jest-simple-dot-reporter",
      {
        color: true
      }
    ]
  ],
  
  transformIgnorePatterns: ["node_modules/(?!(@qe/ui_automation_core)/)"],
  testTimeout: 900000,
  forceExit: true,
  clearMocks: true, 
  globals: { Headless: false ,  NoLogin: true  } , 

};```

Solution

  • Okay. I figured out what was causing the issue.
    Turns out the original owner of this test suite had used jasmine-fail-fast in the config setup

    import * as failFast from 'jasmine-fail-fast' and jasmine.getEnv().addReporter(failFast.init())

    So i commented out those lines and now I get the proper behavior (it runs all tests, instead of skipping everything after the first failure).

    Dan