nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.17k stars 2.3k forks source link

e2e-ci Causes Endless Loop Due to Unmocked POST Request During Cypress Tests #26612

Closed lucas9122 closed 3 weeks ago

lucas9122 commented 2 months ago

Current Behavior

When the POST request is not mocked in cypress tests, it results in a 404 error. This sometimes triggers an endless loop with constant redirection. Each iteration adds "?/" to the endpoint address, causing the test to stuck due to repeated redirections. It is only related to POST requests and the issue is not deterministic, does not happen every time. GET requests does not cause such problems.

image

Expected Behavior

When the POST request is not mocked, the test should handle the 404 error without entering an endless loop. The test should either fail with a clear error message or continue running without causing constant redirections

GitHub Repo

No response

Steps to Reproduce

  1. Run command: nx e2e-ci my-app-e2e

Nx Report

Node   : 18.16.0
OS     : darwin-x64
npm    : 9.5.1

nx (global)        : v17.2.5
nx                 : 18.2.1
@nx/js             : 18.2.1
@nx/jest           : 18.2.1
@nx/linter         : 18.2.1
@nx/eslint         : 18.2.1
@nx/workspace      : 18.2.1
@nx/angular        : 18.2.1
@nx/cypress        : 18.2.1
@nx/devkit         : 18.2.1
@nx/eslint-plugin  : 18.2.1
@nrwl/tao          : 18.2.1
@nx/web            : 18.2.1
@nx/webpack        : 18.2.1
typescript         : 5.2.2
---------------------------------------
Community plugins:
@ngneat/transloco    : 6.0.4
@ngrx/effects        : 17.0.1
@ngrx/entity         : 17.0.1
@ngrx/router-store   : 17.0.1
@ngrx/schematics     : 17.0.1
@ngrx/signals        : 17.1.1
@ngrx/store          : 17.0.1
@ngrx/store-devtools : 17.0.1

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

cypress.config.ts

const preset = nxE2EPreset(__filename, {
  cypressDir: 'src',
  webServerCommands: {
    default: 'nx run my-app:serve',
    production: 'nx run my-app:production',
  },
  ciWebServerCommand: 'nx run my-app:serve-static',
  webServerConfig: {
    reuseExistingServer: true,
    timeout: 1960000,
  },
});
export default defineConfig({
  e2e: {
    ...preset,
    specPattern: './src/integration/**/*.integration.*',
    baseUrl: 'http://localhost:4200',
    fileServerFolder: '.',
    fixturesFolder: './src/fixtures',
    supportFile: './src/support/e2e.ts',
    video: true,
    videoCompression: false,
    videosFolder: '../../dist/cypress/apps/my-app-e2e/videos',
    screenshotsFolder:
      '../../dist/cypress/apps/my-app-e2e/screenshots',
    screenshotOnRunFailure: false,
    chromeWebSecurity: false,
    reporter: 'junit',
    reporterOptions: {
      mochaFile: './results/result-[hash].xml',
      rootSuiteTitle: 'Test',
      useFullSuiteTitle: true,
    },
    pageLoadTimeout: 120000,
    defaultCommandTimeout: 10000,
    viewportWidth: 1920,
    viewportHeight: 1080,
    experimentalRunAllSpecs: true,
    testIsolation: false,
    experimentalMemoryManagement: true,
    async setupNodeEvents(on, config) {
      await preset.setupNodeEvents(on, config);
    }
  },
});

project.json

"serve-static": {
      "executor": "@nx/web:file-server",
      "options": {
        "buildTarget": "my-app:build",
        "staticFilePath": "dist/apps/my-app",
        "spa": true
      }
    },
Coly010 commented 1 month ago

Hey :)

I'm going to need a reproduction to help debug this.

I also notice you're not on the latest version of Nx. Nx 19 shipped with a lot of bug fixes and stability improvements.

It would be worth trying to upgrade to latest Nx (19.5.0 at time of writing) also to see if this helps.

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because no reproduction was provided within 7 days. Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue. Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues. This issue will be closed in 21 days if a reproduction is not provided. If a reproduction has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏