Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Wire up yeoman unit tests in CI/CD pipelines #1152

Merged
merged 6 commits into from
Jun 14, 2021
2 changes: 2 additions & 0 deletions build/yaml/templates/component-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ stages:
displayName: Build Node project
steps:
- template: npm-build-steps.yml
- template: npm-test-steps.yml

- stage: stage_package_node
displayName: 'Node: Build, Version & Pack'
Expand All @@ -18,6 +19,7 @@ stages:
displayName: 'Build & Pack Node project'
steps:
- template: npm-build-steps.yml
- template: npm-test-steps.yml
- template: npm-versioning-steps.yml
- template: npm-package-steps.yml

Expand Down
26 changes: 26 additions & 0 deletions build/yaml/templates/npm-test-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
steps:
# You are probably wondering "Why not just run 'yarn exec npm run --if-present test'?".
peterinnesmsft marked this conversation as resolved.
Show resolved Hide resolved
# On Azure Pipelines, yarn install by default restores modules to a global node_modules cache
# instead of a local package cache. When running the npm CLI, it is unable to resolve required
# dependencies as a result, whereas yarn run <script> can do so successfully. However,
# yarn does not yet have an --if-present condition - the immediate step below simulates this
# by manually reading the package.json and checking for the presence of $.scripts.test in the JSON.
- powershell: |
if (Test-Path -Path package.json) {
$package = Get-Content package.json | ConvertFrom-Json
$result = $package.scripts -and $package.scripts.test
Write-Host "##vso[task.setvariable variable=NpmRunTest;]$result"
} else {
Write-Host "Missing package.json"
exit 1
}
displayName: 'Determine if test script is present'
name: SetNpmRunTest
workingDirectory: '$(WorkingDirectory)'

- script: |
yarn run test
condition: eq(variables.NpmRunTest, true)
continueOnError: true
displayName: 'Run test if it exists'
workingDirectory: '$(WorkingDirectory)'