azure-devops - 在 azure 管道 yaml 中运行 cypress 测试时找不到 package.json
问题描述
我正在尝试使用 YAML 在 Azure Pipeline 作业中运行柏树测试。当管道运行时,它会到达运行 cypress 测试的行并抛出此错误:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\myagent\_work\5\s\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\myagent\_work\5\s\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
这是我的 YAML 文件:
trigger:
- master
pool:
name: Default
variables:
buildConfiguration: 'Release'
steps:
- task: NodeTool@0
displayName: 'Use Node 12.x'
inputs:
versionSpec: 12.18.3
checkLatest: false
- task: Npm@1
displayName: 'npm install'
inputs:
workingDir: WebApp
verbose: false
- task: Npm@1
displayName: 'Build Angular'
inputs:
command: custom
customCommand: run build -- --prod
workingDir: WebApp
- task: UseDotNet@2
displayName: 'Use .NET Core SDK 3.1.300'
inputs:
packageType: sdk
version: 3.1.300
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: AppApi/AppApi.csproj
vstsFeed: '*************'
- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: publish
arguments: '--no-restore --configuration $(buildConfiguration) --verbosity quiet --output $(build.artifactstagingdirectory)'
publishWebProjects: true
zipAfterPublish: true
- script: 'npx cypress verify'
displayName: 'cypress verify'
failOnStderr: true
- script: 'npm run cy:run --headless --spec cypress/integration/TestDemoExpanded.spec.ts --project ./WebApp'
displayName: 'run cypress tests'
workingDirectory: $(Build.SourcesDirectory)/WebApp
我的 package.json 已检入我的 Git 存储库,并且位于我的 WebApp 子文件夹中。我该如何解决这个错误?
更新:我按照建议添加了 workingDirectory 参数,但现在我有这个新错误:npm ERR! missing script: cypress
我解决了“缺少脚本”错误。我在 YAML 文件中的 cypress run 命令与我在 package.json 中的 cypress run 命令不匹配。我更新了 cypress 运行步骤,现在测试在管道中运行。
解决方案
该任务package.json
在根文件夹中搜索,而不是在WebApp
.
只需添加:
workingDirectory: $(Build.SourcesDirectory)/WebApp
到cypress
步骤:
- script: 'npm run cypress run --headless --spec cypress/integration/TestDemoExpanded.spec.ts --project ./WebApp'
displayName: 'run cypress tests'
workingDirectory: $(Build.SourcesDirectory)/WebApp
推荐阅读
- c - 无法在 If 语句中检索或存储二维数组位置
- css - 如何在 Vuetify 中更改文本字段的宽度和高度?
- c# - Unity:使用两个摄像头对单个图层进行灰度化也会对天空盒进行灰度化?
- c - 字节顺序和位移问题
- javascript - 在一个 td 中显示数组项目,每个项目在新行上
- tensorflow - 函数 model.fit() 中的错误不兼容形状
- python - tensorflow找到到真实点的最小距离
- node.js - Angular8 和 webpack4:未捕获的 ReferenceError:vendor_lib 未定义和源映射错误
- javascript - 点击后运行函数
- python - 如何检查特定字符串长度的日志文件并在 Python 中调用下游函数