Skip to content

Commit 9f678c3

Browse files
Merge pull request #1 from DevExpress-Examples/update-for-automated-testing
Update for testing
2 parents bf6e247 + 408b53d commit 9f678c3

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* text=auto eol=lf
2+
13
VB/* linguist-vendored
24
scripts linguist-vendored
35
*.css linguist-detectable=false

test-example.ps1

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
21+
Write-Output "`nInstalling packages in folder: $folderName"
22+
23+
# Loop through each package and install it individually
24+
foreach ($package in $packages) {
25+
$packageWithVersion = "$package@$buildVersion"
26+
Write-Output "Installing $packageWithVersion..."
27+
28+
npm install --save --save-exact --no-fund --loglevel=error --force $packageWithVersion
29+
if (-not $?) {
30+
Write-Error "`nERROR: Failed to install $packageWithVersion in $folderName"
31+
throw "Installation failed for $packageWithVersion in $folderName"
32+
}
33+
}
34+
35+
Write-Output "`nAll packages installed successfully in $folderName"
36+
}
37+
38+
function Build-Project {
39+
param (
40+
[string]$folderName
41+
)
42+
Write-Output "`nBuilding the project in folder: $folderName"
43+
44+
npm run build
45+
if (-not $?) {
46+
Write-Error "`nERROR: Failed to build the project in $folderName"
47+
throw "Build failed in $folderName"
48+
}
49+
}
50+
51+
function Process-JavaScriptProjects {
52+
param (
53+
[string]$buildVersion
54+
)
55+
Write-Output "`n--== Starting JavaScript Projects Processing ==--"
56+
57+
[hashtable[]]$folders = @(
58+
@{ Name = "Angular"; Packages = @("devextreme", "devextreme-angular") },
59+
@{ Name = "React"; Packages = @("devextreme", "devextreme-react") },
60+
@{ Name = "Vue"; Packages = @("devextreme", "devextreme-vue") }
61+
)
62+
63+
$jQueryEntry = @{
64+
Name = "jQuery";
65+
Packages = if ([version]$buildVersion -ge [version]23.1) { # `devextreme-dist` appeared in 23.1
66+
@("devextreme", "devextreme-dist")
67+
} else {
68+
@("devextreme")
69+
}
70+
}
71+
72+
$folders = @($jQueryEntry) + $folders
73+
74+
foreach ($folder in $folders) {
75+
$folderName = $folder.Name
76+
$packages = $folder.Packages
77+
78+
if (-not (Test-Path $folderName)) {
79+
Write-Output "`nDirectory $folderName does not exist. Skipping..."
80+
continue
81+
}
82+
83+
Write-Output "`nProcessing folder: $folderName"
84+
Push-Location $folderName
85+
86+
try {
87+
Write-Output "`nRemoving node_modules & package-lock.json: $pwd"
88+
Remove-Item -Recurse -Force node_modules -ErrorAction SilentlyContinue
89+
Remove-Item -Force package-lock.json -ErrorAction SilentlyContinue
90+
Install-Packages -folderName $folderName -packages $packages -buildVersion $buildVersion
91+
Write-Output "`nInstalling remaining packages in $folderName"
92+
npm install --save --save-exact --no-fund --loglevel=error
93+
if (-not $?) {
94+
throw "ERROR: Failed to install remaining packages in $folderName"
95+
}
96+
Build-Project -folderName $folderName
97+
} catch {
98+
Write-Error "`nAn error occurred: $_"
99+
$global:LASTEXITCODE = 1
100+
$global:ERROR_CODE = 1
101+
$global:FAILED_PROJECTS += $folderName
102+
} finally {
103+
Pop-Location
104+
}
105+
}
106+
107+
Write-Output "`n--== JavaScript Projects Processing Completed ==--"
108+
}
109+
110+
function Process-DotNetProjects {
111+
param (
112+
[string]$RootDirectory = "."
113+
)
114+
115+
Write-Output "`n--== Starting .NET project processing in directory: $RootDirectory ==--"
116+
117+
$slnFiles = Get-ChildItem -Path $RootDirectory -Filter *.sln -Recurse -Depth 1
118+
119+
if ($slnFiles.Count -eq 0) {
120+
Write-Output "`nNo solution files (.sln) found in the specified directory at level 1."
121+
return
122+
}
123+
124+
foreach ($slnFile in $slnFiles) {
125+
Write-Output "`nFound solution file: $($slnFile.FullName)"
126+
127+
try {
128+
Write-Output "`nBuilding solution: $($slnFile.FullName)"
129+
dotnet build $slnFile.FullName -c Release
130+
131+
if ($?) {
132+
Write-Output "`nBuild succeeded for $($slnFile.FullName)."
133+
} else {
134+
throw "Build failed for $($slnFile.FullName)."
135+
}
136+
} catch {
137+
Write-Error "`nERROR: $_"
138+
$global:LASTEXITCODE = 1
139+
$global:ERROR_CODE = 1
140+
$global:FAILED_PROJECTS += "ASP.NET"
141+
}
142+
}
143+
144+
Write-Output "`nCompleted .NET project processing."
145+
}
146+
147+
function Write-BuildInfo {
148+
$BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") {
149+
$global:BUILD_VERSION
150+
} else {
151+
"(empty)"
152+
}
153+
154+
Write-Output "Build Version: $BUILD_VERSION"
155+
}
156+
157+
Write-BuildInfo
158+
Process-JavaScriptProjects -buildVersion $global:BUILD_VERSION
159+
Process-DotNetProjects
160+
161+
Write-Output "`nFinished testing version: $global:BUILD_VERSION. Error code: $global:ERROR_CODE"
162+
if ($global:ERROR_CODE -ne 0 -and $global:FAILED_PROJECTS.Count -gt 0) {
163+
Write-Output "`FAILED PROJECTS: $(($global:FAILED_PROJECTS -join ", "))"
164+
}
165+
166+
exit $global:ERROR_CODE

0 commit comments

Comments
 (0)