По сути, у меня есть конвейер, который работает так, как мы ожидаем. Все работает с одним бегунком, каскадным способом.
Настройка > Сборка > Модульные тесты > тесты e2e
Затем на втором этапе, когда все пройдет, мы публикуем артефакт.
Поскольку модульные тесты и тесты e2e находятся на одном этапе, репортер правильно регистрирует их в разделе покрытия и отображает тесты e2e и модульные тесты вместе.
Однако я попытался разделить их на две задачи, чтобы два параллельных бегуна могли работать быстрее.
Раскол заключается в том, Работа 1:
Проверяет репозиторий, настройка > модульные тесты > PublishCodeCoverageResults@2. Работа 2:
Проверяет репозиторий, настройку > сборку > набор e2e с помощью Playwright > PublishTestResults@2. Как только обе эти задачи будут выполнены успешно, будет создан Артефакт.
Эти же задачи при запуске в одном бегунке корректно генерируют отчет о тестах, однако при параллельной настройке они этого не делают. Отображается только покрытие кода драматурга.
Вот yaml, над которым я сейчас работаю:
trigger:
- main
- release/*
pool:
vmImage: ubuntu-latest
stages:
- stage: Validation
displayName: Validation
jobs:
- job: run_e2e_tests
displayName: Validate and Build
pool:
vmImage: ubuntu-latest
steps:
- task: Npm@1
displayName: Install bun
inputs:
command: custom
customCommand: install -g [email protected]
- script: |
bun install --frozen-lockfile
displayName: 'Install dependencies'
- script: bun run build
displayName: Build project
- script: bun run playwright install --with-deps
displayName: Setup playwright for e2e tests
# Continue even if the tests fail, so that the e2e tests can be run, and the test results can be published.
# The PublishTestResults task will fail if there are any failed tests.
continueOnError: true
- script: bun run e2e --reporter=junit
displayName: e2e tests
# Continue even if the tests fail, so that the test results can be published.
# The PublishTestResults task will fail if there are any failed tests.
continueOnError: true
env:
CI: true
PLAYWRIGHT_JUNIT_OUTPUT_NAME: junit-e2e.xml
- task: PublishTestResults@2
displayName: Publish test results
inputs:
testResultsFormat: JUnit
testResultsFiles: junit*.xml
failTaskOnFailedTests: true
failTaskOnFailureToPublishResults: true
failTaskOnMissingResultsFile: true
- job: run_unit_tests
displayName: Run Unit tests
pool:
vmImage: ubuntu-latest
steps:
- task: Npm@1
displayName: Install bun
inputs:
command: custom
customCommand: install -g [email protected]
- script: |
bun install --frozen-lockfile
displayName: 'Install dependencies'
- script: bun run test --coverage --reporters=jest-junit
displayName: Unit tests
# Continue even if the tests fail, so that the e2e tests can be run, and the test results can be published.
# The PublishTestResults task will fail if there are any failed tests.
continueOnError: true
- task: PublishCodeCoverageResults@2
displayName: Publish unit test code coverage
inputs:
summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage/clover.xml
mergeTestResults: true
failIfCoverageEmpty: true
- stage: ArtefactGeneration
displayName: Artefact Generation
dependsOn: Validation
jobs:
- job: PublishSourceCode
displayName: Publish Source Code
steps:
- task: PublishPipelineArtifact@1
displayName: Publish Source Code Artefact
inputs:
targetPath: $(Pipeline.Workspace)
artifact: frontend-source-code
publishLocation: pipeline
Обратите внимание, что установка deps занимает всего 10 секунд, поэтому я не счел необходимым распределять артефакты между заданиями.
Вот текущий yml для сравнения:
trigger:
- main
- release/*
pool:
vmImage: ubuntu-latest
stages:
- stage: Validation
displayName: Validation
jobs:
- job: StaticValidationAndTests
displayName: Static Validation and Tests
steps:
- task: NodeTool@0
displayName: Install Node.js
inputs:
versionSource: spec
versionSpec: 20.x
- task: Npm@1
displayName: Install bun
inputs:
command: custom
customCommand: install -g [email protected]
- script: bun install --frozen-lockfile
displayName: Install dependencies
- script: bun run build
displayName: Build project
- script: bun run lint
displayName: Run linter
- script: bun run test --coverage --reporters=jest-junit
displayName: Unit tests
# Continue even if the tests fail, so that the e2e tests can be run, and the test results can be published.
# The PublishTestResults task will fail if there are any failed tests.
continueOnError: true
- task: PublishCodeCoverageResults@2
displayName: Publish unit test code coverage
inputs:
summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage/clover.xml
failIfCoverageEmpty: true
- script: bun run playwright install --with-deps
displayName: Install playwright
enabled: false
- script: bun run e2e --reporter=junit
displayName: e2e tests
# Continue even if the tests fail, so that the test results can be published.
# The PublishTestResults task will fail if there are any failed tests.
continueOnError: true
enabled: false
env:
CI: true
PLAYWRIGHT_JUNIT_OUTPUT_NAME: junit-e2e.xml
- task: PublishTestResults@2
displayName: Publish test results
inputs:
testResultsFormat: JUnit
testResultsFiles: junit*.xml
mergeTestResults: true
failTaskOnFailedTests: true
failTaskOnFailureToPublishResults: true
failTaskOnMissingResultsFile: true
- stage: ArtefactGeneration
displayName: Artefact Generation
dependsOn: Validation
jobs:
- job: PublishSourceCode
displayName: Publish Source Code
steps:
- task: PublishPipelineArtifact@1
displayName: Publish Source Code Artefact
inputs:
targetPath: $(Pipeline.Workspace)
artifact: frontend-source-code
publishLocation: pipeline
Спасибо @wadezhou-MSFT. Я обновил вопрос.
По сравнению с исходным и текущим yaml, если Unit tests
и e2e tests
выполняются последовательно или отдельно в двух агентах, выходные данные будут одинаковыми.
В этом сценарии вы можете удалить PublishTestResults@2
и PublishCodeCoverageResults@2
в обоих заданиях и опубликовать выходные данные в обоих заданиях. Добавьте new job
, чтобы загрузить выходные данные выше, затем используйте PublishTestResults@2
и PublishTestResults@2
, чтобы опубликовать результат теста и покрытие.
Можете ли вы также показать yaml при запуске в одном агенте? Это необходимо для сравнения содержимого задач тестирования и публикации. Если одни и те же файлы создаются с помощью двух агентов, вы можете опубликовать результат как артефакт в каждом задании и загрузить их в последнем задании, чтобы получить все результаты, а затем опубликовать, это должно быть так же, как при запуске в одном агенте.