-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRemoveTags.ps1
More file actions
156 lines (105 loc) · 4.97 KB
/
RemoveTags.ps1
File metadata and controls
156 lines (105 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# ----------------------------------------------------------------------------------------------------
# Notes
# ----------------------------------------------------------------------------------------------------
# This script removes tags from SpecFlow+ LivingDoc's FeatureData.json file.
# Removing tags scrubs LivingDoc reports of context-sensitive information, like banks.
# For example, BAML test reports should have tags for all other banks removed.
# Typically, this script should be run after the script to remove skipped tests from Feature Data.
# WARNING: Feature Data must be generated from a test assembly, not from a feature folder!
# ----------------------------------------------------------------------------------------------------
# Parameters
# ----------------------------------------------------------------------------------------------------
Param(
[Parameter(Mandatory=$true)][string[]] $TagsToRemove,
[Parameter(Mandatory=$true)][string] $FeatureDataPath,
[Parameter(Mandatory=$true)][string] $PrunedFeatureDataPath
)
# ----------------------------------------------------------------------------------------------------
# Traversal Function:
# Visits a Feature Data object.
# ----------------------------------------------------------------------------------------------------
function RemoveTagsFromFeatureData {
Param(
[Parameter(Mandatory=$true)][string[]] $Tags,
[Parameter(Mandatory=$true)] $FeatureData
)
foreach ($Node in $FeatureData.Nodes) {
RemoveTagsFromFolder $Tags $Node
}
}
# ----------------------------------------------------------------------------------------------------
# Traversal Function:
# Visits a Feature Data folder (or node).
# ----------------------------------------------------------------------------------------------------
function RemoveTagsFromFolder {
Param(
[Parameter(Mandatory=$true)][string[]] $Tags,
[Parameter(Mandatory=$true)] $Folder
)
foreach ($SubFolder in $Folder.Folders) {
RemoveTagsFromFolder $Tags $SubFolder
}
foreach ($Feature in $Folder.Features) {
RemoveTagsFromFeature $Tags $Feature
}
}
# ----------------------------------------------------------------------------------------------------
# Traversal Function:
# Visits a Feature Data feature.
# Removes tags from the feature.
# ----------------------------------------------------------------------------------------------------
function RemoveTagsFromFeature {
Param(
[Parameter(Mandatory=$true)][string[]] $Tags,
[Parameter(Mandatory=$true)] $Feature
)
$Feature.Tags = @($Feature.Tags | Where-Object {-not ($Tags -contains $_)})
foreach ($Scenario in $Feature.ScenarioDefinitions) {
RemoveTagsFromScenario $Tags $Scenario
}
}
# ----------------------------------------------------------------------------------------------------
# Traversal Function:
# Visits a Feature Data scenario or scenario outline.
# Removes tags from the scenario.
# ----------------------------------------------------------------------------------------------------
function RemoveTagsFromScenario {
Param(
[Parameter(Mandatory=$true)][string[]] $Tags,
[Parameter(Mandatory=$true)] $Scenario
)
$Scenario.Tags = @($Scenario.Tags | Where-Object {-not ($Tags -contains $_)})
if ($Scenario.Keyword -eq "Scenario Outline") {
foreach ($Example in $Scenario.Examples) {
RemoveTagsFromExample $Tags $Example
}
}
}
# ----------------------------------------------------------------------------------------------------
# Traversal Function:
# Visits a Feature Data scenario outline example table.
# Removes tags from the example table.
# ----------------------------------------------------------------------------------------------------
function RemoveTagsFromExample {
Param(
[Parameter(Mandatory=$true)][string[]] $Tags,
[Parameter(Mandatory=$true)] $Example
)
$Example.Tags = @($Example.Tags | Where-Object {-not ($Tags -contains $_)})
}
# ----------------------------------------------------------------------------------------------------
# Read JSON LivingDoc files
# ----------------------------------------------------------------------------------------------------
Write-Host "Reading '$FeatureDataPath'"
$FeatureData = Get-Content -Raw -Path "$FeatureDataPath" | ConvertFrom-Json
# ----------------------------------------------------------------------------------------------------
# Remove tags from Feature Data
# ----------------------------------------------------------------------------------------------------
Write-Host "Removing tags from Feature Data"
Write-Host "Tags to remove:" $TagsToRemove
RemoveTagsFromFeatureData $TagsToRemove $FeatureData
# ----------------------------------------------------------------------------------------------------
# Save the new Feature Data to a JSON file
# ----------------------------------------------------------------------------------------------------
Write-Host "Saving the new Feature Data to '$PrunedFeatureDataPath'"
$FeatureData | ConvertTo-Json -Depth 20 | Out-File "$PrunedFeatureDataPath"