allure-framework / allure-js

Allure integrations for JavaScript test frameworks
https://allurereport.org/
Apache License 2.0
223 stars 117 forks source link

[allure-jest] Retrying test does not work with allure-jest reporter #1060

Closed lifanov-rza closed 1 month ago

lifanov-rza commented 1 month ago

jest.retry docs

I'm trying to run tests with retrying when they failed but I get an error (see below).

test:

import allureReporter from '../../../../src/helpers/allureReporter';

let attempt = 0;

beforeEach(async () => {
  attempt++;
});

describe('Jest retry suite', () => {
  jest.retryTimes(1, { logErrorsBeforeRetry: true });
  test(`Retry test`, async () => {

    if (attempt === 1) {
      allureReporter.startStep('Start comparing');
      expect(true).toBe(true);
      await allureReporter.finishStep();
    } else {
      expect(true).toBe(true);
    }
});

To Reproduce

  1. Create jest project with jest-circus runner and allure-jest reporter
  2. Add a simple test (see example above). You can add allure-reporter invocation in your test
  3. Run the test with retries

Expected behavior Retrying is correctly working and logging

Actual behavior

Can't find "AB test @admin-cp [PUT] Succeed add landing in test by selecting group for campaign. AIO campaign @TC-158000000" test while tried to start it!
Can't find "AB test @admin-cp [PUT] Succeed add landing in test by selecting group for campaign. AIO campaign @TC-158000000" test while tried to mark it as passed!
Can't find "AB test @admin-cp [PUT] Succeed add landing in test by selecting group for campaign. AIO campaign @TC-158000000" test while tried to dispose it after start!

Error: expect(received).toBe(expected) // Object.is equality

Expected: false
Received: true
<Click to see difference>

    at Object.toBe (/Users/dmitrii/Documents/Projects/api-test/tests/admin/advertiser/campaign/abTest.test.ts:26:20)
    at Promise.then.completed (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-circus/build/utils.js:298:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-circus/build/utils.js:231:10)
    at _callCircusTest (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-circus/build/run.js:316:40)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at _runTest (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-circus/build/run.js:252:3)
    at _runTestsForDescribeBlock (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-circus/build/run.js:126:9)
    at _runTestsForDescribeBlock (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-circus/build/run.js:121:9)
    at run (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-circus/build/run.js:71:3)
    at runAndTransformResultsToJestFormat (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/Users/dmitrii/Documents/Projects/api-test/node_modules/jest-runner/build/testWorker.js:106:12)

AllureReporter class is a facade of allure-jest reporter.

Screenshots image image

Additional context

Jest config

import type { Config } from 'jest';

require('dotenv').config();

const GREP = process.env.GREP || '';

const config: Config = {
  moduleFileExtensions: [
    'ts',
    'tsx',
    'js',
  ],
  reporters: [
    'default',
    'jest-junit',
  ],
  setupFiles: ['dotenv/config'],
  testEnvironment: require.resolve('allure-jest/node'),
  testEnvironmentOptions: {
    resultsDir: './allure-results',
  },
  testNamePattern: GREP,
  testResultsProcessor: 'jest-junit',
  testRunner: 'jest-circus/runner',
  testTimeout: 15000,
  transform: {
    '.(ts|tsx)': '@swc/jest',
  },
  verbose: true,
  workerIdleMemoryLimit: '512MB',
};

export default config;
"devDependencies": {
    ...
    "allure-jest": "^2.15.1",
    "jest": "^29.7.0",
    "typescript": "^5.5.3"
    ....
  },
baev commented 1 month ago

Could you please check if the issue can be reproduced by using allure-jest@3.0.0-beta.6? According to the tests it should be already fixed

lifanov-rza commented 1 month ago

Could you please check if the issue can be reproduced by using allure-jest@3.0.0-beta.6? According to the tests it should be already fixed

Checked, it's okay. Thanks