Skip to content

Commit 83b9671

Browse files
committed
Add more tests.
1 parent 40f5847 commit 83b9671

File tree

3 files changed

+212
-5
lines changed

3 files changed

+212
-5
lines changed

.scaffold/tests/bats/_assert_init.bash

+11
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,14 @@ assert_workflow() {
144144

145145
popd >/dev/null || exit 1
146146
}
147+
148+
assert_files_present_nodejs() {
149+
local dir="${1:-$(pwd)}"
150+
151+
pushd "${dir}" >/dev/null || exit 1
152+
153+
assert_file_contains "package.json" '"name": "@drupal/force_crystal"'
154+
assert_file_contains "package.json" '"description": "Provides force_crystal functionality."'
155+
156+
popd >/dev/null || exit 1
157+
}

.scaffold/tests/bats/functional.init.bats

+199-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Functional tests for init.sh.
44
#
55
# Example usage:
6-
# ./tests/scaffold/node_modules/.bin/bats --no-tempdir-cleanup --formatter tap --filter-tags smoke tests/scaffold
6+
# ./.scaffold/tests/node_modules/.bin/bats --no-tempdir-cleanup --formatter tap --filter-tags smoke .scaffold/tests
77
#
88
# shellcheck disable=SC2030,SC2031,SC2129
99

@@ -14,7 +14,7 @@ export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
1414
export SCRIPT_FILE="init.sh"
1515

1616
# bats test_tags=smoke
17-
@test "Init, defaults" {
17+
@test "Init, defaults, workflow" {
1818
answers=(
1919
"YodasHut" # organisation
2020
"force_crystal" # project
@@ -35,11 +35,13 @@ export SCRIPT_FILE="init.sh"
3535
assert_output_contains "Please follow the prompts to adjust your extension configuration"
3636
assert_files_present_common "${BUILD_DIR}"
3737
assert_files_present_extension_type_module "${BUILD_DIR}"
38+
assert_output_contains "Initialization complete."
39+
3840
assert_workflow "${BUILD_DIR}"
3941
}
4042

4143
# bats test_tags=smoke
42-
@test "Init, theme" {
44+
@test "Init, extension theme, workflow" {
4345
answers=(
4446
"YodasHut" # organisation
4547
"force_crystal" # project
@@ -60,5 +62,199 @@ export SCRIPT_FILE="init.sh"
6062
assert_output_contains "Please follow the prompts to adjust your extension configuration"
6163
assert_files_present_common "${BUILD_DIR}"
6264
assert_files_present_extension_type_theme "${BUILD_DIR}"
65+
assert_output_contains "Initialization complete."
66+
67+
assert_workflow "${BUILD_DIR}"
68+
}
69+
70+
# bats test_tags=smoke
71+
@test "Init, no release drafter, workflow" {
72+
answers=(
73+
"YodasHut" # organisation
74+
"force_crystal" # project
75+
"Force Crystal" # name
76+
"module" # type
77+
"Jane Doe" # author
78+
"nothing" # use NodeJS
79+
"n" # use GitHub release drafter
80+
"nothing" # use GitHub pr auto-assign
81+
"nothing" # use GitHub funding
82+
"nothing" # use GitHub PR template
83+
"nothing" # use Renovate
84+
"nothing" # remove init script
85+
"nothing" # proceed with init
86+
)
87+
tui_run "${answers[@]}"
88+
89+
assert_output_contains "Please follow the prompts to adjust your extension configuration"
90+
assert_files_present_common "${BUILD_DIR}"
91+
assert_files_present_extension_type_module "${BUILD_DIR}"
92+
assert_file_not_exists ".github/workflows/draft-release-notes.yml"
93+
assert_file_not_exists ".github/release-drafter.yml"
94+
assert_output_contains "Initialization complete."
95+
96+
assert_workflow "${BUILD_DIR}"
97+
}
98+
99+
# bats test_tags=smoke
100+
@test "Init, no PR auto-assign, workflow" {
101+
answers=(
102+
"YodasHut" # organisation
103+
"force_crystal" # project
104+
"Force Crystal" # name
105+
"module" # type
106+
"Jane Doe" # author
107+
"nothing" # use NodeJS
108+
"nothing" # use GitHub release drafter
109+
"n" # use GitHub pr auto-assign
110+
"nothing" # use GitHub funding
111+
"nothing" # use GitHub PR template
112+
"nothing" # use Renovate
113+
"nothing" # remove init script
114+
"nothing" # proceed with init
115+
)
116+
tui_run "${answers[@]}"
117+
118+
assert_output_contains "Please follow the prompts to adjust your extension configuration"
119+
assert_files_present_common "${BUILD_DIR}"
120+
assert_files_present_extension_type_module "${BUILD_DIR}"
121+
assert_file_not_exists ".github/assign-author.yml"
122+
assert_output_contains "Initialization complete."
123+
124+
assert_workflow "${BUILD_DIR}"
125+
}
126+
127+
@test "Init, no funding, workflow" {
128+
answers=(
129+
"YodasHut" # organisation
130+
"force_crystal" # project
131+
"Force Crystal" # name
132+
"module" # type
133+
"Jane Doe" # author
134+
"nothing" # use NodeJS
135+
"nothing" # use GitHub release drafter
136+
"nothing" # use GitHub pr auto-assign
137+
"n" # use GitHub funding
138+
"nothing" # use GitHub PR template
139+
"nothing" # use Renovate
140+
"nothing" # remove init script
141+
"nothing" # proceed with init
142+
)
143+
tui_run "${answers[@]}"
144+
145+
assert_output_contains "Please follow the prompts to adjust your extension configuration"
146+
assert_files_present_common "${BUILD_DIR}"
147+
assert_files_present_extension_type_module "${BUILD_DIR}"
148+
assert_file_not_exists ".github/FUNDING.yml"
149+
assert_output_contains "Initialization complete."
150+
151+
assert_workflow "${BUILD_DIR}"
152+
}
153+
154+
@test "Init, no PR template, workflow" {
155+
answers=(
156+
"YodasHut" # organisation
157+
"force_crystal" # project
158+
"Force Crystal" # name
159+
"module" # type
160+
"Jane Doe" # author
161+
"nothing" # use NodeJS
162+
"nothing" # use GitHub release drafter
163+
"nothing" # use GitHub pr auto-assign
164+
"nothing" # use GitHub funding
165+
"n" # use GitHub PR template
166+
"nothing" # use Renovate
167+
"nothing" # remove init script
168+
"nothing" # proceed with init
169+
)
170+
tui_run "${answers[@]}"
171+
172+
assert_output_contains "Please follow the prompts to adjust your extension configuration"
173+
assert_files_present_common "${BUILD_DIR}"
174+
assert_files_present_extension_type_module "${BUILD_DIR}"
175+
assert_file_not_exists ".github/PULL_REQUEST_TEMPLATE.md"
176+
assert_output_contains "Initialization complete."
177+
178+
assert_workflow "${BUILD_DIR}"
179+
}
180+
181+
@test "Init, no Renovate, workflow" {
182+
answers=(
183+
"YodasHut" # organisation
184+
"force_crystal" # project
185+
"Force Crystal" # name
186+
"module" # type
187+
"Jane Doe" # author
188+
"nothing" # use NodeJS
189+
"nothing" # use GitHub release drafter
190+
"nothing" # use GitHub pr auto-assign
191+
"nothing" # use GitHub funding
192+
"nothing" # use GitHub PR template
193+
"n" # use Renovate
194+
"nothing" # remove init script
195+
"nothing" # proceed with init
196+
)
197+
tui_run "${answers[@]}"
198+
199+
assert_output_contains "Please follow the prompts to adjust your extension configuration"
200+
assert_files_present_common "${BUILD_DIR}"
201+
assert_files_present_extension_type_module "${BUILD_DIR}"
202+
assert_file_not_exists "renovate.json"
203+
assert_output_contains "Initialization complete."
204+
205+
assert_workflow "${BUILD_DIR}"
206+
}
207+
208+
@test "Init, do not remove script, workflow" {
209+
answers=(
210+
"YodasHut" # organisation
211+
"force_crystal" # project
212+
"Force Crystal" # name
213+
"module" # type
214+
"Jane Doe" # author
215+
"nothing" # use NodeJS
216+
"nothing" # use GitHub release drafter
217+
"nothing" # use GitHub pr auto-assign
218+
"nothing" # use GitHub funding
219+
"nothing" # use GitHub PR template
220+
"nothing" # use Renovate
221+
"n" # remove init script
222+
"nothing" # proceed with init
223+
)
224+
tui_run "${answers[@]}"
225+
226+
assert_output_contains "Please follow the prompts to adjust your extension configuration"
227+
assert_files_present_common "${BUILD_DIR}"
228+
assert_files_present_extension_type_module "${BUILD_DIR}"
229+
assert_file_exists "init.sh"
230+
assert_output_contains "Initialization complete."
231+
63232
assert_workflow "${BUILD_DIR}"
64233
}
234+
235+
@test "Init, remove script, workflow" {
236+
answers=(
237+
"YodasHut" # organisation
238+
"force_crystal" # project
239+
"Force Crystal" # name
240+
"module" # type
241+
"Jane Doe" # author
242+
"nothing" # use NodeJS
243+
"nothing" # use GitHub release drafter
244+
"nothing" # use GitHub pr auto-assign
245+
"nothing" # use GitHub funding
246+
"nothing" # use GitHub PR template
247+
"nothing" # use Renovate
248+
"y" # remove init script
249+
"nothing" # proceed with init
250+
)
251+
tui_run "${answers[@]}"
252+
253+
assert_output_contains "Please follow the prompts to adjust your extension configuration"
254+
assert_files_present_common "${BUILD_DIR}"
255+
assert_files_present_extension_type_module "${BUILD_DIR}"
256+
assert_file_not_exists "init.sh"
257+
assert_output_contains "Initialization complete."
258+
259+
#assert_workflow "${BUILD_DIR}"
260+
}

init.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# ./init.sh
88
#
99
# Silent:
10-
# ./init.sh yournamespace yourproject "Your Name"
10+
# ./init.sh yournamespace extension_machine_name "Extension Name" extension_type author
1111
#
1212
# shellcheck disable=SC2162,SC2015
1313

@@ -203,7 +203,7 @@ process_internal() {
203203
replace_string_content "Yourproject logo" "${extension_name} logo"
204204
replace_string_content "Provides your_extension functionality." "Provides ${extension_machine_name} functionality."
205205
replace_string_content "drupal-module" "drupal-${extension_type}"
206-
replace_string_content "Drupal module scaffold FE example used for template testing" "${extension_name}"
206+
replace_string_content "Drupal module scaffold FE example used for template testing" "Provides ${extension_machine_name} functionality."
207207

208208
remove_string_content "Generic project scaffold template"
209209
replace_string_content "drupal_extension_scaffold" "${extension_machine_name}"

0 commit comments

Comments
 (0)