Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'?".
# 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)'