Skip to content

Commit 65d805a

Browse files
Merge pull request #10 from DevExpress-Examples/add-script-for-testing
Create test-example.ps1
2 parents bfc6123 + 2388902 commit 65d805a

File tree

2 files changed

+157
-1
lines changed

2 files changed

+157
-1
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<!-- default badges list -->
2-
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/782922866/23.1.3%2B)
32
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T1226606)
43
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
54
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)

test-example.ps1

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# For local testing, you can pass buildVersion.
2+
# Example usage:
3+
# ./test-example.ps1 -buildVersion 23.1.13
4+
param (
5+
[string]$buildVersion = $Env:CodeCentralBuildVersion
6+
)
7+
8+
# Masstest-specific parameter. Specifies the minor version (example: '21.1.5')
9+
$global:BUILD_VERSION = $buildVersion
10+
11+
$global:ERROR_CODE = 0
12+
$global:FAILED_PROJECTS = @()
13+
14+
function Install-Packages {
15+
param (
16+
[string]$folderName,
17+
[string[]]$packages,
18+
[string]$buildVersion
19+
)
20+
Write-Output "`nInstalling packages in folder: $folderName"
21+
22+
$packageList = $packages | ForEach-Object { "$_@$buildVersion" }
23+
Write-Output "`nPackages to install: $($packageList -join ", ")"
24+
# TODO: Uninstall DevExtreme packages to avoid potential peer-dependency issues
25+
npm install @($packageList) --save --save-exact --no-fund
26+
if (-not $?) {
27+
Write-Error "`nERROR: Failed to install DevExtreme packages in $folderName"
28+
throw "Installation failed in $folderName"
29+
}
30+
}
31+
32+
function Build-Project {
33+
param (
34+
[string]$folderName
35+
)
36+
Write-Output "`nBuilding the project in folder: $folderName"
37+
38+
npm run build
39+
if (-not $?) {
40+
Write-Error "`nERROR: Failed to build the project in $folderName"
41+
throw "Build failed in $folderName"
42+
}
43+
}
44+
45+
function Process-JavaScriptProjects {
46+
param (
47+
[string]$buildVersion
48+
)
49+
Write-Output "`n--== Starting JavaScript Projects Processing ==--"
50+
51+
[hashtable[]]$folders = @(
52+
@{ Name = "Angular"; Packages = @("devextreme", "devextreme-angular") },
53+
@{ Name = "React"; Packages = @("devextreme", "devextreme-react") },
54+
@{ Name = "Vue"; Packages = @("devextreme", "devextreme-vue") }
55+
)
56+
57+
$jQueryEntry = @{
58+
Name = "jQuery";
59+
Packages = if ([version]$buildVersion -ge [version]23.1) { # `devextreme-dist` appeared in 23.1
60+
@("devextreme", "devextreme-dist")
61+
} else {
62+
@("devextreme")
63+
}
64+
}
65+
66+
$folders = @($jQueryEntry) + $folders
67+
68+
foreach ($folder in $folders) {
69+
$folderName = $folder.Name
70+
$packages = $folder.Packages
71+
72+
if (-not (Test-Path $folderName)) {
73+
Write-Output "`nDirectory $folderName does not exist. Skipping..."
74+
continue
75+
}
76+
77+
Write-Output "`nProcessing folder: $folderName"
78+
Push-Location $folderName
79+
80+
try {
81+
Install-Packages -folderName $folderName -packages $packages -buildVersion $buildVersion
82+
Write-Output "`nInstalling remaining packages in $folderName"
83+
npm install --save --save-exact --no-fund --loglevel=error
84+
if (-not $?) {
85+
throw "ERROR: Failed to install remaining packages in $folderName"
86+
}
87+
Build-Project -folderName $folderName
88+
} catch {
89+
Write-Error "`nAn error occurred: $_"
90+
$global:LASTEXITCODE = 1
91+
$global:ERROR_CODE = 1
92+
$global:FAILED_PROJECTS += $folderName
93+
} finally {
94+
Pop-Location
95+
}
96+
}
97+
98+
Write-Output "`n--== JavaScript Projects Processing Completed ==--"
99+
}
100+
101+
function Process-DotNetProjects {
102+
param (
103+
[string]$RootDirectory = "."
104+
)
105+
106+
Write-Output "`n--== Starting .NET project processing in directory: $RootDirectory ==--"
107+
108+
$slnFiles = Get-ChildItem -Path $RootDirectory -Filter *.sln -Recurse -Depth 1
109+
110+
if ($slnFiles.Count -eq 0) {
111+
Write-Output "`nNo solution files (.sln) found in the specified directory at level 1."
112+
return
113+
}
114+
115+
foreach ($slnFile in $slnFiles) {
116+
Write-Output "`nFound solution file: $($slnFile.FullName)"
117+
118+
try {
119+
Write-Output "`nBuilding solution: $($slnFile.FullName)"
120+
dotnet build $slnFile.FullName -c Release
121+
122+
if ($?) {
123+
Write-Output "`nBuild succeeded for $($slnFile.FullName)."
124+
} else {
125+
throw "Build failed for $($slnFile.FullName)."
126+
}
127+
} catch {
128+
Write-Error "`nERROR: $_"
129+
$global:LASTEXITCODE = 1
130+
$global:ERROR_CODE = 1
131+
$global:FAILED_PROJECTS += "ASP.NET"
132+
}
133+
}
134+
135+
Write-Output "`nCompleted .NET project processing."
136+
}
137+
138+
function Write-BuildInfo {
139+
$BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") {
140+
$global:BUILD_VERSION
141+
} else {
142+
"(empty)"
143+
}
144+
145+
Write-Output "Build Version: $BUILD_VERSION"
146+
}
147+
148+
Write-BuildInfo
149+
Process-JavaScriptProjects -buildVersion $global:BUILD_VERSION
150+
Process-DotNetProjects
151+
152+
Write-Output "`nFinished testing version: $global:BUILD_VERSION. Error code: $global:ERROR_CODE"
153+
if ($global:ERROR_CODE -ne 0 -and $global:FAILED_PROJECTS.Count -gt 0) {
154+
Write-Output "`FAILED PROJECTS: $(($global:FAILED_PROJECTS -join ", "))"
155+
}
156+
157+
exit $global:ERROR_CODE

0 commit comments

Comments
 (0)