Home > OS >  TestCafe only running first test in loop
TestCafe only running first test in loop

Time:12-28

I have the following function to run parameterized tests:

export function multiTest<T>({cases, setup, testFn, testNamePrefix, skip, options: _options}: {
  cases: TestCases<T>
  setup: (t: SetupHelper, cases: TestCases<T>) => (void | Promise<void>) 
  testFn: MultiTestFn<T>,
  testNamePrefix?: string,
  skip?: boolean
  options?: HelperOptions
}): Promise<void> {
  const doSetup = async () => {
    if (skip) {
      return;
    }

    // some setup code here left out

    await setup(new SetupHelper(options), cases);
  }

  let wrappedFn = test.page(someUrl);
  if(skip) {
    wrappedFn = wrappedFn.skip;
  }

  let didSetup = false;
  cases.forEach(([testName, caseData]) => {
    wrappedFn(`${testNamePrefix || ""}${testName}`, async (t) => {
      if(!didSetup) {
        await doSetup();
        didSetup = true;
      }
      await testFn(t, new Helper(t, options), caseData)
    })
  });
}

The test code that calls this:

skeleton.multiTest({
  testNamePrefix: "Content masking: ",
  cases: [
    { suppressMessages: "off", suppressTypes: "all", expectedMasks: 0},
    { suppressMessages: "all", suppressTypes: "all", expectedMasks: 12},
    { suppressMessages: "otherOnly", suppressTypes: "all", expectedMasks: 6 },
    { suppressMessages: "all", suppressTypes: "links", expectedMasks: 2 },
    { suppressMessages: "all", suppressTypes: "phones", expectedmasks: 4, replacement: "           
  • Related