nrwl / nx

Smart Monorepos ยท Fast CI
https://nx.dev
MIT License
23.17k stars 2.31k forks source link

@nrwl/cypress devServerTarget skips dependsOn on target project #5803

Closed trumbitta closed 5 months ago

trumbitta commented 3 years ago

Current Behavior

In workspace.json, for an e2e app with @nrlw/cypress, "devServerTarget": "my-project:serve" makes Nx run my-project:serve but it skips the new dependsOn option for my-project:serve.

To make it work, I have to add a dependsOn block to my-project-e2e instead.

Expected Behavior

I'd expect for targets to always follow the dependsOn chain

Steps to Reproduce

Environment

  Node : 12.18.3
  OS   : darwin x64
  npm  : 6.14.6

  nx : Not Found
  @nrwl/angular : Not Found
  @nrwl/cli : 12.3.4
  @nrwl/cypress : 12.3.4
  @nrwl/devkit : 12.3.4
  @nrwl/eslint-plugin-nx : 12.3.4
  @nrwl/express : Not Found
  @nrwl/jest : 12.3.4
  @nrwl/linter : 12.3.4
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : 12.3.4
  @nrwl/react : 12.3.4
  @nrwl/schematics : Not Found
  @nrwl/tao : 12.3.4
  @nrwl/web : 12.3.4
  @nrwl/workspace : 12.3.4
  @nrwl/storybook : 12.3.4
  @nrwl/gatsby : Not Found
  typescript : 4.1.5
vsavkin commented 3 years ago

Thank you for submitting the issue.

Currently, running a target imperatively runs that target, and not all the targets it depends on. It doesn't go through the tasks runner etc. We should be able to extend it in H2 2021 after combining the tao and workspace packages. For now though, this isn't possible. Sorry about this.

The workaround you provided works. A different workaround would be to create a separate target: "serve-using-nx" and do something like this there:

target: 'serve-using-nx',
executor: '@nrwl/workspace:run-commands',
options: {
  command: 'nx serve myapp'
}

In this case you will create a separate process using Nx, so the tasks runner will schedule all the right tasks.

trumbitta commented 3 years ago

I see, makes sense! I'm glad there are workarounds and some hope for the near future ๐Ÿš€

I'll just keep on following the releases ๐Ÿ•ต๏ธ until I can dismantle my workaround, then!

Lonli-Lokli commented 2 years ago

Will you add suppport for for dependsOn for serve targets?

julienboulay commented 2 years ago

Hi, I encountered the same issue, trying to configure Cypress, running e2e test on Storybook server, with compodoc as dependency.

@trumbitta thank you for the workaround. It works pretty well.

Here is the config file I use:

"my-lib": {
  "projectType": "library",
  "root": "libs/my-lib",
  "sourceRoot": "libs/my-lib/src",
  "prefix": "awesome",
  "architect": {
    "_storybook": {
      "builder": "@nrwl/storybook:storybook",
      "options": {
        "projectBuildConfig": "my-app",
        "uiFramework": "@storybook/angular",
        "port": 4400,
        "config": {
          "configFolder": "libs/my-lib/.storybook"
        }
      },
      "configurations": {
        "ci": {
          "quiet": true
        }
      }
    },
    "_build-storybook": {
      "builder": "@nrwl/storybook:build",
      "outputs": ["{options.outputPath}"],
      "options": {
        "projectBuildConfig": "my-app",
        "uiFramework": "@storybook/angular",
        "outputPath": "dist/storybook/my-lib",
        "config": {
          "configFolder": "libs/my-lib/.storybook"
        }
      },
      "configurations": {
        "ci": {
          "quiet": true
        }
      }
    },
    "compodoc": {
      "builder": "@twittwer/compodoc:compodoc",
      "options": {
        "tsConfig": "libs/my-lib/tsconfig.lib.json",
        "outputPath": "dist/compodoc/my-lib",
        "exportFormat": "json"
      }
    },
    "storybook": {
      "builder": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "npx nx run my-lib:compodoc --watch",
          "npx nx run my-lib:_storybook"
        ],
        "parallel": true
      }
    },
    "build-storybook": {
      "builder": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "npx nx run my-lib:compodoc",
          "npx nx run my-lib:_build-storybook"
        ],
        "parallel": false
      }
    }
  }
},
"my-lib-e2e": {
  "root": "apps/my-lib-e2e",
  "sourceRoot": "apps/my-lib-e2e/src",
  "projectType": "application",
  "architect": {
    "e2e": {
      "builder": "@nrwl/cypress:cypress",
      "dependsOn": [
        {
          "target": "compodoc",
          "projects": "dependencies"
        }
      ],
      "options": {
        "cypressConfig": "apps/my-lib-e2e/cypress.json",
        "devServerTarget": "my-lib:_storybook"
      },
      "configurations": {
        "ci": {
          "devServerTarget": "my-lib:_storybook:ci"
        }
      }
    }
  }
},

As a side effect, when I run all e2e test with the command nx run-many --target=e2e --all --headless, only compodoc tasks are executed for e2e targets. It seems that e2e test execution stops after dependsOn target is executed. Did someone encountered this issue ?

antoineviscardi commented 2 years ago

Thank you for submitting the issue.

Currently, running a target imperatively runs that target, and not all the targets it depends on. It doesn't go through the tasks runner etc. We should be able to extend it in H2 2021 after combining the tao and workspace packages. For now though, this isn't possible. Sorry about this.

The workaround you provided works. A different workaround would be to create a separate target: "serve-using-nx" and do something like this there:

target: 'serve-using-nx',
executor: '@nrwl/workspace:run-commands',
options: {
  command: 'nx serve myapp'
}

In this case you will create a separate process using Nx, so the tasks runner will schedule all the right tasks.

I tried using the workaround described above and it hangs on the serve target in the command. Is that normal?

zyf0330 commented 2 years ago

Is there any progress till now?

Thank you for submitting the issue.

Currently, running a target imperatively runs that target, and not all the targets it depends on. It doesn't go through the tasks runner etc. We should be able to extend it in H2 2021 after combining the tao and workspace packages. For now though, this isn't possible. Sorry about this.

The workaround you provided works. A different workaround would be to create a separate target: "serve-using-nx" and do something like this there:

target: 'serve-using-nx',
executor: '@nrwl/workspace:run-commands',
options: {
  command: 'nx serve myapp'
}

In this case you will create a separate process using Nx, so the tasks runner will schedule all the right tasks.

zyf0330 commented 2 years ago

Is there any progress till now?

Thank you for submitting the issue.

Currently, running a target imperatively runs that target, and not all the targets it depends on. It doesn't go through the tasks runner etc. We should be able to extend it in H2 2021 after combining the tao and workspace packages. For now though, this isn't possible. Sorry about this.

The workaround you provided works. A different workaround would be to create a separate target: "serve-using-nx" and do something like this there:

target: 'serve-using-nx',
executor: '@nrwl/workspace:run-commands',
options: {
  command: 'nx serve myapp'
}

In this case you will create a separate process using Nx, so the tasks runner will schedule all the right tasks.

Leandros commented 1 year ago

Any update on this? It's very frustrating.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

Leandros commented 1 year ago

It's still an issue.

tamusil-cen55253 commented 1 year ago

Same for us

lukascivil commented 11 months ago

I have the same problem.

DanLatimer commented 5 months ago

FYI - seeing another consequence of not using the task runner. nx will not respect the proper configuration env file for the devServerTarget.

Eg. having a

    "static-serve": {
      // statically serve the app
    },
    "e2e2": {
      "executor": "@nx/cypress:cypress",
      "options": {
        "cypressConfig": "apps/my-app/cypress.config.ts",
        "testingType": "e2e",
        "devServerTarget": "my-app:serve-static:e2e",
        "port": 3030,
        "browser": "chrome"
      }
    },

running nx run my-app:e2e2 will run the e2e2 target but when it runs the devServerTarget it will use the configuration e2e2 when looking for it's .env file so it'll look for .env.e2e2 even though the devServerTarget specifies the configuration should be called e2e.

What's worse is that this is only an issue if the e2e2 task is in the same project as the devServerTarget, if I have another feature Eg. nx run my-feature:e2e2 that has a similar e2e2 but serves the app project Ie.

    "e2e2": {
      "executor": "@nx/cypress:cypress",
      "options": {
        "cypressConfig": "apps/my-app/cypress.config.ts",
        "testingType": "e2e",
        "devServerTarget": "my-app:serve-static:e2e",
        "port": 3030,
        "browser": "chrome"
      }
    },

then it will pick up the .env.e2e environment variable file from the my-app project when running the devServerTarget

FrozenPandaz commented 5 months ago

The new command based Cypress Plugin fixes this issue. Running the command will invoke dependent tasks while running a target in an executor did not.

github-actions[bot] commented 4 months ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.