Reputation: 47
I have an Azure DevOps project that has 2 repos in it, one with the .net web app and another with Cypress tests. I need to create a pipeline that builds and runs the unit tests from the web app repo, then checkout the Cypress repo and runs the e2e tests. When my pipeline tries to run the Cypress tests, I get the error "Cypress could not verify that this server is running: https://localhost:5001/"
I believe because my cypress tests are in a different repo, I need to keep my web app running on a server until my cypress tests are completed. Is this correct? I'm not sure so this is a guess. How can I set this up so that my tests can run properly?
Here is my pipeline yaml file:
trigger:
- development
resources:
repositories:
- repository: e2ecypress
type: git
name: devopsapp/e2ecypress
jobs:
- job: build_unit_tests
displayName: '.Net Build'
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- job: cypress_tests
displayName: 'Cypress Tests'
pool:
vmImage: 'windows-latest'
steps:
- checkout: e2ecypress
- task: NodeTool@0
inputs:
versionSpec: '14.x'
displayName: 'Install Node.js'
- task: Npm@1
inputs:
command: 'install'
displayName: 'NPM Install'
- script: |
npx cypress run
displayName: 'Cypress Tests'
Here is the error from my pipeline run:
Upvotes: 1
Views: 847
Reputation: 1146
A possible solution would be to check out both repositories in the same job like:
steps:
- checkout: self
- checkout: e2ecypress
The keyword self refers to the repository you execute the pipeline from, so your web app. But be aware that when checking out multiple repositories, the directory paths for them change a bit, see Docs: Check out multiple repositories in your pipeline
Then you can access the content from both repositories within the same job in a VM by using the correct paths. This allows you to do a build of your web app, launch it, and then run the Cypress tests on the running app.
To start your app, run the tests, and automatically exit the web app when finished, you can use the solution described in the following answer which is also recommend by Cypress: https://stackoverflow.com/a/70541458/6135684
Upvotes: 2