Skip to content

Commit ef26523

Browse files
committed
build: 📦 force TDD for exercises that need it
1 parent 795e49f commit ef26523

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

‎tools/cook/config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ const exercises: Exercise[] = [
7171
{
7272
id: '304-recipe-search-async-pipe',
7373
name: '304 - Recipe Search Async Pipe',
74+
forceTdd: true,
7475
implementationFiles: [files.recipeSearch],
7576
},
7677
{
7778
id: '305-recipe-search-signals',
7879
name: '305 - Recipe Search Signals',
80+
forceTdd: true,
7981
implementationFiles: [files.recipeSearch],
8082
},
8183
{

‎tools/cook/core.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,12 @@ export interface Config {
66
export interface Exercise {
77
id: string;
88
name: string;
9+
10+
/**
11+
* This option forces TDD mode.
12+
* It is necessary for exercises where we want users to migrate something,
13+
* and see which tests survive the migration.
14+
*/
15+
forceTdd?: boolean;
916
implementationFiles?: string[];
1017
}

‎tools/cook/main.spec.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ describe('cook', () => {
5757
]);
5858
});
5959

60+
it('uses TDD mode when forceTdd is true', async () => {
61+
const { executedCommands } = await runMain({
62+
choices: { exercise: '3-recipe-search-async-pipe' },
63+
nxJsonContent: {},
64+
});
65+
66+
expect(executedCommands).toEqual([
67+
'git switch main',
68+
'git branch -D cooking || exit 0',
69+
'git switch -c cooking',
70+
'git add .',
71+
'git commit -m "feat: ✨ focus on 3-recipe-search-async-pipe-starter"',
72+
]);
73+
});
74+
6075
it('checks out solution', async () => {
6176
const { executedCommands, files } = await runMain({
6277
choices: { command: 'solution', confirmOverwrite: true },
@@ -150,6 +165,12 @@ async function runMain({
150165
implementationFiles: ['src/app/recipe/recipe-search.ng.ts'],
151166
},
152167
{ id: '2-test-double', name: 'Test Double' },
168+
{
169+
id: '3-recipe-search-async-pipe',
170+
name: 'Recipe Search Async Pipe',
171+
forceTdd: true,
172+
implementationFiles: ['src/app/recipe/recipe-search.ng.ts'],
173+
},
153174
];
154175

155176
await main(args, {

‎tools/cook/main.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,17 @@ async function goToExercise(ctx: Context, exerciseId?: string) {
221221
let tdd = true;
222222

223223
if (selectedExercise.implementationFiles) {
224-
const tddChoice = await promptAdapter.prompt<{ useTdd: boolean }>({
225-
type: 'confirm',
226-
name: 'useTdd',
227-
message: 'Do you want to use TDD?',
228-
initial: false,
229-
});
230-
tdd = tddChoice.useTdd;
224+
if (selectedExercise.forceTdd) {
225+
tdd = true;
226+
} else {
227+
const tddChoice = await promptAdapter.prompt<{ useTdd: boolean }>({
228+
type: 'confirm',
229+
name: 'useTdd',
230+
message: 'Do you want to use TDD?',
231+
initial: false,
232+
});
233+
tdd = tddChoice.useTdd;
234+
}
231235
}
232236

233237
console.log(`\nSetting up exercise: ${selectedExercise.name}`);

0 commit comments

Comments
 (0)